Skip to content

Instantly share code, notes, and snippets.

@devSarry
Forked from mkhlil1288/SetupServer.md
Created February 8, 2017 18:44
Show Gist options
  • Save devSarry/b64bfcd945da665213cce31fe4022775 to your computer and use it in GitHub Desktop.
Save devSarry/b64bfcd945da665213cce31fe4022775 to your computer and use it in GitHub Desktop.
Setup server ( Ubuntu 16 - LEMP - GitHooks - ... )

Setup My Server

sudo apt-get update
sudo apt-get install git
sudo apt-get install nodejs
sudo ln -s /usr/bin/nodejs /usr/bin/node
sudo apt-get install npm
sudo npm install --global gulp
sudo apt-get install nginx
sudo apt-get install mysql-server
sudo mysql_secure_installation
sudo apt-get install php-fpm php-mysql php-mbstring
sudo nano /etc/php/7.0/fpm/php.ini

cgi.fix_pathinfo=0

sudo nano /etc/nginx/sites-available/default
server {
        listen 80 default_server;
        listen [::]:80 default_server;
        
        root /var/www/laravel/public;
        index index.php index.html index.htm index.nginx-debian.html;
        
        server_name 160.153.231.194;
        
        location / {
                try_files $uri $uri/ /index.php?$query_string;
        }
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
                fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        }
        location ~ /\.ht {
                deny all;
        }
}
sudo nginx -t
sudo systemctl reload nginx
sudo mkdir -p /var/www/laravel
sudo service nginx restart

Create Swap File (Optional)

sudo fallocate -l 1G /swapfile
sudo mkswap /swapfile
sudo chmod 0600 /swapfile
sudo swapon /swapfile

install Composer (after Swap File for tiny ram servers)

cd ~
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

Setting Up Git Hooks

cd /var
mkdir repo && cd repo
mkdir site.git && cd site.git
git init --bare
cd hooks/
sudo nano post-receive
#!/bin/sh
git --work-tree=/var/www/laravel --git-dir=/var/repo/site.git checkout -f
sudo chmod +x post-receive

Set up our Local Computer to Push to Production

git remote add production ssh://root@example.com/var/repo/site.git
git push production master

Database Setup

mysql -u root -p
SHOW DATABASES;
CREATE DATABASE blog;

Other Useful Terminal Code

sudo tail -f /var/log/nginx/error.log
sudo service php7.0-fpm restart

sudo chown -R m5lil:m5lil laravel/
sudo chown -R :www-data /var/www/laravel
sudo chmod -R 775 /var/www/laravel/bootstrap/cache
sudo chmod -R 775 /var/www/laravel/storage

sudo chown -R m5lil:m5lil /var/repo/site.git/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment