Skip to content

Instantly share code, notes, and snippets.



Last active May 18, 2018
What would you like to do?
Install LEMP stack
#!/usr/bin/env bash
# curl -LO
# chmod +x
# ./
echo "--- Welcome User. This is very exciting. ---"
echo "--- Updating packages list ---"
sudo apt-get install software-properties-common
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
echo "--- Installing phpmyadmin ---"
sudo apt install -y phpmyadmin
echo "--- Installing PHP-specific packages and Curl ---"
sudo apt-get -y install nginx php7.1 php7.1-cli php7.1-common php7.1-json php7.1-opcache php7.1-mysql php7.1-fpm php7.1-ldap php7.1-tidy php7.1-mbstring php7.1-xml php7.1-curl php7.1-zip
echo "--- Applying modifications to php7.1-fpm ---"
sudo sed -i '/cgi.fix_pathinfo=1/c cgi.fix_pathinfo=0' /etc/php/7.1/cli/php.ini
sudo sed -i '/max_execution_time = 30/c max_execution_time = 300' /etc/php/7.1/cli/php.ini
sudo sed -i '/upload_max_filesize = 2M/c upload_max_filesize = 80M' /etc/php/7.1/cli/php.ini
echo "--- Check if no error in nginx ----"
sudo nginx -t
echo "--- Restart PHP-FPM if everything is ok ---"
sudo systemctl restart php7.1-fpm.service
echo "--- Enable Nginx and PHP-FPM on system boot ---"
sudo systemctl enable nginx.service
sudo systemctl enable php7.1-fpm.service
# Create folder
sudo mkdir -p /var/www/app
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/php7.1-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
echo "--- Restarting php7.1-fpm and Nginx ---"
sudo /etc/init.d/nginx restart
sudo /etc/init.d/php7.1-fpm restart
# Create Swap File (Optional)
# sudo fallocate -l 1G /swapfile
# sudo mkswap /swapfile
# sudo swapon /swapfile
echo "--- Fetching and installing Composer ---"
sudo curl -sS | php
sudo mv composer.phar /usr/local/bin/composer
# echo "--- Installing node.js ---"
sudo apt-get install -y nodejs
sudo apt-get install -y npm
sudo chown -R :www-data /var/www/app
# sudo chmod -R 775 /var/www/app/storage
echo "--- Restarting php7.1-fpm and Nginx ---"
sudo /etc/init.d/nginx restart
sudo /etc/init.d/php7.1-fpm restart
echo "Rebooting server..."
sudo reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment