Skip to content

Instantly share code, notes, and snippets.

@nguyenthanhcong101096
Last active May 5, 2020 16:19
Show Gist options
  • Save nguyenthanhcong101096/7d7da73371aeb8dd9d2f9217e8f9e75d to your computer and use it in GitHub Desktop.
Save nguyenthanhcong101096/7d7da73371aeb8dd9d2f9217e8f9e75d to your computer and use it in GitHub Desktop.
Push Project Laravel to EC2

Deploy Laravel to EC2

Install PHP 7.1 with Nginx on Ubuntu 16.04

Step 1: Enable PPA

sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update

Step 2: Install PHP 7.1

sudo apt-get install php7.1

Step 3: Search and install specific PHP 7.1 modules

sudo apt-cache search php7.1

Step 4: Install most commonly used modules

sudo apt-get install php7.1 php7.1-cli php7.1-common php7.1-pgsql php7.1-json php7.1-opcache php7.1-mysql php7.1-mbstring php7.1-mcrypt php7.1-zip php7.1-fpm

This solved my issues
sudo apt-get install php7.1-xml

Step 5: Configure php.ini file

php --ini |grep Loaded
Loaded Configuration File: /etc/php/7.1/cli/php.ini

Edit the file using your favorite text editor:

sudo nano /etc/php/7.1/cli/php.ini Make the following changes:

cgi.fix_pathinfo=0

Then, restart the PHP-FPM service:

sudo systemctl restart php7.1-fpm.service

Step 6: Install Nginx on Ubuntu 16.04

sudo apt-get install nginx

server {
    listen 80;
    listen [::]:80;
    root /var/www/html/MyProject/public;
    index  index.php index.html index.htm;
    server_name  example.com;

    location / {
        try_files $uri $uri/ /index.php?$query_string;        
    }

  
    location ~ \.php$ {
         try_files $uri =404;
         fastcgi_split_path_info  ^(.+\.php)(/.+)$;
         fastcgi_index            index.php;
         fastcgi_pass             unix:/var/run/php/php7.1-fpm.sock;
         include                  fastcgi_params;
         fastcgi_param   PATH_INFO       $fastcgi_path_info;
         fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

}

Check if there are errors with the configuration:

sudo nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

If the syntax is OK and there are no errors you can restart Nginx.

sudo systemctl restart nginx.service

Enable Nginx and PHP-FPM on system boot:

sudo systemctl enable nginx.service
sudo systemctl enable php7.1-fpm.service

Step 7: Install composer

sudo curl -O sudo curl -O https://getcomposer.org/composer.phar
sudo mv composer.phar composer
sudo mv composer /usr/local/bin/

Step 8: setup project

clone project tu github ve

chay composer install hoac composer update chay yarn install mv env.example to .env

-Permit Laravel

sudo chown -R :www-data /var/www/laravel
sudo chmod -R 775 /var/www/laravel/storage
sudo chmod -R 775 /var/www/laravel/bootstrap/cache
sudo chown -R $USER:www-data storage
sudo chown -R $USER:www-data bootstrap/cache
then to set directory permission try this:

chmod -R 775 storage
chmod -R 775 bootstrap/cache
Update:

Webserver user and group depend on your webserver and your OS. to figure out what's your web server user and group use the following commands. for nginx use:

ps aux|grep nginx|grep -v grep

1 so lenh

sudo service php7.1-fpm restart
sudo service php7.1-fpm status

refs: https://websiteforstudents.com/install-laravel-on-ubuntu-17-04-17-10-with-nginx-mariadb-and-php-support/ https://www.rosehosting.com/blog/install-php-7-1-with-nginx-on-an-ubuntu-16-04-vps/ https://medium.com/@sagarnasit/deploy-laravel-application-with-lemp-stack-ubuntu-and-enginx-e82a4445b3d2 https://www.youtube.com/watch?v=p_VwZTmyG5o

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