Home » How to configure nginx virtual host with phpMyAdmin, MariaDB and php-fpm

How to configure nginx virtual host with phpMyAdmin, MariaDB and php-fpm

This is part 2 How to install a web server on CentOS 7 using nginx, php-fpm, MariaDB, and firewalld. In this guide I’ll show you how to configure nginx virtual host with phpMyAdmin, MariaDB and php-fpm to run several sites in a lien and organized fashion 🙂

First, let’s start by making a folder structure. I prefer to have all my sites in /www because it makes the most sense to me:

Now let’s a make the folders for our first site:

Now that we have the folders all setup for our first site, let’s make an index file inside /www/yoursite.com/public/index.php and put in a phpinfo() call so we can test php:

Now it’s time to setup nginx! Let’s start by adding a virtual host file for our new site. Place the following into /etc/nginx/conf.d/yoursite.conf

If you don’t prefer to use phpMyAdmin, delete lines 7-9 in the configuration above and skip the phpMyAdmin steps below. Otherwise, let’s install phpMyAdmin:

Real quick… if the above doesn’t work (their server was down for me a couple of times), then just Google “Enable EPEL repo on CentOS 7” and you’ll find articles like this that will help you install the EPEL repo so you can continue.

Now let’s setup a config file for phpmyadmin so we can easily include it in our virtual host files (like we did above on lines 7-9 of yoursite.conf). Place the following inside /etc/nginx/phpmyadmin.conf

I’d suggest renaming the /phpmyadmin/ alias to something else for added security from brute force attacks, but I’m just keeping it as /phpmyadmin/ for the sake of this tutorial.

Note: if you’re going to change this, you only need to change /phpmyadmin/ to something like /sqladmin/ on the lines that have “location” in front, NOT the /usr/share/phpMyAdmin directory.

Now we need to change the owner and permissions of our new PHP session directory so PHP can write to it.

Now let’s test our configuration:

You should hopefully see a nice successful output from nginx like so:

If your test is successful, you can reload the nginx configs:

Now you should be able to access http://yoursite.com/phpmyadmin/. It requires the trailing forward slash and has to be accessed via the virtual host, so you’ll want to either hack your hosts file to point yoursite.com to your ip address or point your DNS to your server.

If you notice an error about a missing mbstring extension like this:
Missing mbstring extension errorThen all you have to do is install and restart php-fpm:

The next thing I’d recommend is setting up APC and batcache for your site and make it run like the wind! Check out my other post for instructions:

Add batcache to your WordPress site (nginx + APC + php-fpm + batcache)

15 comments on “How to configure nginx virtual host with phpMyAdmin, MariaDB and php-fpm

  1. Andro Qholix on

    It’s fantastic web with usefull content.
    I used all of your tutorial, but i have problem with phpmyadmin cannot access 404 (not found).

    Hope you can tell me how to fix it ..

    Thank You.

    • Jeff Hays on

      Hi Andro,

      Are you sure that you’re adding the trailing forward slash at the end of your alias? In my example you should access your URL like http://yoursite.com/phpmyadmin/ after you have reloaded the nginx config and/or restarted php-fpm.

      These issues can be tricky to troubleshoot without seeing the URL being used or the logs. Try to check both of these to make sure things look correct.

    • Jeff Hays on

      Hey Mak,

      This could be caused from a series of things. Check your php-fpm logs and your nginx error logs to get details on the error. If you can’t even get the login page to load then it’s probably an issue with the nginx config itself, case sensitivity of the URL, or you might just need to restart php-fpm. Post back with your error logs if you continue to have issues.

      • Mak Adang on

        Hi Jeff,

        Thank you for you answer, i check my php-fm log there is no error.
        But i have error in nginx log as below,
        “[error] 465#0: *22029 FastCGI sent in stderr: “PHP message: PHP Fatal error: Call to undefined function __() in /usr/share/phpMyAdmin/libraries/core.lib.php on line 235” while reading response header from upstream, client: 192.99.xx.xxx, server: domain.me, request: “GET /phpmyadmin/ HTTP/1.1”, upstream: “fastcgi://unix:/var/run/php-fpm/www.sock:”, host: domain.me”
        i also check line 235 in core.lib.php is “include_once GETTEXT_INC;”


  2. Stephen on

    I followed the tutorial I believe exactly and got the error: PHP message: PHP Fatal error: Call to undefined function __() in /usr/share/phpMyAdmin/libraries/core.lib.php on line 245

    After a bit of researched I read that it may be because the session folder is not writable by the web service.. I noticed that you had us create the ‘/var/run/session’ direction but in my default php settings the session folder is set to ‘/var/lib/php/session’ Did I miss something?

    • Jeff Hays on

      Hey Stephen,

      You can set the session folder to be anywhere you want really, and I believe I ended up chmod’ing to 777 to initially get this to work. I am sure there’s an owner that can be set here that would be the same owner as the user that runs the php-fpm process, and then you could set g+w on the /var/run/session directory instead, but that’s how I got it initially working.

      Alternatively you could just leave the session path to the default of /var/lib/php/session

  3. danfalos on

    Error message from phpMyAdmin ::
    FastCGI sent in stderr: “PHP message: PHP Fatal error: Call to undefined function __() in /usr/share/phpMyAdmin/libraries/core.lib.php on line 245” while reading response header from upstream, client:

    Solution that worked on my Fedora 22 server x86_64 using nginx :
    changing the owner and the group identifier from root:apache on the file /var/lib/php/session
    to root:nginx
    using the command sudo chown -Rfv root:nginx /var/lib/php/session

    • Jeff Hays on

      That works until your next update – because for some reason the ownership changes back to having apache as the group when you update. That’s why I applied 777 in this tutorial. I’m on the fence with writing this in with a note to do this every time you update.

        • Jeff Hays on

          You just need to specify your domains with the server_name declaration:

          server_name .yoursite.com; this is any subdomain of yoursite.com, i.e. http://www.yoursite.com, http://ftp.yoursite.com, random.yoursite.com, etc.
          server_name .yoursite.com .anothersite.net; this is any subdomain of yoursite.com or anothersite.net
          server_name mysite.net www.coolsite.com; this is mysite.net (NOT including www.mysite.net) and www.coolsite.com (HAS to have the www. subdomain)

Leave a Reply

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