Skip to content

Instantly share code, notes, and snippets.

@godfreymakori
Last active April 19, 2020 04:38
Show Gist options
  • Save godfreymakori/ab483f8bef8c315b10bcf716f1c49d14 to your computer and use it in GitHub Desktop.
Save godfreymakori/ab483f8bef8c315b10bcf716f1c49d14 to your computer and use it in GitHub Desktop.
Laravel LEMP Setup --
# Instructions
# 1. Replace laravel-app-folder with your laravel app folder name
server {
listen 80 default_server;
listen [::]:80 default_server;
client_max_body_size 200M;
# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
# include snippets/snakeoil.conf;
root /home/ubuntu/laravel-app-folder/public;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
#!/usr/bin/env bash
# Usage Instructions
1. Copy the two files setup.bash and nginx.config into the root of your laravel project
2. In the nginx.conf file replace laravel-app-folder with your actual laravel app folder/repository name
3. Configure the 4 variables (APPFOLDER,DBNAME,DBUSER and DBPASSWD) for your live environment
4. In your laravel project create .env.live file with your live .env file
5. Push the changes to your remote repo
6. Clone the project folder to your server
7. cd into your laravel project folder and run the following command
8. sudo bash setup.sh
# Variables
APPFOLDER=laravel-app-folder
DBNAME=yourdbname
DBUSER=root
DBPASSWD=YourDBPasswordHere
sudo apt-get install -y python-software-properties
sudo add-apt-repository -y ppa:ondrej/php
sudo add-apt-repository -y ppa:chris-lea/redis-server
sudo apt-get update -y
sudo apt install -y nginx redis-server nodejs
sudo apt install -y git curl unzip
sudo apt install -y php7.2-fpm php7.2-common php7.2-cli php7.2-sqlite3 php7.2-mysql php7.2-gd php7.2-curl
sudo apt install -y php7.2-memcached php7.2-imap php7.2-mbstring php7.2-xml php7.2-zip php7.2-bcmath php7.2-soap
sudo apt install -y php7.2-intl php7.2-readline php7.2-dev php7.2-bcmath php7.2-memcached php-pear
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password password $DBPASSWD"
sudo debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $DBPASSWD"
sudo apt-get -y install mysql-server
mysql -u$DBUSER -p$DBPASSWD -e "CREATE DATABASE $DBNAME"
sudo cp nginx.conf /etc/nginx/sites-available/default
cd ~
curl -sS https://getcomposer.org/installer -o composer-setup.php
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
# restart all services
sudo systemctl restart php7.2-fpm
sudo systemctl restart nginx
sudo systemctl restart mysql
sudo systemctl restart redis-server
#Laravel Related
cd $APPFOLDER
composer install
cp ./.env.live .env
sudo chmod -R 0777 storage/
sudo chmod -R 0777 bootstrap/cache/
php artisan key:generate
php artisan config:clear
php artisan migrate --seed
php artisan storage:link
echo -e "\n\n $APPFOLDER is ready and live! :)\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment