Install Nginx, MariaDB and PHP-FPM (LEMP) on Ubuntu 17.10
Nginx, MariaDB, PHP-FPM (LEMP) is an alternative to LAMP. LEMP is an acronym for Linux, Nginx, MySQL / MariaDB and PHP. It’s collection of opensource software that powers some of the most popular websites and applications online today.
This brief tutorial shows students and new users how to install LEMP on Ubuntu 17.10. This website is powered by LEMP. I run a Ubuntu server with Nginx, MariaDB and PHP-FPM installed. If you need to run a PHP-based website like WordPress, Drupal or Joomla, then LEMP or LAMP should be considered.
In the part Linux, Apache2, MySQL and PHP (LAMP) was the preferred choice to run dynamic PHP based applications and website. Now, LEMP is rapidly gaining traction because of Nginx HTTP server. Nginx is lightweight, robust, and powerful HTTP server that some of the busiest websites use. It can also serve as a reversed proxy.
To get LEMP installed on Ubuntu 17.10, follow the steps below:
Step 1: Update Ubuntu server
Update Ubuntu first before installing additional software and packages. This assumes that you have administrative (root) rights to the systems and can install packages from the command line. To update Ubuntu server, run the commands below:
sudo apt update && sudo apt dist-upgrade && sudo apt autoremove
Step 2: Install Nginx HTTP Server
After updating Ubuntu, run the commands below to install Nginx HTTP server.
sudo apt install nginx
After installing Nginx, the commands below can be used to stop, start, disable and enable Nginx service
sudo systemctl stop nginx.service sudo systemctl start nginx.service sudo systemctl disable nginx.service sudo systemctl enable nginx.service
Step 3: Install MariaDB Database Server
MariaDB is a drop-in replacement for MySQL and the default opensource database server. To install MariaDB run the commands below
sudo apt install mariadb-server mariadb-client
After installing, the commands below can be used to stop, start and enable MariaDB service to always start up when the server boots.
sudo systemctl stop mariadb.service sudo systemctl start mariadb.service sudo systemctl enable mariadb.service
After that, run the commands below to secure MariaDB server.
sudo mysql_secure_installation
When prompted, answer the questions below by following the guide.
- Enter current password for root (enter for none): Just press the Enter
- Set root password? [Y/n]: Y
- New password: Create password
- Re-enter new password: Repeat password
- Remove anonymous users? [Y/n]: Y
- Disallow root login remotely? [Y/n]: Y
- Remove test database and access to it? [Y/n]: Y
- Reload privilege tables now? [Y/n]: Y
Continue below to install PHP-FPM and related PHP modules.
Step 4: Installing PHP-FPM on Ubuntu
The last step is to install PHP-FPM and other PHP modules on Ubuntu to get the LEMP stack complete.
To install PHP-FPM run the commands below:
sudo apt install php-fpm
For most PHP applications to function properly, you must also install related PHP modules. Run the commands below to get as much installed.
sudo apt install php-mbstring php-xmlrpc php-soap php-gd php-xml php-intl php-mysql php-cli php-mcrypt php-ldap php-zip php-curl
Step 5: Configure Nginx to use PHP-FPM
Now that LEMP is installed, open Nginx default configuration file and enable PHP-FPM configuration… To do that, run the commands below:
sudo nano /etc/nginx/sites-available/default
Then edit the highlighted lines below and save.
server { listen 80 default_server; listen [::]:80 default_server; ............ ............ index index.php index.html index.htm; # 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.1-fpm.sock; # # With php-cgi (or other tcp sockets): # fastcgi_pass 127.0.0.1:9000; } ..........
Congratulations! You’ve successfully installed LEMP!
You may also like the post below:
You forgot to put the configuration for nginx
Thanks.. updated.
Very good instructions! Everything worked including WordPress