Skip to content

Instantly share code, notes, and snippets.

@m5lil
Forked from mkhlil1288/SetupServer.md
Last active January 19, 2018 21:12
Show Gist options
  • Save m5lil/84a023227ff7e312ec05e3b32d322d32 to your computer and use it in GitHub Desktop.
Save m5lil/84a023227ff7e312ec05e3b32d322d32 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
dpkg -l | grep php | tee packages.txt
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install -y php7.2 php7.2-fpm php7.2-cli php7.2-curl php7.2-xml php7.2-zip php7.2-gd php7.2-mysql php7.2-mbstring php7.2-intl php7.2-mcrypt
sudo gedit /etc/php/7.0/fpm/php.ini

cgi.fix_pathinfo=0

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/example.com
sudo nano /etc/nginx/sites-available/example.com
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 ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/example.com

sudo chmod 755 /var/www
sudo chown -R www-data:www-data /var/www/html/laravel/public/

sudo nginx -t
sudo systemctl reload nginx    //or  sudo service nginx restart
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 php7.1

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

sudo apt-get install php7.1 php7.1-common

sudo apt-get install php7.1-curl php7.1-xml php7.1-zip php7.1-gd php7.1-mysql php7.1-mbstring
dpkg -l | grep php | tee packages.txt

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://[email protected]/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