How to install Nginx, MySQL, PHP v7 (LEMP) stack on CentOS 7

Nginx is a growing open source web server software and PHP v7 is the latest version of the PHP engine. In this tutorial, we will use it to build a stack server LEMP (Linux, ANDNginx, MySQL, P). Nginx replaces the popular Apache package found on the LAMP stack.

what you will need

Before you begin this guide, you will need the following:

Step 1 – Install Nginx on CentOS 7

Since Nginx is not available in the CentOS repositories by default, we will install the repository EPEL running this command:

yum install epel-release -y

Next, we will install Nginx like so:

yum install nginx -y

Once the installation is complete, enable Nginx startup on boot and run it:

systemctl start nginx systemctl enable nginx

To check if Nginx is running, you can visit your IP address through the browser. First, identify your IP:

dig +short myip.opendns.com @resolver1.opendns.com

Then just copy and paste it into the browser and you will see a page similar to this:

Step 2 – Install MySQL (MariaDB)

Once the web server is installed, we can continue with the installation of MySQL. MariaDB is a community fork of the good old MySQL service. Since MariaDB comes with default CentOS repositories, we can run Yum to install it:

yum install mariadb-server mariadb -y

After finishing the installation, enable and start the service:

systemctl start mariadb systemctl enable mariadb

Lastly, run the initial setup script which will remove some of the default settings:

mysql_secure_installation

However, MariaDB will ask you for the root password, but since this is the initial installation, you don’t have one, so just press ENTER. The following message will ask if you want to set a root password, enter Y and follow the instructions:

See also  How to use XAMPP to setup a local WordPress site (in 3 steps)?

Enter current password for root (enter for none): OK, successfully used password, moving on… Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorization. New password: password Re-enter new password: password Password updated successfully! Reloading privilege tables.. … Success!

You can safely press the key ENTER and accept the default settings for all other questions. After completing the setup, continue with the PHP installation.

Step 3 – Install PHP v7.1.0

The first thing we will do is install the additional CentOS repository that contains the necessary packages for PHP v7.1:

wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm rpm -Uvh remi-release-7.rpm

Enable the php71 repository which is disabled by default:

yum install yum-utils -y yum-config-manager –enable remi-php71

Second, install the PHP package:

yum –enablerepo=remi,remi-php71 install php-fpm php-common

Install the common modules, such as , , among others:

yum –enablerepo=remi,remi-php71 install php-opcache php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-redis php-pecl-memcache php -pecl-memcached php-gd php-mbstring php-mcrypt php-xml

Step 4 – Configure Nginx to work with PHP 7

Create a new Nginx configuration file by running vim or the text editor:

nano /etc/nginx/conf.d/default.conf

Enter this code:

server { listen 80; server_name your_server_ip; # note that these lines are originally from the “location /” block root /usr/share/nginx/html; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } location ~ \.php$ { try_files $uri =404; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }

IMPORTANT! Replace your_server_ip with the actual IP of your server

Save the file by pressing CTRL + X (CMD + X for Mac users). Restart Nginx for the change to take effect:

See also  Marketing Archives

systemctl restart nginx

Now open the settings PHP-FPM:

nano /etc/php-fpm.d/www.conf

Find and replace these lines:

user = apache by user = nginx

group = apache per group = nginx

listen.owner = nobody by listen.owner = nginx

listen.group = nobody by listen.group = nginx

And finally, under ;listen = 127.0.0.1:9000 add this line:

listen = /var/run/php-fpm/php-fpm.sock

Once again, save the file by pressing CTRL + X. And finally, start php-fpm and enable it on startup:

systemctl start php-fpm.service systemctl enable php-fpm.service

conclusion

Installing the LEMP stack may require more configuration than the well-known LAMP setup, but you can be sure that you will be using the latest technology from both worlds: a fast PHP-FPM v7 processor package with Nginx modern web service. That’s all for now, feel free to check other VPS tutorials on our page.

Gustavo is passionate about creating websites. He focuses on the application of SEO strategies at for Spain and Latin America, as well as the creation of high-level content. When he is not applying new WordPress tricks you can find him playing the guitar, traveling or taking an online course.

Loading Facebook Comments ...
Loading Disqus Comments ...