Install LEMP Stack on CentOS 7 (Red Hat 7)

• How-To   • Linux

A very quick how-to guide on installing NGINX, MySQL and PHP, otherwise known as a LEMP stack on CentOS 7 (and usable on Red Hat 7 as well). Image from Digital Ocean link.

1. Install MySQL (mariadb)

1
2
3
$ yum install mariadb mariadb-server
$ mariadb restart
$ sudo /usr/bin/mysql_secure_installation

2. Add the NGINX repository Create the file named /etc/yum.repos.d/nginx.repo with the following contents:

1
2
3
4
5
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/mainline/centos/7/$basearch/
gpgcheck=0
enabled=1

3. Install NGINX

1
2
3
$ yum install nginx
$ service nginx start
$ service nginx status

4. Allow NGINX through the firewall

1
2
3
$ firewall-cmd --set-default-zone=home
$ firewall-cmd --permanent --zone=home --add-service=http
$ firewall-cmd --reload

5. Install PHP

1
$ sudo yum install php-fpm php-mysql

6. Autostart MySQL, NGINX and PHP on boot

1
$ sudo chkconfig --levels 235 mariadb on sudo chkconfig --levels 235 nginx on sudo chkconfig --levels 235 php-fpm on

And we are finished! Start configuring your new LEMP stack on CentOS nginx-success