Skip to content

Instantly share code, notes, and snippets.

@unique1984
Created April 1, 2019 23:09
Show Gist options
  • Select an option

  • Save unique1984/030f43ea46d4c13a4b4f4057bf122fa4 to your computer and use it in GitHub Desktop.

Select an option

Save unique1984/030f43ea46d4c13a4b4f4057bf122fa4 to your computer and use it in GitHub Desktop.
Apache Symfony Application [add|rm] config
#!/usr/bin/env bash
#---------------------------------------------------------------------#
# addSymfonySite #
# #
# apache add Symfony site #
# #
# Script : addSymfonySite.sh #
# Version : 1.0.0 #
# Author : Yasin KARABULAK <yasinkarabulak@gmail.com> #
# Date : 2019-04-02 #
#---------------------------------------------------------------------#
function parcala {
#~ https://stackoverflow.com/questions/3362920/get-just-the-filename-from-a-path-in-a-bash-script?answertab=votes#tab-top
FULL="$1"
F_PATH=${FULL%/*}
F_BASE=${FULL##*/}
F_NAME=${F_BASE%.*}
F_EXT=${F_BASE##*.}
#~ echo $F_PATH
#~ echo $F_BASE
#~ echo $F_NAME
#~ echo $F_EXT
#~ exit
}
if [ -d "src" ] && [ -d "vendor" ] && [ -d "public" ] && [ -d "var" ] && [ -f "symfony.lock" ] && [ -f ".env" ]; then
parcala $(pwd)
if [ -f "/etc/apache2/sites-available/$F_BASE.conf" ]; then
echo "$F_BASE isminde bir site var programdan çıkılıyor!"
exit
fi
else
echo -e "Bulunduğunuz dizin Symfony App dizini mi?\n"
echo -e "Symfony projesi oluşturmak için !"
echo -e "1. symfony new symfonyDemo 4.1"
echo -e "2. composer create-project symfony/skeleton symfonyDemo"
echo -e "git clone <repo> && composer install"
exit
fi
VARDIR=$(stat -c "%a" var/)
if [ "$VARDIR" -lt "777" ]; then
chmod -R 777 $(pwd)/var
fi
echo -e $(cat <<EOF
<VirtualHost *:80>\n
\t ServerAdmin webmaster@localhost\n
\t ServerName $F_BASE\n
\t ServerAlias $F_BASE\n
\t DocumentRoot $(pwd)/public\n
\t ErrorLog \${APACHE_LOG_DIR}/error.log\n
\t CustomLog \${APACHE_LOG_DIR}/access.log combined\n
\n
\t <IfModule mod_userdir.c>\n
\t UserDir $(pwd)/public\n
\t UserDir disabled\n
\t UserDir enabled $(whoami)\n
\t </IfModule>\n
</VirtualHost>\n
\n
<Directory $(pwd)/public>\n
\t AllowOverride All\n
\t Require all granted\n
\t Order Allow,Deny\n
\t Allow from All\n
\n
\t <IfModule mod_rewrite.c>\n
\t Options FollowSymLinks Includes ExecCGI MultiViews\n
\t RewriteEngine On\n
\t RewriteCond %{REQUEST_FILENAME} !-f\n
\t RewriteRule ^(.*)$ index.php [QSA,L]\n
\t </IfModule>\n
</Directory>\n
# SetEnv APP_ENV prod\n
# SetEnv APP_DEBUG 0\n
EOF
) > "$F_BASE.conf"
sudo cp $F_BASE.conf /etc/apache2/sites-available/$F_BASE.conf
rm $F_BASE.conf
sudo bash -c "echo -e '127.0.0.1\t$F_BASE' >> /etc/hosts"
sudo a2ensite $F_BASE.conf
sudo /etc/init.d/apache2 restart
#!/usr/bin/env bash
#---------------------------------------------------------------------#
# rmSymfonySite #
# #
# apache rm Symfony site configuration #
# #
# Script : rmSymfonySite.sh #
# Version : 1.0.0 #
# Author : Yasin KARABULAK <yasinkarabulak@gmail.com> #
# Date : 2019-04-02 #
#---------------------------------------------------------------------#
if [ ! -z "$1" ] && [ -f "/etc/apache2/sites-available/$1.conf" ]; then
sudo a2dissite "$1.conf"
sudo rm "/etc/apache2/sites-available/$1.conf"
sudo /etc/init.d/apache2 restart
sudo nano /etc/hosts
else
echo -e "Belirtilen config dosyası bulunamadı !"
ls -lh "/etc/apache2/sites-available/"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment