Home » How to install a web server on CentOS 7 using nginx, php-fpm, MariaDB, and firewalld

How to install a web server on CentOS 7 using nginx, php-fpm, MariaDB, and firewalld

This is a simple step-by-step tutorial about how to install nginx, php-fpm, MariaDB, and firewalld on CentOS 7 for an awesome web server. This tutorial expects you to be logged in as root so add sudo in front of these commands as needed. I personally hate reading long-winded intros to a tutorial so allow me to shut up and get to the good stuff…

First we need to enable the nginx repo for CentOS 7:

First let’s install nginx, php-fpm, mariadb, and firewalld in one fell swoop:

Now let’s start nginx:

Now you can test to see if nginx is up and running by visiting your server’s ip in your browser. You should see the default nginx page. If you don’t see the default nginx page, it’s possible that your specific distro of CentOS 7 already comes with firewalld installed. If this is the case, skip the next step.

Now let’s start the firewall daemon and open up port 80 permanently:

Now just be sure to reload your server’s ip in your web browser. You should still see your default nginx page. If everything is in order, let’s move on to MariaDB!

If you’re not familiar with MariaDB, it’s a drop-in replacement for MySQL and anything that runs on MySQL will run on MariaDB. It has some enhancements and things run better overall. Don’t be afraid of MariaDB! For people that are used to MySQL, you won’t notice hardly any differences outside of the name of the service you use to start/stop/restart the SQL server. For more information read up on MariaDB here.

Let’s start by starting the service:


Before we do anything else, let’s secure our MariaDB installation:

Note: if you don’t know about correct horse battery staple passwords, check them out.

Next step is to configure php-fpm to run through the local unix:// socket. This is faster than running things through port 9000 (the default) as it doesn’t take any network overhead to pass php files to php-fpm.

Look for the line that says “listen” towards the top and change it to this:

Then we’ll change the user and group that PHP will run as from apache to nginx. Find the lines that say user and group and change to the following:

Before we start php-fpm, let’s create the www.sock file and change the owner to nginx and assign the appropriate permissions:

Now we can start php-fpm…

Okay, now that we have MariaDB, nginx, and php-fpm all setup and ready to go, we can now setup all of these services to start on boot:

That’s it! You now have a functional web server running on CentOS 7! Check out my How to configure a nginx virtual host and phpMyAdmin with php-fpm guide to get your virtual hosts configured.

4 comments on “How to install a web server on CentOS 7 using nginx, php-fpm, MariaDB, and firewalld

    • Jeff Hays on

      Awesome! It sounds like everything was setup correctly then. Feel free to follow the link I added to the bottom of this tutorial to setup a virtual host so you can route inbound domains to a directory on your server and give it some different content to serve for your site. Let me know if you have any questions.


Leave a Reply

Your email address will not be published. Required fields are marked *