Need help? Chat now!
Search results for:
Table of Contents
Tags CentOS Web Panel
LEMP stands for Linux, Nginx (replacing the Apache server), MySQL (which acts as the database storage), and its dynamic content is adapted by PHP. LEMP stack is a convenient way to bundle open-source software. LEMP enables a server to host web apps, ever-evolving websites and centers around the Linux operating system.
Note: The main focus of the article is Hostwinds clients who have a Cloud or VPS server with the goal of helping you install the LEMP stack on the CentOS 7 Operating System.
Before You Get Started: To follow along with this tutorial, you will need to have root access. If a non-root user account is installed on your server, make sure that it has sudo privileges to utilize the sudo and yum commands in the following article. As with all changes, we highly recommend taking a snapshot backup before proceeding with this guide.
For site visitors to use what you wish to display, you'll need a capable, up-to-date web server. For the sake of this article, we're going to use Nginx. This is the E in LEMP due to its pronunciation (engine – x)
* To add the CentOS 7 EPEL archive, open your terminal and type in the following yum command:
sudo yum install epel-release
When prompted, press y and hit enter to start the installation. This will install the required archive so that Nginx can be installed. When this has been completed, a message stating Complete! will appear.
Once the Nginx archive is installed on your server, you'll want actually to install Nginx using the following command:
sudo yum install nginx
Your web server is now installed. You can start the Nginx service by entering the command:
sudo systemctl start nginx
With a sudo command in use, all these operations will now execute with root privileges. To verify that you have permission to run commands with these root privileges, you must enter your regular user's password.
At this point, make sure to check the server's public IP address in your web browser. You should see the default CentOS 7 Nginx web page as confirmation that Nginx is installed and running. You should be greeted with a message similar to the following:
Before moving on, you'll want to enable Nginx to start on bootup. That way, you do not have to retype the above command each time the server starts. You can do so by entering the following command:
sudo systemctl enable nginx
Next, we're going to install a MySQL drop-in alternative called MariaDB. MariaDB is a community-developed branch of MySQL database management that organizes and allows access to the databases storing your website's information. Syntactically, MySQL and MariaDB are very similar, and there aren't significant differences. This is the M in LEMP.
Since we've already employed yum, we'll use it again to grab and install the necessary software.
MySQL / MariaDB is not required to run all web applications, though it is a popular choice. To install MariaDB, you'll want to enter this command:
sudo yum install mariadb-server mariadb
When finished, start MariaDB by entering:
sudo systemctl start mariadb
Next, you'll want to employ a security script to remove some of the potentially harmful defaults and anchor your database:
Note: Don't worry if the prompt asks you for your current root password. At this stage, you won't have one yet, so leave it blank by hitting enter.
When prompted to set a root password, type "Y" and follow the instructions to set up your root password, make sure to make a note of it for future use.
Hitting "Enter" for the next series of prompts will accept the default values. This allows MySQL to immediately acknowledge changes you've made by removing sample users and databases. Additionally, disabling remote root logins and then reloading the privilege table.
To allow MariaDB to start on bootup, use this command:
sudo systemctl enable mariadb
Feel free to pat yourself on the back; you just set up your whole database system!
To process your web pages that are written in PHP, you will want to install PHP to your web server and also make sure it starts up if your system reboots using the following commands:
To install PHP, type this command:
sudo yum install php php-common php-fpm php-mysql -y
To initially start the PHP service to run, enter the following command:
sudo systemctl start php-fpm
For enabling the PHP service to start automatically, so you don't have to type the command above every time the server restarts, use this command here:
sudo systemctl enable php-fpm
It is important to configure PHP properly once it is installed.
You should have the following in php.ini :
"cgi.fix_pathinfo = 0;"
You can accomplish this by editing your php.ini file in /etc/php.ini and saving this file. Here are the commands to accomplish this using the vim text editor:
sudo vi /etc/php.ini
Find the line;cgi.fix_pathinfo=1 and change this to remove the comment and change the value to 0, like so:
You can also use the nano text editor if that is easier.
Once this is done, make sure to save your changes to /etc/php.ini
To allow PHP and the webserver to see the new changes, both services will need to be restarted. To restart PHP, type the following command:
sudo systemctl restart php-fpm
To restart the Nginx service, type the following command:
sudo systemctl restart nginx
You can confirm that this is set properly by creating a php.info page and viewing this page in your browser. The phpinfo.php page should contain the following and be removed once you have confirmed this setting is active:
Make sure that you place the file into your /usr/share/nginx/HTML directory, as this is where your web server will grab files from.
Congratulations! If you have followed the above steps successfully, you should now have the LEMP stack installed on your server. You can now upload your site's files to the /usr/share/nginx/HTML directory or another directory if you update the Nginx config (located at /etc/nginx/nginx.conf).
If you should have any questions or would like assistance, please contact us through Live Chat or submit a ticket with our Technical Support team.
Written by Peter H / November 28, 2016