How to Install Nginx with PHP and MySQL (LEMP Stack) on Ubuntu 18.04
0

Nginx (pronounced “engine x”) is a free, open-source, high-performance HTTP server. Nginx is thought for its stability, wealthy characteristic set, easy configuration, and low useful resource consumption. This tutorial exhibits how one can set up Nginx on an Ubuntu 18.04 LTS server with PHP 7.2 help (by means of PHP-FPM) and MySQL help (LEMP = Linux + nginx (pronounced “engine x”) + MySQL + PHP).

Conditions

  • Ubuntu 18.04 LTS Server
  • Root privileges

What we are going to do?

  1. Set up Nginx
  2. Set up MySQL
  3. Set up PHP-FPM
  4. Configure Nginx and PHP-FPM
  5. Set up PhpMyAdmin
  6. Configure PhpMyAdmin
  7. Testing

Step 1 – Set up Nginx

Nginx or engine x is a high-performance HTTP and proxy server with low reminiscence consumption. Most large-scale web sites like Netflix, Pinterest, CloudFlare, GitHub are utilizing Nginx.

On this step, we are going to set up Nginx internet server from the Ubuntu repository.

Run the command under.

sudo apt set up nginx -y

After the set up is full, begin the Nginx service and allow it to launch each time at system boot.

systemctl begin nginx
systemctl allow nginx

The Nginx set up is full.

Configure the Firewall

It is really helpful to activate the firewall on the server.

Add the SSH and HTTP service port to the firewall configuration.

Run the UFW command under.

ufw permit ssh
ufw permit http

Now begin the UFW firewall and allow it to launch everytime at system boot.

ufw allow

The Nginx internet server is up and working underneath the UFW firewall.

UFW Firewall Configuration

Step 2 – Set up MySQL

MySQL is the most well-liked open supply Relational Database Administration System (RDBMS) created by Oracle Company. It is a central element of the LEMP Stack, and we are going to set up the most recent MySQL model from the Ubuntu repository.

Set up MySQL utilizing the apt command under.

sudo apt set up mysql-server mysql-client -y

After the MySQL set up is full, begin the MySQL service and allow it to launch everytime at system boot.

systemctl begin mysql
systemctl allow mysql

Install MySQL database server

And we have put in MySQL 5.7 on Ubuntu 18.04 server.

Step 3 – Set up PHP-FPM

PHP-FPM or FastCGI Course of Supervisor is an alternate for the older PHP FastCGI which offers extra options and pace enhancements. It fits effectively for small to giant websites based mostly on the PHP programming language.

On this step, we are going to set up PHP7.2-FPM with some extra extensions required by phpmyadmin.

Set up PHP-FPM utilizing the command under.

sudo apt set up php7.2 php7.2-fpm php7.2-cli php7.2-curl php7.2-mysql php7.2-curl php7.2-gd php7.2-mbstring php-pear -y

Now begin the PHP-FPM service and allow it to launch each time at system boot in spite of everything set up is full.

systemctl begin php7.2-fpm
systemctl allow php7.2-fpm

PHP7.2-FPM is up and working on Ubuntu 18.04 underneath the sock file, examine it utilizing the netstat command.

netstat -pl | grep php

Install and test PHP FPM

Step 4 – Configure Nginx and PHP-FPM

On this step, we are going to configure the Nginx internet server and PHP-FPM.

Configure Nginx

Go to the ‘/and so forth/nginx’ configuration listing, and edit the ‘nginx.conf’ file utilizing vim or nano. 

cd /and so forth/nginx/
vim nginx.conf

Uncomment the next traces.

keepalive_timeout 2;
 server_tokens off;

Save the configuration file and exit the editor.

Now edit the default Nginx digital host file.

vim sites-available/default

Uncomment the PHP line proven under and alter the sock file line.

        location ~ .php$ {
                 embody snippets/fastcgi-php.conf;
         #
         # # With php-fpm (or different unix sockets):
                 fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
         # # With php-cgi (or different tcp sockets):
         # fastcgi_pass 127.2.0.1:9000;
         }

Save and exit.

Take a look at Nginx configuration and ensure there isn’t a error, then restart the service.

nginx -t
systemctl reload nginx

Restart Nginx and test the configuration

Configure PHP-FPM

Go to the ‘/and so forth/php/7.2’ listing and edit the ‘php.ini’ file.

cd /and so forth/php/7.2/
vim fpm/php.ini

Uncomment the ‘cgi.fix_patinfo’ line and alter the worth to ‘0’.

cgi.fix_pathinfo=0

Save and exit.

Reload the PHP-FPM service.

systemctl reload php7.2-fpm

And we have accomplished configuration of Nginx internet server and PHP-FPM.

Step 5 – Set up PhpMyAdmin

PhpMyAdmin is a PHP based mostly software to handle MySQL or MariaDB databases from an online browser.

On this step, we are going to set up and configure phpmyadmin underneath the LEMP (Linux, Nginx, MySQL, and PHP-FPM) stack.

Set up PHPMyAdmin utilizing the apt command under.

sudo apt set up phpmyadmin -y

Throughout the set up, it’ll ask you in regards to the internet server configuration for phpmyadmin.

Install PHPMyAdmin

Select none choice and transfer the cursor to ‘OK’.

For the phpmyadmin database configuration, select ‘Sure’.

Do not select to configure a web server

And sort new ‘STRONG’ phpmyadmin admin equivalent to ‘[email protected]#’.

Enter a password

Repeat the ‘[email protected]#’ password.

repeat the password

And the phpmyadmin set up is full.

Step 6 – Configure PhpMyAdmin

After the phpmyadmin set up, we have to configure phpmyadmin to run underneath the Nginx internet server and configure the MySQL consumer phpmyadmin entry.

Configure PhpMyAdmin with Nginx

To be able to run phpmyadmin underneath the Nginx internet server, we have to add the configuration to the digital host configuration file.

Go to the ‘/and so forth/nginx’ configuration listing, and edit the default digital host file.

cd /and so forth/nginx/
vim sites-available/default

Paste the next Nginx configuration for phpmyadmin contained in the ‘server {…}’ bracket.

location /phpmyadmin {
     root /usr/share/;
     index index.php;
     try_files $uri $uri/ =404;
 
 location ~ ^/phpmyadmin/(doc|sql|setup)/ {
     deny all;
     }
 
 location ~ /phpmyadmin/(.+.php)$ {
     fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     embody fastcgi_params;
     embody snippets/fastcgi-php.conf;
     }
 }

Save and exit.

Take a look at the nginx configuration and restart the nginx service.

nginx -t
systemctl reload nginx

And we have added the Nginx configuration for phpmyadmin.

Configure MySQL Consumer for PhpMyAdmin

On this tutorial, we can be utilizing non-root MySQL consumer for phpmyadmin. We’ll create a brand new consumer and grant all privileges of database contained in the server to the consumer.

Login to the MySQL shell.

mysql -u root -p

Now create a brand new consumer utilizing the MySQL queries under.

create consumer [email protected]'localhost' recognized by '[email protected]#';
grant all privileges on *.* to [email protected]'localhost' recognized by '[email protected]#';
flush privileges;
exit;

And we have created a brand new consumer for phpmyadmin entry.

Configure a MySQL user

Step 7 – Testing

Take a look at PHP Information

Go to the web-root listing ‘/var/www/html’ and create a brand new phpinfo file.

cd /var/www/html/
vim data.php

Paste the phpinfo script under.

<?php
 phpinfo();
 ?>

Save and exit.

Now open the net browser and kind the server IP handle as proven under. Substitute the IP along with your server ip.

http://192.168.33.10/info.php

And under is all details about PHP server configuration.

PHP Info result

Take a look at Login PhpMyAdmin

On the internet browser, kind the next phpmyadmin URL (change the IP along with your server IP).

http://192.168.33.10/phpmyadmin/

On the phpmyadmin login web page, kind the consumer ‘hakase’ with password ‘[email protected]#’ and click on the ‘Go’ button.

PHPMyAdmin login

Now we are going to see the phpmyadmin dashboard as under.

PHPMyAdmin dashboard

The LEMP Stack and PhpMyAdmin are efficiently put in on Ubuntu 18.04 LTS.

E mail chain prompts Microsoft to research stories of sexual harassment ignored by HR

Previous article

Android Q Beta 2, a deep dive

Next article

You may also like

Comments

Leave a Reply

More in Linux