Last active
January 4, 2020 11:11
-
-
Save myathtut-zafir/4ff21c7c8f3169ddf5de811184fc3fca to your computer and use it in GitHub Desktop.
mht-gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
project=/var/www/travel_list | |
swapfile=/swapfile | |
update() { | |
apt update | |
apt autoremove -yqq | |
apt autoclean | |
} | |
swap() { | |
swapoff | |
rm -rf $swapfile | |
fallocate -l 1G $swapfile | |
chmod 600 $swapfile | |
mkswap $swapfile | |
swapon $swapfile | |
cp /etc/fstab /home | |
tr -d "swapfile" /etc/fstab | |
echo "/swapfile swap swap default 0 0" >>/etc/fstab | |
} | |
php_install() { | |
sudo apt install -yqq php-cli php-zip php-mbstring php-xml composer | |
} | |
set_up() { | |
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" | |
HASH="$(wget -q -O - https://composer.github.io/installer.sig)" | |
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" | |
php composer-setup.php --install-dir=/usr/local/bin --filename=composer | |
} | |
composer_install() { | |
rm -rf $project | |
composer create-project --prefer-dist laravel/laravel $project | |
} | |
server_info() { | |
cd /var/www/travel_list/ | |
cat >/var/www/travel_list/.env <<'EOF' | |
APP_NAME=TravelList | |
APP_ENV=development | |
APP_KEY=APPLICATION_Userver | |
APP_DEBUG=true | |
APP_URL= | |
LOG_CHANNEL=stack | |
DB_CONNECTION=mysql | |
DB_HOST=127.0.0.1 | |
DB_PORT=3306 | |
DB_DATABASE=travel_list | |
DB_USERNAME=travel_user | |
DB_PASSWORD=password | |
EOF | |
php artisan key:generate | |
php artisan config:cache | |
} | |
database() { | |
mysql -u root -ppassword <<'EOF' | |
CREATE DATABASE travel_list; | |
GRANT ALL ON travel_list.* TO 'travel_user'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION; | |
exit | |
EOF | |
} | |
permission() { | |
cd $project | |
chmod -R 755 ./ | |
chmod -R 775 bootstrap/cache storage | |
chown -R www-data:www-data ./ | |
chmod -R ug+rwx storage bootstrap/cache | |
} | |
nginx_config() { | |
sudo apt-get install -yqq nginx | |
cat >/etc/nginx/sites-available/travel_list <<'EOF' | |
server{ | |
listen 80; | |
server_name 178.128.210.231; | |
root /var/www/travel_list/public; | |
add_header X-Frame-Options "SAMEORIGIN"; | |
add_header X-XSS-Protection "1; mode=block"; | |
add_header X-Content-Type-Options "nosniff"; | |
index index.html index.htm index.php; | |
charset utf-8; | |
location / { | |
try_files $uri $uri/ /index.php?$query_string; | |
} | |
location = /favicon.ico { access_log off; log_not_found off; } | |
location = /robots.txt { access_log off; log_not_found off; } | |
error_page 404 /index.php; | |
location ~ \.php$ { | |
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
location ~ /\.(?!well-known).* { | |
deny all; | |
} | |
} | |
EOF | |
rm -rf /etc/nginx/sites-enabled/* | |
ln -s /etc/nginx/sites-available/travel_list /etc/nginx/sites-enabled/travel_list | |
nginx -t | |
systemctl enable nginx | |
systemctl reload nginx | |
} | |
case "$1" in | |
s) | |
echo "swap file create" | |
swap | |
;; | |
u) | |
echo "updating" | |
update | |
;; | |
p) | |
echo "downloading required php modules" | |
php_install | |
;; | |
c) | |
echo "composer installing" | |
composer_install | |
;; | |
e) | |
echo "connection" | |
set_up | |
;; | |
i) | |
echo "Editing server info" | |
server_info | |
;; | |
d) | |
echo "Database Creating" | |
database | |
permission | |
;; | |
n) | |
echo "Nginx Set Up" | |
nginx_config | |
;; | |
a) | |
echo "install all" | |
update | |
swap | |
database | |
php_install | |
composer_install | |
set_up | |
server_info | |
permission | |
nginx_config | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment