Last active
September 6, 2022 19:10
-
-
Save deepaksp/366177865ccdd1bfe7906bb1f1422891 to your computer and use it in GitHub Desktop.
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 | |
ARG=$1 | |
if [ "$ARG" = "-i" ] || [ "$ARG" = "-a" ]; then | |
echo 'Website Name ? (example.com)' | |
read site | |
echo 'Website Script Directory ? (/var/www/example)' | |
read site_dir | |
cd /tmp | |
fi | |
function install_base() { | |
echo 'install base (php ppa, git, zip, imagick)' | |
sudo apt-get install -y language-pack-en-base software-properties-common | |
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 | |
} | |
function install_nginx() { | |
echo "install nginx" | |
sudo apt-get install nginx -y | |
# add nginx config | |
rm -f /etc/nginx/sites-enabled/default | |
rm -f /etc/nginx/sites-available/default | |
} | |
function install_php() { | |
echo "install php and composer" | |
sudo apt-get install php$phpver-fpm php$phpver-mysql php$phpver-pdo php$phpver-mbstring php$phpver-xml php$phpver-curl php$phpver-gd php$phpver-mbstring php$phpver-imagick -y | |
curl -sS https://getcomposer.org/installer | php | |
sudo mv composer.phar /usr/local/bin/composer | |
} | |
function add_nginx_site() { | |
cat <<EOF > "/etc/nginx/sites-available/$site" | |
server { | |
server_name www.$site; | |
return 301 \$scheme://$site\$request_uri; | |
} | |
server { | |
listen 80; | |
root $site_dir; | |
index index.php index.html index.htm; | |
server_name $site; | |
location / { | |
try_files \$uri \$uri/ /index.php?\$args; | |
} | |
location ~ \.php\$ { | |
include snippets/fastcgi-php.conf; | |
fastcgi_pass unix:/run/php/php$phpver-fpm.sock; | |
} | |
} | |
EOF | |
ln -s "/etc/nginx/sites-available/$site" "/etc/nginx/sites-enabled/$site" | |
service nginx restart | |
} | |
function add_nginx_php_conf() { | |
#nginx config (add client max body size for large upload) | |
cat <<EOF > "/etc/nginx/conf.d/z_custom.conf" | |
client_max_body_size 100M; | |
EOF | |
#php config custom ini for large upload and opcache setup | |
cat <<EOF > "/etc/php/$phpver/fpm/conf.d/php.ini" | |
[PHP] | |
engine = On | |
error_reporting = E_ALL | |
expose_php = Off | |
log_errors = On | |
memory_limit = 512M | |
output_buffering = 4096 | |
post_max_size = 50M | |
register_argc_argv = Off | |
request_order = "GP" | |
short_open_tag = Off | |
upload_max_filesize = 50M | |
variables_order = "GPCS" | |
[CLI Server] | |
cli_server.color = On | |
[Date] | |
date.timezone = UTC | |
[Assertion] | |
zend.assertions = -1 | |
[opcache] | |
opcache.enable = 1 | |
opcache.interned_strings_buffer = 64 | |
opcache.max_accelerated_files = 30000 | |
opcache.memory_consumption = 512 | |
opcache.save_comments = 1 | |
opcache.validate_timestamps = 0 | |
[Date] | |
date.timezone="UTC" | |
EOF | |
mv /etc/php/$phpver/fpm/pool.d/www.conf /etc/php/$phpver/fpm/pool.d/www.conf_bak | |
cat > /etc/php/$phpver/fpm/pool.d/www.conf << EOF | |
[www] | |
user = www-data | |
group = www-data | |
listen = /run/php/php$phpver-fpm.sock | |
listen.owner = www-data | |
listen.group = www-data | |
listen.mode = 0666 | |
pm = dynamic | |
pm.max_children = 24 | |
pm.start_servers = 2 | |
pm.min_spare_servers = 1 | |
pm.max_spare_servers = 3 | |
request_terminate_timeout = 60 | |
EOF | |
phpdismod xdebug #disable xdebug #phpenmod xdebug enable xdebug | |
service php$phpver-fpm restart | |
service nginx restart | |
} | |
function install_mysql() { | |
export DEBIAN_FRONTEND="noninteractive" | |
# https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-22-04 | |
apt-get install mysql-client mysql-server -y | |
mysql -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '$mysql_pass'" | |
mysql -e "FLUSH PRIVILEGES" | |
service mysql restart | |
} | |
function install_webmin() { | |
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 | |
} | |
function add_worker_conf() { | |
#sample setting for laravel queue | |
if [ $add_worker != "no" ]; then | |
cat <<EOF > /etc/supervisor/conf.d/laravel-worker.conf | |
[program:laravel-worker] | |
process_name=%(program_name)s_%(process_num)02d | |
command=php $add_worker 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 | |
} | |
if [ "$ARG" = "-i" ]; then | |
echo 'PHP Version to spin ? (7.3, 7.2 or 7.1)' | |
read phpver | |
echo 'MYSQL Password (keep a-z-0-9 avoid symbols)' | |
read mysql_pass | |
echo 'install webmin ? (yes or no)' | |
read install_webmin | |
echo 'install redis server ? (yes or no)' | |
read install_redis | |
echo 'install Supervisor ? (yes or no)' | |
read install_supervisor | |
if [ $install_supervisor = "yes" ]; then | |
echo 'Add Laravel Worker Config ?? (no or artisan path /var/site/artisan)' | |
read add_worker | |
fi | |
if [ $install_webmin = "yes" ]; then | |
echo 'Webmin Password ?? (keep a-z-0-9 avoid symbols)' | |
read webmin_pass | |
fi | |
install_base | |
install_nginx | |
install_php $phpver | |
add_nginx_site $site $site_dir $phpver | |
add_nginx_php_conf $phpver | |
install_mysql $mysql_pass | |
if [ $install_webmin = "yes" ]; then | |
install_webmin $webmin_pass | |
fi | |
if [ $install_redis = "yes" ]; then | |
sudo apt-get install redis-server -y | |
fi | |
if [ $install_supervisor = "yes" ]; then | |
sudo apt-get install supervisor -y | |
add_worker_conf $add_worker | |
fi | |
elif [ "$ARG" == "-a" ]; then | |
echo 'Active PHP Version (7.3, 7.2 or 7.1)' | |
read phpver | |
add_nginx_site $site $site_dir $phpver | |
else | |
echo "Argument missing" | |
echo "-i for install [First Time User]" | |
echo "-a add nginx site" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment