Home » Install nginx, php-fpm, APC, MariaDB, and phpMyAdmin on CentOS 6

Install nginx, php-fpm, APC, MariaDB, and phpMyAdmin on CentOS 6

This is a complete guide on how to install nginx, php-fpm, APC, MariaDB, and phpMyAdmin on CentOS 6. If you are looking for a similar guide on how to do this on CentOS 7, then this article is the one you’re looking for instead.

First you need to make sure you have the EPEL repo installed. If you don’t, simply Google “Install EPEL CentOS” and you’ll find what you need to proceed. If you need to check if you have EPEL installed then just type this:

If you see any output from the command above, then you already have EPEL installed and you’re ready to move on.

Now let’s install nginx and php-fpm:

Usually at this point I like to start the nginx service and accept ports 80 and 443 in iptables so we can access our server to ensure nginx is running and delivering pages properly:


Now lets add port 80 to iptables so people can connect to your webserver on port 80:

(optional): You can also add port 443 if you want to accept SSL via https:// protocol:

Now let’s flush the iptables rules:

And at this point, you should be able to browse to the ip address of your server with something like where is your server’s ip address. If everything is in order, let’s install 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. For more information read up on MariaDB here.


To get started, we’ll install the remi repo:

Now we’ll add a repo for MariaDB:

Paste the following into that file:

Then upgrade (to make sure any previous MySQL stuff gets overwritten), install MariaDB, and start the service:

Note: if you get a huge list of compatibility errors when you run yum upgrade during the transaction test, just do “yum remove mysql” and try the commands above.

At this point I’d suggest securing MySQL:

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:

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

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 phpMyAdmin and nginx vhosts.


Now let’s configure phpMyAdmin:


Change your blowfish_secret to a random secure string and save the file. Now let’s setup an alias for /sqladmin/ on any of your sites to go to phpMyAdmin:

Paste the following into that file:

And finally, it’s time to setup a vhost in nginx for your site. I’m going to use the vhost that I’ve used for this site. You can change any instance of “robido” and “robido.com” to your site’s URL for the following steps:

Paste the following into that file (replacing robido.com as needed). Note: lines 19-24 are specifically for this WordPress site on a subdirectory install of https://robido.com and adding the rewrites for WordPress SEO sitemap.xml files. These lines can be excluded if they don’t apply to your install.

You’ll notice there’s a note in that config that suggest to modify your php.ini file to change your cgi.fix_pathinfo to 0. Edit your /etc/php.ini file and search for “fix_pathinfo” then set it to 0:

Now that we have a vhost setup, we can create directories for our site, add a user for SFTP/FTP/SSH and restart nginx:

Once you’ve set your password we can reload nginx to pull in the new configs. Note: it’s always good to use “nginx -t” to check to see that your configs don’t have any problems before restarting:

And if you want nginx, php-fpm, and mysql to start on boot:

That’s it folks! You should now be able to create an index.html, index.htm, or index.php file (in /www/robido.com/public/index.php for example) and the contents of that file will be displayed when you point your domain (robido.com in this case) to your server and access https://robido.com. You can also browse to phpMyAdmin with a URL like https://robido.com/sqladmin/ (the trailing / is necessary here with our current config).

If any of the steps above throw errors for you, or you have questions or issues, feel free to post a comment and I’ll help debug. The only issue that I had during my setup process was some conflicts of php-mcrypt, php-mbstring, and the other libraries that phpMyAdmin needed (which were a different version than my install from the remi repository). I added in –enablerepo remi into the phpMyAdmin install step to hopefully prevent anyone else from having the same issue.

If you want to make your WordPress site SCREAMING fast with this setup, check out my other post about installing batcache:  Add batcache to your WordPress site (nginx + APC + php-fpm + batcache). Any comments, questions, or concerns are encouraged!

6 comments on “Install nginx, php-fpm, APC, MariaDB, and phpMyAdmin on CentOS 6

    • Jeff Hays on

      Hey Kingsley,

      So long as the nginx -t is ran shy of reloading the config with nginx -s reload it’s fine either way since nginx will bark at you if a directory you need doesn’t exist. Feel free to create directories first if that suits you. Thanks for the feedback 🙂


Leave a Reply

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