{"id":4109,"date":"2014-07-29T12:56:53","date_gmt":"2014-07-29T17:56:53","guid":{"rendered":"https:\/\/secure.rosehosting.com\/blog\/?p=4109"},"modified":"2022-06-03T03:46:49","modified_gmt":"2022-06-03T08:46:49","slug":"how-to-install-lemp-linux-nginx-mariadb-php-fpm-on-a-centos-7-vps","status":"publish","type":"post","link":"https:\/\/www.rosehosting.com\/blog\/how-to-install-lemp-linux-nginx-mariadb-php-fpm-on-a-centos-7-vps\/","title":{"rendered":"How to install LEMP (Linux, Nginx, MariaDB & PHP-FPM) on a CentOS 7 VPS"},"content":{"rendered":"
The following article will walk you through the steps on how to install LEMP (Linux, Nginx, MariaDB & PHP-FPM)<\/strong> on one of our CentOS 7<\/strong> Linux Virtual Servers<\/strong><\/a>.<\/p>\n If instead, you are looking for how to set-up LAMP<\/strong>, then please refer to our guide on how to install LAMP (Linux Apache, MariaDB & PHP)<\/a> on a CentOS 7 VPS<\/a><\/strong><\/p>\n What is LEMP?<\/strong><\/p>\n A LEMP<\/strong> stack is a synonym of LEMP<\/strong> server or LEMP<\/strong> web server. It refers to a set-up which includes Linux<\/b>, Nginx<\/strong>, MariaDB (MySQL)<\/strong> and PHP<\/strong>.<\/p>\n <\/p>\n As usual, MariaDB<\/strong> is a drop-in replacement for MySQL<\/strong> and is the default database server used in CentOS 7 (RHEL7)<\/strong>. Proceed with installing it using Next, open This will bind MariaDB to listen on localhost only<\/strong>, which is considered to be a good security practice. OK, now restart the MariaDB database server and enable it to start on system start-up using:<\/p>\n Optionally, you can run the For example:<\/p>\n Once it’s installed, run the following command to find out the number of CPUs available in your SSD VPS:<\/p>\n This number should represent the number of Stop Apache if it\u2019s running on the system using the following command:<\/p>\n and test, start and add Nginx to system\u2019s start-up using:<\/p>\n Navigate to http:\/\/server_ip<\/span> and you should get something like:<\/p>\n <\/p>\n This means that your have Nginx up and running just fine.<\/p>\n We are going to run PHP as FastCGI using PHP-FPM<\/strong>, so install PHP support using also, you may want to install some other PHP extensions<\/strong> required by your applications. Here is the list:<\/p>\n Edit PHP main configuration file in Also, edit set-up log directory ownership:<\/p>\n start and add the PHP server to the system\u2019s start-up using Let’s say you have a domain test and re-start Nginx using:<\/p>\n Optionally, create a test and try to access it in your browser at http:\/\/mydomain.com\/info.php<\/span><\/p>\n Of course you don\u2019t have to do any of this if you use one of our Linux VPS Hosting<\/a> services, in which case you can simply ask our expert Linux admins to install LEMP for you<\/strong>. They are available 24×7 and will take care of your request immediately. You can also try reading our guide on How to install LEMP (Linux, Nginx, MySQL & PHP-FPM) on a Debian 8 VPS<\/a>.<\/p>\n PS<\/span>.<\/strong> If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.<\/p>\n","protected":false},"excerpt":{"rendered":" The following article will walk you through the steps on how to install LEMP (Linux, Nginx, MariaDB & PHP-FPM) on … <\/p>\nUPDATE THE SYSTEM<\/b><\/h3>\n
SSH<\/code> to your Linux VPS<\/a>, initiate a
screen<\/code> session and make sure your CentOS 7<\/strong> is fully up-to-date by running the following commands:<\/p>\n
## screen -U -S lemp-centos7\n## yum update<\/pre>\n
INSTALL MARIA DB (MYSQL)<\/b><\/h3>\n
yum<\/code> as in:<\/p>\n
## yum install mariadb mariadb-server mysql<\/pre>\n
\/etc\/my.cnf.d\/server.cnf<\/code> using your favorite text editor and add
bind-address = 127.0.0.1<\/code> within the
[mysqld]<\/code> block. For example:<\/p>\n
## vim \/etc\/my.cnf.d\/server.cnf\n\n[mysqld]\n#log-bin=mysql-bin\n#binlog_format=mixed\nbind-address = 127.0.0.1<\/pre>\n
## systemctl restart mariadb\n## systemctl status mariadb\n## systemctl enable mariadb<\/pre>\n
mysql_secure_installation<\/code> post-installation script to improve MariaDB (MySQL) installation security<\/strong>. For example:<\/p>\n
## mysql_secure_installation\n\nEnter current password for root (enter for none): ENTER\nSet root password? [Y\/n] Y\nRemove anonymous users? [Y\/n] Y\nDisallow root login remotely? [Y\/n] Y\nRemove test database and access to it? [Y\/n] Y\nReload privilege tables now? [Y\/n] Y<\/pre>\n
INSTALL NGINX HTTP SERVER<\/b><\/h3>\n
Nginx<\/code> is not yet available in CentOS 7<\/strong> official repositories at the time of writing this article. So, to be easily installed and managed using
yum<\/code>, we can use the repository for the latest stable version of Nginx for CentOS 7<\/a>.<\/p>\n
## rpm -Uvh http:\/\/nginx.org\/packages\/centos\/7\/noarch\/RPMS\/nginx-release-centos-7-0.el7.ngx.noarch.rpm\n## yum install nginx<\/pre>\n
## grep -c processor \/proc\/cpuinfo\n2<\/pre>\n
nginx<\/code> processes set in Nginx main configuration file in
\/etc\/nginx\/nginx.conf<\/code>.<\/p>\n
## vim \/etc\/nginx\/nginx.conf\n...\nworker_processes 2;\n<\/pre>\n
## [[ $(pgrep httpd) ]] && ( systemctl stop httpd; systemctl disable httpd )<\/pre>\n
## nginx -t\n## systemctl restart nginx\n## systemctl enable nginx<\/pre>\n
INSTALL PHP-FPM<\/b><\/h3>\n
yum<\/code>:<\/p>\n
## yum install php-fpm php-mysql<\/pre>\n
php-bcmath : A module for PHP applications for using the bcmath library\nphp-cli : Command-line interface for PHP\nphp-common : Common files for PHP\nphp-dba : A database abstraction layer module for PHP applications\nphp-devel : Files needed for building PHP extensions\nphp-embedded : PHP library for embedding in applications\nphp-enchant : Enchant spelling extension for PHP applications\nphp-fpm : PHP FastCGI Process Manager\nphp-gd : A module for PHP applications for using the gd graphics library\nphp-intl : Internationalization extension for PHP applications\nphp-ldap : A module for PHP applications that use LDAP\nphp-mbstring : A module for PHP applications which need multi-byte string handling\nphp-mysql : A module for PHP applications that use MySQL databases\nphp-mysqlnd : A module for PHP applications that use MySQL databases\nphp-odbc : A module for PHP applications that use ODBC databases\nphp-pdo : A database access abstraction module for PHP applications\nphp-pear.noarch : PHP Extension and Application Repository framework\nphp-pecl-memcache : Extension to work with the Memcached caching daemon\nphp-pgsql : A PostgreSQL database module for PHP\nphp-process : Modules for PHP script using system process interfaces\nphp-pspell : A module for PHP applications for using pspell interfaces\nphp-recode : A module for PHP applications for using the recode library\nphp-snmp : A module for PHP applications that query SNMP-managed devices\nphp-soap : A module for PHP applications that use the SOAP protocol\nphp-xml : A module for PHP applications which use XML\nphp-xmlrpc : A module for PHP applications which use the XML-RPC protocol<\/pre>\n
\/etc\/php.ini<\/code> and set the following:<\/p>\n
## vim \/etc\/php.ini\n\ndate.timezone = America\/New_York\nmemory_limit = 64M\nexpose_php = Off<\/pre>\n
\/etc\/php-fpm.d\/www.conf<\/code> and change the user and group the fpm pool will be running under to
nginx<\/code>:<\/p>\n
## vim +\/^user \/etc\/php-fpm.d\/www.conf\n\nuser = nginx\ngroup = nginx<\/pre>\n
## chown nginx:root -R \/var\/log\/php-fpm\/<\/pre>\n
systemctl<\/code><\/p>\n
## systemctl restart php-fpm\n## systemctl enable php-fpm<\/pre>\n
SET-UP NGINX VHOST<\/b><\/h3>\n
mydomain.com<\/code> and you like to use it to host a PHP based web application in
\/srv\/www\/mydomain.com.com<\/code> like WordPress, Joomla, Laravel etc. To set-up Nginx serve requests for
mydomain.com<\/code>, and serve the PHP scripts in
\/srv\/www\/mydomain.com.com<\/code> you would have to create a server block in
\/etc\/nginx\/conf.d\/mydomain.com.conf<\/code> which would look something like:<\/p>\n
## vim \/etc\/nginx\/conf.d\/mydomain.com.conf\n\nserver {\n server_name mydomain.com;\n listen 80;\n root \/srv\/www\/mydomain.com;\n access_log \/var\/log\/nginx\/mydomain.com-access.log;\n error_log \/var\/log\/nginx\/mydomain.com-error.log;\n index index.php;\n\n location \/ {\n try_files $uri $uri\/ \/index.php?$args;\n }\n\n location ~* \\.(jpg|jpeg|gif|css|png|js|ico|html)$ {\n access_log off;\n expires max;\n }\n location ~ \/\\.ht {\n deny all;\n }\n location ~ \\.php {\n try_files $uri = 404;\n fastcgi_pass 127.0.0.1:9000;\n fastcgi_index index.php;\n include \/etc\/nginx\/fastcgi_params;\n fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n }\n}<\/pre>\n
## nginx -t\n## systemctl restart nginx<\/pre>\n
info.php<\/code> script using the following command:<\/p>\n
## mkdir -p \/srv\/www\/mydomain.com\n## echo -e \"<?php\\n\\tphpinfo();\" > \/srv\/www\/mydomain.com\/info.php\n## chown nginx: -R \/srv\/www\/<\/pre>\n
\n