Install LEMP (Linux, Nginx, MariaDB and PHP) in Ubuntu 15.10

Ubuntu 15.10Wily Werewolf has been released a few days back and you can now easily install LEMP on it.

For those of you who don’t know what LEMP is – this is a combination of software packages – Linux, Nginx (pronounced EngineX), MariaDB and PHP. You can use LEMP for both testing purposes or in a real production environment to deploy web applications.

Install LEMP on Ubuntu 15.10

You may wonder what’s the different between LAMP and LEMP. Well the only different is the web server that is included – Apache (in LAMP) and Nginx (in LEMP). Both web servers are pretty good and while Apache is the most frequently used one, Nginx doesn’t back down in any way.

If you looking for a LAMP setup for your Ubuntu 15.10, then you should follow our LAMP setup guide here:

Prerequisites:

Step 1: Installing Nginx Web Server

1.Nginx is a fast modern web server designed to server many concurrent connections without consuming too much server resources. This is why it’s often the preferred choice in enterprise environments.

You can setup Nginx on your Ubuntu 15.10 desktop or server by running the following command:

$ sudo apt-get install nginx

Install Nginx in Ubuntu 15.10

2. Now it’s time to check if the Nginx installation was successful by calling the Nginx page via browser using server IP Address.

If you don’t know your Server IP address, you can find using ip command as shown.

$ ip addr show

Find Server IP Address

3. Now copy that IP address and paste it in the address bar of your browser. You should see the default Nginx page:

http://server-ip-address

Confirm Nginx Installation

If you need to modify the Nginx settings, you can find its configuration file in:

/etc/nginx/nginx.conf

Step 2: Installing MariaDB Database

4. MariaDB is relatively new relational database management system which was designed as community fork of MySQL after it’s Oracle acquisition.

The installation of MariaDB is simple and can be started with command as:

$ sudo apt-get install mariadb-server mariadb-client

Install MariaDB in Ubuntu 15.10

5. If you wish to improve the MariaDB security, you can run the mysql_secure_installation command, which will provide some basic, yet important options to configure:

$ sudo mysql_secure_installation

Secure MySQL Installation

6. You will be asked to enter the MySQL/MariaDB root password. The default one is empty so you may simply press enter. After that you will be asked if you wish to setup new password for MariaDB root user:

Set MySQL root Password

7. By default MariaDB allows connections from anonymous users. You should disable anonymous logins as well as disable remote root access to the databases on your database server.

Usually you will be creating separate users who have privileged users to each database. This is why anonymous and remote root connections should be disabled:

Remove MySQL Anonymous User

8. When installing MariaDB it creates a "test" database. You will be asked if you wish to remove it. The recommended answer is yes:

Remove MySQL test Database

9. Finally to implement the changes you just made, you will need to reload the privilege table. Simply use "y" as answer:

Your MariaDB installation is now complete and secured. To start and check the service status, use the following commands:

$ sudo service mysql start
$ sudo service mysql status

Start MariaDB Service

10. If you wish to modify the configuration settings of MariaDB you will need to edit the following file:

/etc/my.cnf

Keep in mind that each time you modify the file, you will need to restart the MariaDB service with:

$ sudo service mysql restart

Step 3: Installing PHP Language

11. PHP is programming language designed for building dynamic web applications. You can easily install it on your Ubuntu 15.10 by using:

$ sudo apt-get install php5-fpm php5-mysql

Install PHP and PHP-FPM in Ubuntu 15.10

12. As php5-fpm runs as service you will need to start it with the following command:

$ sudo service php5-fpm start
$ sudo service php5-fpm status

Start PHP-FPM Service

Step 4: Configure Nginx Web Server

13. Next we need to configure Nginx so that it can use PHP that we just installed. To do that, we need to modify the server blocks.

Server blocks are similar to Apache vhosts. To edit the server blocks, you need to modify the following file with root privileges:

Make sure to change server_domain_name_or_IP with your actual domain or IP address. Once you have finished editing the file restart Nginx with:

$ sudo service nginx restart
$ sudo service nginx status

14. Now let’s test if PHP is working as intended. Create an info.php file like this:

$ sudo vi /usr/share/nginx/html/info.php

Press “i” and insert the following code:

<?php phpinfo() ?>

Now press “Esc” and then “:wq” so the file is saved. Now open your browser and navigate to:

http://your-ip-address/info.php

You should see a PHP info page like this:

Check PHP and PHP-FPM Info

Congratulations! Your LEMP setup on Ubuntu 15.10 is now complete!

Conclusion

Your LEMP setup is now complete and you can start building your web applications or simply play with the Nginx and MariaDB services you just installed. These are widely used and gaining more knowledge in them is highly recommended for system administrators.

I am a bachelor in computer science and a Linux Foundation Certified System Administrator. Currently working as a Senior Technical support in the hosting industry. In my free time I like testing new software and inline skating.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.