Skip to content

Instantly share code, notes, and snippets.

@psgganesh
Last active April 7, 2016 16:02
Show Gist options
  • Save psgganesh/3d9ed0d34e8fa773ce386fb48e5c9dd5 to your computer and use it in GitHub Desktop.
Save psgganesh/3d9ed0d34e8fa773ce386fb48e5c9dd5 to your computer and use it in GitHub Desktop.
KPM lemp project setup
# Name: kpm-setup.sh
# Description: Automated setup of LEMP stack with desired laravel project
# Author: Shankar <shankar.ganesh@ellipsonic.com>
# Twitter handle: @psgganesh
# USAGE
# CURL or WGET the RAW URL of this file and run below two commands
# 1. chmod +x kpm-setup.sh
# 2. sudo bash ./kpm-setup.sh
# Check your browser with the IP address of the host machine and viola, you have lemp installed and project setup
# Globals
php_config_file="/etc/php5/fpm/php.ini"
# Init
apt-get update
apt-get -y install sudo
apt-get -y install nano
# Step one, nginx
sudo apt-get -y install nginx
sudo service nginx restart
clear
echo "Please check http://localhost OR server_domain_name OR IP, you should get a nginx page"
sleep 10s
echo "Please enter project name"
read project_name
# Step two, php and it's dependencies, curl and git
sudo apt-get -y install php5-fpm php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-sqlite php5-tidy php5-xmlrpc php5-cli curl git
clear
sudo php5enmod mcrypt
sudo apt-get -y install imagemagick
sudo apt-get -y install php5-imagick
sudo php5enmod imagick
echo "Php and it's dependencies are installed !"
sleep 5s
# Step three, mysql and it's dependencies
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password password root'
sudo debconf-set-selections <<< 'mysql-server mysql-server/root_password_again password root'
sudo apt-get -y install mysql-server
# Create DB
echo "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION" | mysql -u root -proot
echo "GRANT PROXY ON ''@'' TO 'root'@'%' WITH GRANT OPTION" | mysql -u root -proot
mysql -u root -e "CREATE DATABASE IF NOT EXISTS ".$project_name." " -proot
mysql -u root -e "GRANT ALL PRIVILEGES ON ".$project_name.".* TO 'root'@'localhost' IDENTIFIED BY 'root'" -proot
mysql -u root -e "FLUSH PRIVILEGES" -proot
sleep 15s
clear
echo "mySQL and it's dependencies are installed !"
sleep 5s
# php.ini config change
sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g" ${php_config_file}
sudo service php5-fpm restart
# Get composer globally installed
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
# Get Lumen
mkdir /var/www/
cd /var/www/
rm-rf *
rm-rf .*
echo "Please enter git https url"
read project_clone_url
git clone ${project_clone_url} $project_name
# Reset base nginx web root
cd /etc/nginx/sites-enabled/default
sudo rm-rf .*
sudo rm-rf *
sudo rm -rf /etc/nginx/sites-enabled/default
sudo rm -rf /etc/nginx/sites-available/default
cd /etc/nginx/sites-available/
git clone https://gist.github.com/8d1790dd0c16ab5a4cde.git .
sed -i "s/;lumen/$project_name/g" /etc/nginx/sites-available/default
read site
sed -i "s/;server_domain_or_IP/$site/g" /etc/nginx/sites-available/default
sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/default
# Restart services
sudo service php5-fpm restart
sudo service nginx restart
# Composer install
cd /var/www/$project_name
sudo composer install
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment