Verified and Tested 05/29/15
Introduction
This how-to will help you with your LEMP installation in Arch Linux so that you can successfully run a high available solid platform for your web environment. LEMP is simply a software bundle that consists of 4 components that work together to form a powerful web server. Linux (L) is the platform’s core, which will sustain the other components. Nginx (E) is used for the web service. MySQL (M) is used for database management, and PHP (P) is used as the file programming language.
Getting Started
To get started, log in to your Arch Linux server via SSH or through the VNC Console here. Atlantic.Net Cloud servers are set up as minimal installations to avoid having unnecessary packages from being installed and never used. If some software packages that you’re used to using aren’t installed by default, feel free to install them as needed.
Let’s start to make sure that your server is fully up-to-date.
sudo pacman -Syu
We can continue the process and install LEMP on your server with the server up-to-date.
Install Nginx On Arch Linux
We must first begin by installing Apache with the following command:
sudo pacman -S nginx
Start the Nginx service with the following command:
sudo systemctl start nginx.service
To edit the main Nginx configuration file for one or many websites according to your preference, they are configured in the following directory:
sudo nano /etc/nginx/nginx.conf
You can now verify that Apache is installed correctly by typing http:// and your IP address on your browser.
http:// YOUR.IP.ADD.RESS (To get your servers IP Address, type the following command:)
curl -s icanhazip.com
Restart the Nginx service so the changes can take effect on your system.
sudo systemctl restart nginx.service
Install MySQL On Arch Linux
We then would like to continue by installing MySQL. However, in Arch Linux, MySql is replaced with MariaDB. So, after running the following MySql command, hit enter to select one, then Enter, then confirm your installation by tapping Enter.
sudo pacman -S mysql
After the install, you must run the following command to complete the installation fully.
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
Make sure that the MySql/MariaDB service is on with the following command before proceeding:
sudo systemctl start
mysqld.service
To ensure the security of the default settings of MySQL/MariaDB, continue with the command below:
sudo mysql_secure_installation
Note: When prompted with “Enter current password for root,” hit enter for none then Y(Yes) to set the MYSQL password. You will then be prompted with a series of questions. Type Y for yes on all of them. See the screenshot below:
Install PHP On Arch Linux
Finally, we will conclude the LEMP Stack by installing PHP with the following command:
sudo pacman -S php-fpm
Make sure that PHP has started with the following command:
sudo systemctl start
php-fpm.service
We must change the PHP configuration file to activate the specified LEMP module. enabled:
sudo nano /etc/php/php.ini
Using the Ctrl+w in your text editor(nano), locate the following line and remove the semicolon to activate
;extension=mysqli.so
Now we can configure the Nginx configuration file so that it can recognize PHP files.
sudo nano /etc/nginx/nginx.conf
The following instructions are crucial and must be completed so PHP and Nginx work correctly. Locate the following line #location ~ \.php$ { using Ctrl+w, tap enter to create a space in between the # and paste the following code in between:
location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; root /srv/http; include fastcgi.conf; }
Fantastic! You can now save the file and restart Nginx and PHP so all your configuration takes effect.
sudo systemctl restart nginx.service
To verify and test the installation, create a test PHP file in the following directory with the command below:
sudo nano /srv/http/info.php
Insert the following PHP code in the empty file, then save and exit:
<?php phpinfo(); ?>
Restart the Apache HTTP service one last time, so all the changes will be affected.
sudo systemctl restart httpd.service
You can now verify that PHP is installed correctly by typing the following on your browser.
http:// YOUR.IP.ADD.RESS/info.php
What Next?
Congratulations! You now have a server with a LEMP Stack platform for your web environment. Thank you for following along, and feel free to check back with us for further updates.
Learn more about our VPS hosting services and VPS hosting price.