Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thanhhaiqtvn/bf4eb03a4cd920f36854036b28153f11 to your computer and use it in GitHub Desktop.
Save thanhhaiqtvn/bf4eb03a4cd920f36854036b28153f11 to your computer and use it in GitHub Desktop.
HOW TO INSTALL LEMP(PHP 7.2.x, NGINX 1.10.x & MYSSQL5.7) & PHPMYADMIN

HOW TO INSTALL LEMP(PHP 7.2.x, NGINX 1.10.x & MYSSQL5.7) & PHPMYADMIN

Step 1: Install Nginx HTTP Server On Ubuntu
Step 2: Install MySQL to Manage Site Data
Step 3: Install PHP7.2 and PHP7.2-FPM
Step 4: Configure Nginx PHP-FPM Settings
Step 5: phpMyAdmin

---------------Step 1: Install Nginx HTTP Server On Ubuntu---------------

Install software-properties-common package to give us add-apt-repository package

sudo apt-get install -y software-properties-common

Install latest nginx version from community maintained ppa

sudo add-apt-repository ppa:nginx/stable

Update packages after adding ppa

sudo apt-get update

Install nginx

sudo apt-get install -y nginx

Check status

sudo service nginx

Start nginx if it is not already running

sudo service nginx start

---------------Step 2: Install MySQL to Manage Site Data---------------

You can install this easily by typing:

sudo apt-get install mysql-server

You will be asked to supply a root (administrative) password for use within the MySQL system.

The MySQL database software is now installed, but its configuration is not exactly complete yet.

To secure the installation, we can run a simple security script that will ask whether we want to modify some insecure defaults. Begin the script by typing:

mysql_secure_installation

---------------Step 3: Install PHP7.2 and PHP7.2-FPM---------------

check what is the latest PHP version supplied by UBUNTU

sudo apt-cache show php

Add Repository which gives us the latest php version 7.2

sudo add-apt-repository ppa:ondrej/php

Lets now check what is the latest PHP version available now after the repository is added

sudo apt-cache show php

Lets now install php7.2 and some important modules which we will need.

sudo apt-get install php7.2-cli php7.2-fpm php7.2-curl php7.2-gd php7.2-mysql php7.2-mbstring zip unzip

Once done all basic modules will be installed now, lets check the version now

php -v

Lets also check if the PHP7.2-FPM is running, if not start it

sudo service php7.2-fpm status
sudo service php7.2-fpm start ###### (if the service isn't running already)

Configure the PHP Processor

We now have our PHP components installed, but we need to make a slight configuration change to make our setup more secure.

Open the main php-fpm configuration file with root privileges:

sudo nano /etc/php/7.2/fpm/php.ini

What we are looking for in this file is the parameter that sets cgi.fix_pathinfo. This will be commented out with a semi-colon (;) and set to "1" by default.

This is an extremely insecure setting because it tells PHP to attempt to execute the closest file it can find if the requested PHP file cannot be found. This basically would allow users to craft PHP requests in a way that would allow them to execute scripts that they shouldn't be allowed to execute.

We will change both of these conditions by uncommenting the line and setting it to "0" like this:

/etc/php/7.0/fpm/php.ini
cgi.fix_pathinfo=0

Save and close the file when you are finished.

---------------Step 4: Configure Nginx PHP-FPM Settings---------------

Next, open the Nginx site configuration file… by default it’s stored at /etc/nginx/sites-available/default

If you have a custom file, then edit it to enable Nginx PHP support. Run the commands below to open Nginx default site configuration file

sudo nano /etc/nginx/sites-available/default

Then uncomment or remove the # symbol on the highlighted lines below to enable Nginx PHP support.

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

    location / {
        try_files $uri $uri/ =404;       
    }

  
     # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
               include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
               fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        }
}

Muốn nginx đọc được file cấu hình bạn phải tạo một symbolic link đến sites-enabled

ln -s /etc/nginx/sites-available/admin.nhanhviec.com /etc/nginx/sites-enabled/

lets now restart both nginx and php7.2-fpm

sudo service nginx reload sudo service php7.2-fpm restart

Now lets create a index.php file within the document root i.e. root /var/www/html;

touch /var/www/html/index.php

and put phpinfo() and save it.

now open http://localhost and you should see the screen with all php informaiton

---------------Step 5: phpMyAdmin---------------

Vào thư mục www chứa nội dung website, chạy lệnh sau:

sudo wget https://files.phpmyadmin.net/phpMyAdmin/4.4.14/phpMyAdmin-4.4.14-all-languages.tar.gz

Unzip:

sudo tar -xzvf phpMyAdmin-4.4.14-all-languages.tar.gz
sudo apt-get install php-mbstring php-gettext

Reference:

https://www.digitalocean.com/community/tutorials/how-to-install-linux-nginx-mysql-php-lemp-stack-in-ubuntu-16-04
https://www.thuysys.com/server-vps/web-server/cai-nginx-mysql-php-lemp-tren-ubuntu-16-04.html
https://hackernoon.com/add-new-users-to-ec2-and-give-ssh-key-access-d2abd084f30c
https://www.digitalocean.com/community/tutorials/how-to-add-swap-space-on-ubuntu-16-04
https://medium.com/@asked_io/how-to-install-php-7-2-x-nginx-1-10-x-laravel-5-6-f9e30ee30eff
https://gist.github.com/GhazanfarMir/03bd1f1f770a3834d47274586d46ea62
https://websiteforstudents.com/installing-nginx-mariadb-on-ubuntu-16-04-17-10-18-04-with-php-7-2-support-lemp/

Other:

install git ubuntu 16.04

sudo apt-get update
sudo apt-get install git

install composer

apt-get -y install composer

issue:

issue 1 Can't update composer(ubuntu 16.04)

  • Installation request for phpoffice/phpexcel 1.8.0 -> satisfiable by phpoffice/phpexcel[1.8.0].
  • phpoffice/phpexcel 1.8.0 requires ext-xml * -> the requested PHP extension xml is missing from your system.

https://askubuntu.com/questions/865442/cant-update-composerubuntu-16-04

sudo apt-get install php7.2-xmlrpc php7.2-xml

issue 2 To install GMP on PHP7 on Ubuntu:

Run: sudo apt-get install php7.2-gmp
And add the following to php.ini:
extension=php_gmp.so
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment