Skip to content

Instantly share code, notes, and snippets.

@mannysoft
Last active April 25, 2022 04:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mannysoft/9c502d38c0912e45627ffa4343dd483a to your computer and use it in GitHub Desktop.
Save mannysoft/9c502d38c0912e45627ffa4343dd483a to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
echo "--- Welcome User. This is very exciting. ---"
echo "--- Updating packages list ---"
sudo apt-get install software-properties-common
#https://colorfield.be/blog/fix-following-signatures-couldnt-be-verified-because-public-key-not-available-ubuntu-1604
sudo add-apt-repository ppa:ondrej/nginx
sudo add-apt-repository ppa:ondrej/nginx-mainline
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
echo "--- Installing text editor NANO ---"
sudo apt-get install -y nano
echo "--- Installing git ---"
sudo apt-get install -y git-core
echo "--- Installing MySQL ---"
sudo apt-get update
sudo apt-get install -y mysql-server
sudo mysql_secure_installation
# https://www.digitalocean.com/community/tutorials/how-to-install-mysql-on-ubuntu-18-04
# If access denied https://phoenixnap.com/kb/access-denied-for-user-root-localhost
echo "--- Installing PHP-specific packages and Curl ---"
sudo apt-get -y install nginx php8.1 php8.1-cli php8.1-common php8.1-opcache php8.1-mysql php8.1-fpm php8.1-ldap php8.1-tidy php8.1-bcmath php8.1-mbstring php8.1-xml php8.1-curl php8.1-zip php8.1-gd php8.1-sqlite3 php8.1-redis php8.1-intl --allow-unauthenticated
echo "--- Applying modifications to php8.1-fpm ---"
sudo sed -i '/cgi.fix_pathinfo=1/c cgi.fix_pathinfo=0' /etc/php/8.1/cli/php.ini
sudo sed -i '/max_execution_time = 30/c max_execution_time = 300' /etc/php/8.1/cli/php.ini
sudo sed -i '/upload_max_filesize = 2M/c upload_max_filesize = 80M' /etc/php/8.1/cli/php.ini
sudo sed -i '/post_max_size = 8M/c post_max_size = 80M' /etc/php/8.1/cli/php.ini
sudo sed -i '/upload_max_filesize = 2M/c upload_max_filesize = 80M' /etc/php/8.1/fpm/php.ini
sudo sed -i '/post_max_size = 8M/c post_max_size = 80M' /etc/php/8.1/fpm/php.ini
echo "--- Check if no error in nginx ----"
sudo nginx -t
echo "--- Restart PHP-FPM if everything is ok ---"
sudo systemctl restart php8.1-fpm.service
sudo systemctl restart nginx.service
echo "--- Enable Nginx and PHP-FPM on system boot ---"
sudo systemctl enable nginx.service
sudo systemctl enable php8.1-fpm.service
# Create folder
sudo mkdir -p /var/www/app
sudo mkdir -p /var/www/app/public
echo "--- Configuring default Nginx site to support Laravel ---"
cat << 'EOF' | sudo tee /etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/app/public;
index index.php index.html index.htm;
# Make site accessible from http://localhost/
server_name localhost;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ /index.php?$query_string;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
EOF
# set client body size to 2M #
# Add the following line to http or server or location context to increase the size limit in nginx.conf, enter:
client_max_body_size 20M;
echo "--- Restarting php8.1-fpm and Nginx ---"
sudo systemctl restart php8.1-fpm.service
sudo systemctl restart nginx.service
# Create Swap File (Optional)
# sudo fallocate -l 1G /swapfile
# sudo mkswap /swapfile
# sudo swapon /swapfile
echo "--- Fetching and installing Composer ---"
sudo curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
# echo "--- Installing node.js ---"
sudo apt-get install -y nodejs --allow-unauthenticated
sudo apt-get install -y npm --allow-unauthenticated
#laravel-echo-server start
#nodejs-legacy
#sudo chown -R username /var/www/app
sudo chown -R www-data /var/www
# sudo chmod -R 775 /var/www/app/storage
echo "--- Restarting php8.1-fpm and Nginx ---"
sudo systemctl restart php8.1-fpm.service
sudo systemctl restart nginx.service
#phpmyadmin
#sudo apt-get install -y --allow-unauthenticated phpmyadmin
# sudo ln -s /usr/share/phpmyadmin /var/www/app/public
echo "Rebooting server..."
sudo reboot
# Install SSL Certificate
# https://www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04
sudo apt-get update
sudo apt-get install certbot
sudo apt-get install python3-certbot-nginx
sudo certbot --nginx -d example.com -d www.example.com
# Set up subdomain
#https://hackprogramming.com/how-to-setup-subdomain-or-host-multiple-domains-using-nginx-in-linux-server/
# Install MailHog for email testing
# https://gist.github.com/mannysoft/a0238f5c33c4c294064ec5f563564961
# Install supervisor
sudo apt-get install supervisor -y
# https://laravel.com/docs/7.x/queues#running-the-queue-worker
# Nginx file upload
# https://www.tecmint.com/limit-file-upload-size-in-nginx/
# client_max_body_size 100M;
# MongoDB
# https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/
sudo apt-get install php-mongodb
# Using Mac
pecl install mongodb
# Check
php -i | grep mongodb
# Git so that it wont ask for username and password
# git config credential.helper store - stores the credentials indefinitely.
# git config credential.helper 'cache --timeout=3600'- stores for 60 minutes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment