Skip to content

Instantly share code, notes, and snippets.

@deepaksp
Last active January 8, 2019 04:36
Show Gist options
  • Save deepaksp/9b36002b9e811cedcf71169c93e7ad3b to your computer and use it in GitHub Desktop.
Save deepaksp/9b36002b9e811cedcf71169c93e7ad3b to your computer and use it in GitHub Desktop.
Script to Install Php7.x-Fpm Nginx Mysql Webmin and Supervisor Automatically (No Interaction)
#!/bin/bash
site="example"
site_name="example.com"
site_dir="/var/www/example/public"
mysql_pass="test123"
webmin_pass="test321"
php_ver="php7.3"
install_base=true
install_php=true
install_mysql=true
install_redis=true
install_nginx=true
#so you can run nginx conf again for new site !
add_nginx_conf=true
install_webmin=true
install_supervisor=true
#change true if you going to upload large file
update_nginx=false
update_php=false
cd /tmp
# Install Base !
if [ $install_base = true ]; then
sudo apt-get install -y language-pack-en-base
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php -y
sudo apt-get update -y
sudo apt-get install zip unzip git imagemagick -y
fi
# Install PHP !
if [ $install_php = true ]; then
#install php and composer
sudo apt-get install $php_ver-fpm $php_ver-mysql $php_ver-pdo $php_ver-mbstring $php_ver-xml $php_ver-curl $php_ver-gd $php_ver-mbstring $php_ver-imagick -y
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
fi
# Install Nginx !
if [ $install_nginx = true ]; then
sudo apt-get install nginx -y
fi
# Add Nginx Configuration !
if [ $add_nginx_conf = true ]; then
rm -f /etc/nginx/sites-enabled/default
rm -f /etc/nginx/sites-available/default
mkdir "/var/www/$site"
cat <<EOF > "/etc/nginx/sites-available/$site"
server {
server_name www.$site_name;
return 301 \$scheme://$site_name\$request_uri;
}
server {
listen 80;
root $site_dir;
index index.php index.html index.htm;
server_name $site_name;
location / {
try_files \$uri \$uri/ /index.php?\$args;
}
location ~ \.php\$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/$php_ver-fpm.sock;
}
}
EOF
ln -s "/etc/nginx/sites-available/$site" "/etc/nginx/sites-enabled/$site"
service nginx restart
fi
# Change Nginx Config
if [ $update_nginx = true ]; then
cat <<EOF > "/etc/nginx/conf.d/z_custom.conf"
client_max_body_size 100M;
EOF
service nginx restart
fi
# Add Custom Php.ini
if [ $update_php = true ]; then
cat <<EOF > "/tmp/php/z_custom.ini"
memory_limit = 640M
upload_max_filesize = 100M
post_max_size = 100M
max_execution_time = 1800
max_input_time = 1000
opcache.enable=1
opcache.memory_consumption=512
opcache.interned_strings_buffer=64
opcache.max_accelerated_files=20000
opcache.validate_timestamps=0
opcache.save_comments=1
opcache.fast_shutdown=1
xdebug.remote_autostart=0
xdebug.remote_enable=0
xdebug.profiler_enable=0
[Date]
date.timezone="UTC"
EOF
sudo cp /tmp/php/z_custom.ini /etc/php/7.3/fpm/conf.d/z_custom.ini
sudo cp /tmp/php/z_custom.ini /etc/php/7.2/fpm/conf.d/z_custom.ini
sudo cp /tmp/php/z_custom.ini /etc/php/7.1/fpm/conf.d/z_custom.ini
#disable xdebug
phpdismod xdebug
#enable xdebug
#phpenmod xdebug
service $php_ver-fpm restart
fi
# Install MySQL !
if [ $install_mysql = true ]; then
export DEBIAN_FRONTEND="noninteractive"
apt-get install mysql-client mysql-server -y
mysql -e "UPDATE mysql.user SET authentication_string = PASSWORD('$mysql_pass') WHERE User = 'root'"
mysql -e "FLUSH PRIVILEGES"
service mysql restart
fi
# Install Webmin !
if [ $install_webmin = true ]; then
echo 'deb http://download.webmin.com/download/repository sarge contrib' >/tmp/webmin.list
sudo cp /tmp/webmin.list /etc/apt/sources.list.d/
rm /tmp/webmin.list
wget http://www.webmin.com/jcameron-key.asc
sudo apt-key add jcameron-key.asc
sudo apt-get update -y
sudo apt-get install webmin -y
/usr/share/webmin/changepass.pl /etc/webmin root $webmin_pass
service webmin restart
fi
# Install Redis-Server !
if [ $install_redis = true ]; then
sudo apt-get install redis-server -y
fi
# Install Supervisor !
if [ $install_supervisor = true ]; then
sudo apt-get install supervisor -y
#sample setting for laravel queue
cat <<EOF > /etc/supervisor/conf.d/laravel-worker.conf
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/$site/artisan queue:work redis --sleep=3 --tries=3
autostart=true
autorestart=true
user=root
numprocs=8
redirect_stderr=true
stdout_logfile=/var/log/worker.log
EOF
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel-worker:*
fi
# just copy past below code edit ur site info and run sudo ./setup-server.sh
# wget https://gist.github.com/deepaksp/9b36002b9e811cedcf71169c93e7ad3b/raw/setup-server.sh && sudo chmod +x setup-server.sh && sudo nano setup-server.sh
@deepaksp
Copy link
Author

deepaksp commented Jan 8, 2019

just copy past below code edit ur site info and run sudo ./setup-server.sh
wget https://gist.github.com/deepaksp/9b36002b9e811cedcf71169c93e7ad3b/raw/setup-server.sh && sudo chmod +x setup-server.sh && sudo nano setup-server.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment