trying to get phpMyAdmin on nginx to work

Original Post:

ctrlbrk

Free Member
May 13, 2021
995
399
I have a test website on a localhost machine. Apache has been the web server of choice but I decided to try nginx.

Because of my poor understanding of nginx configuration, while I am able to serve static pages, I am having a hard time trying to get phpMyAdmin to work.

I keep getting 404 - not found type error when trying to access it. Googling the issue seems to suggest it's a common problem, tried a few things they suggested but still no luck.



anyone come across this?

Thanks
 
Solution
@ctrlbrk that explains it. You installed it from the nginx repo so you did not get the debian specific configuration which is only in Debian's own repos.

I think the usual Debian instructions will now work for you.

I think it is better to install from the distro's own repos unless you really need to do otherwise (e.g., you need a feature that is only in the latest version).

ctrlbrk

Free Member
May 13, 2021
995
399
How far have you got?
The documentation I have googled makes references to certain folders at times and other folders at other times, i.e. in some instances the documentation references sites-available and sites-enabled (which are used in Apache), but these were not created by default during the nginx installation process. Some documentation also suggests that phpmyadmin should be in a subfolder of my main site, which I struggle to understand, given on Apache you don't need any of that.
Have you got other things working? Is phpMyAdmin the only php application you cannot run?
I was able to run a static site - that's about the only success I have had with ngninx.
How are you configuring php? If you are running it with fastcgi have you run it and checked it is working? No idea. With Apache I just installed what the documentation told me to and everything worked. I understand that with nginx I can use two different php modules to run dynamic sites but I haven't got that far yet.
Thanks gpietersz for taking the time to reply. My answers above in bold.
 
Upvote 0

gpietersz

Free Member
  • Business Listing
    Sep 10, 2019
    2,721
    2
    713
    Northwhich, Cheshire
    pietersz.net
    What OS (and distro) are you on. sites-available and sites-enabled are (only AFAIK) used with nginx on Debian based distros (e.g. Ubuntu).

    You can put everything in nginx.conf or include files individually, import from your own folder. Debian just added an include for everything in sites-enabled in their default nginx.conf.

    I suggest you first get a simple page with a single line of php working.

    I am not sure what you mean by not in a subfolder on Apache. php files are usually inside the document root, so unless they are at the toplevel of the site they are usually in a subfolder.

    I am currently moving some Wordpress sites from one server using Apache to another using nginx. I copied the files over, and configured nginx. You might find this helpful: https://www.nginx.com/resources/wiki/start/topics/examples/phpfcgi/

    Why are you installing locally? Is it on your development machine directly or on a VPS?
     
    • Like
    Reactions: ctrlbrk
    Upvote 1
    U

    UkAppCoder

    I installed NGINX on a local CentOS 7 machine about four years ago so that I could work on a project for someone who was using a Ubuntu/NGINX setup. I didn't install PHPMyAdmin, but since it's just a PHP script, I imagine it should just work as any other.

    I remember everything being quite straightforward. I used the following instructions:


    If you've got your NGINX serving HTML files, then for your convenience, you might be able to use the following extracts from the article to enable PHP and configure NGINX (any directory paths might be different on your Linux):

    SvennD:

    Configure php-fpm

    After the installation its time to finetune our setup a bit. Let’s start with php-fpm, we need to modify /etc/php-fpm.d/www.conf

    Change both the user and the group to nginx.

    ; Start a new pool named 'www'.
    [www]
    ; Unix user/group of processes
    ; Note: The user is mandatory. If the group is not set, the default user$
    ; will be used.
    ; RPM: apache Choosed to be able to access some dir as httpd
    user = nginx
    ; RPM: Keep a group allowed to write in log dir.
    group = nginx
    [...]

    Note : it’s possible to let Nginx use a socket instead of loopback device. This is a bit faster, but I found that the headache is not really worth it.

    Configure Nginx

    Depending on the installation there is already a default server configuration. I tend to remove it and replace it with an empty file and create a file [name].conf in /etc/nginx/conf.d/

    http server

    [ I SIMPLIFIED THE SUGGESTED SERVER BLOCK TO THE FOLLOWING ]

    server {
    listen 80;
    server_name nginxsite.com;
    root /var/www/nginxsite.com;

    location / {
    index index.php index.html index.htm;
    try_files $uri $uri/ /index.php?$args;
    }

    location ~* \.php$ {
    include /etc/nginx/fastcgi_params;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    fastcgi_index index.php;
    }
    }

    Hope this helps. :)
     
    • Like
    Reactions: ctrlbrk
    Upvote 0
    So you've installed a basic command line version of Debian. I would abandon this and install something with a GUI. I doubt that even a professional sysadmin would use such a basic installation nowadays! :)

    If you do this, then it should be just a simple matter of logging into your system as root, browsing the file system to find the files you need, and editing them as required. You could do this as a user, but you would need to use the command line. Therefore, I recommend the root route. :)

    However, I get the feeling that you haven't installed PHP yet. Therefore, my answer below takes this into account. To check that PHP is installed, use the following command:

    $ php -v

    You should get some output like:

    PHP 7.2.24 (cli) (built: Oct 22 2019 08:28:36) ( NTS )
    Copyright (c) 1997-2018 The PHP Group
    Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

    If you insist on using Debian, then you can explore the directory structure at:


    (I've always used CentOS because that's what most professional sysadmins seemed to prefer at the time I started out. Also, for support purposes, I wanted the most popular, but I realise that many people have their own reasons for their own preferences.)

    It would appear that you need to modify the following files:

    For the NGINX configuration:

    /etc/nginx/nginx.conf

    To enable PHP:

    I am not a sysadmin, so I'm not sure about the PHP bit on Debian. If PHP is not installed, then you could look at the following which I've just lifted from the web (there's other stuff which should be useful too):


    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    6. Install PHP

    Install PHP-FPM 7.4 and other required packages.

    $ sudo apt-get install php php-fpm php-curl php-cli php-zip php-mysql php-xml -y

    Check the PHP version to verify the installation.

    $ php -v

    It should return something like this:

    PHP 7.4.28 (cli) (built: Feb 17 2022 16:17:19) ( NTS )
    Copyright (c) The PHP Group
    Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.28, Copyright (c), by Zend Technologies

    Create a PHP test file in your editor.

    $ sudo nano /var/www/html/phpinfo.php

    Paste this into your phpinfo.php file.

    <?php

    phpinfo();

    ?>

    Save and exit the file.
    In your browser, navigate to http://www.example.com/phpinfo.php to view the PHP test file, which shows the PHP information.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    Once you've done this, then it should be just a matter of modifying the file I mentioned in my previous post - look for it at the link I posted above - here it is again:


    I will soon be installing a CentOS 8 on a machine that I've had lying underneath my desk for the last few months. I'll be replicating the system I use now on my current machine. I use (and prefer) Apache, but I could also install NGINX while I'm at it. If you like, I can hold your hand through the process so that you end up with a complete professional Linux CentOS 8 setup with GUI trimmings including the Thunar file explorer. There's only one condition, you would need a quad-core processor because although Linux CentOS is awesome, it is no different from other systems in that it has its quirky flaws which includes crashing every now and then for some unknown reason when running on a dual-core. On a quad-core, there are no problems. I've been paying between £100 and £170 for refurbished Dell quad-cores on Amazon, and they are worth every penny. :)

    Offer stands for the next two weeks. Will be starting in the first half of October. No charge whatsoever. :)
     
    Upvote 0

    ctrlbrk

    Free Member
    May 13, 2021
    995
    399
    Thanks @UkAppCoder , I do appreciate your offer, however Debian, CLI etc. are all business decisions so they will stay, but I am grateful for your kind offer nevertheless.

    Over the next few days I will dedicate more time to troubleshooting nginx and why php (which is installed) is not working right now.
     
    Upvote 0
    No worries. Good luck with it. :)

    Just to make sure you know, but you do get to keep your CLI. A desktop GUI is just another software application to make things easier for people who are not professional administrators, but you still have full access to your CLI.

    You could of course install a GUI on your Debian. If you did this, then I think it would be safer to do it on a spare machine to make sure you don't lose what you have. The following site shows how to install the GNOME desktop on Debian:


    There are better GUIs than GNOME, but any of them would make things a hell of lot easier for you. :)
     
    Upvote 0

    gpietersz

    Free Member
  • Business Listing
    Sep 10, 2019
    2,721
    2
    713
    Northwhich, Cheshire
    pietersz.net
    If you installed from the repo I am puzzled by the sites-enabled/sites-available directories not being there. I just had a look at a Debian Buster VPS I set up, and they are there (and I did not create them!).

    The contents of /etc/nginx/ should look something like this:

    conf.d koi-utf modules-available proxy_params sites-enabled win-utf
    fastcgi.conf koi-win modules-enabled scgi_params snippets
    fastcgi_params mime.types nginx.conf sites-available uwsgi_params

    If not, I think the install has somehow gone wrong. Are you sure you installed the nginx pacakge and not nginx-light? I suggest apt purge and reinstall if you can lose your nginx configuration.

    You should also check you have php-fpm installed.

    You can check it is running with:

    pgrep -a php

    Which should return multiple lines containing "php-fpm"

    @UkAppCoder's advice on verifying php versions and using phpinfo() is good.

    I strongly disagree about using a GUI. It uses resources and increases attack surface. Professional sysadmins do not use GUIs for servers because the command line is more productive. They do have a lot of other tools they use for managing large numbers of servers and to manage complex setups reproducibly.

    @UkAppCoder Given what is happening with CentOS are thinking of switching? If so to something Red Hat based (e.g. Alma Linux, Rocky Linux, Oracle Linux) or something new?
     
    • Like
    Reactions: ctrlbrk
    Upvote 1
    gpieterz wrote:
    @UkAppCoder Given what is happening with CentOS are thinking of switching?

    There have been no problems for the last three years, so why would I change? It was just a quirk with the initial CentOS 8 release three years ago. Anyway, I should imagine it's been fixed by now. And I don't think all the CentOS sysadmins in the world will be changing either! :)

    gpieterz wrote:
    I strongly disagree about using a GUI. It uses resources and increases attack surface.

    As I understand it, ctrlbrk is setting up a local machine. I know he said 'localhost' in his original post, but from the nature of his requirements, I'm sure he means 'local' machine.

    The "attack surface" is as wide as the user allows it to be. All the usual elementary precautions should be observed by anyone on any machine.

    As far as "resources" are concerned, well this is the same for any computer, so I can't see what your point is here. Are you suggesting that the entire world should revert to command line only machines in order to save on resources?! :oops:

    Without a GUI, then it would take a Linux novice an inordinate amount of time to do what he's attempting here.
     
    Upvote 0
    Actually, regarding my CentOS 8 issue, I remember now. I think I did identify the problem to a degree. I'm sure it was related to the USB ports along with running processor-intensive programs.

    On the dual-core machine, I installed CentOS 8. One night when I closed it down, I left mobile device USBs plugged in, or just pulled them out without unmounting/ejecting safely. This had always been okay before, but with the extra strain, the system I had at the time wouldn't have it.

    Also, I was running Android Studio which is very resource intensive both locally and across the network. So I'm sure that my problem at the time was related to an inadequate machine for my requirements, coupled with my negligent lazy behaviour! :)

    Didn't lose any data, but it was a real pain going into the the command line of a crashed machine to rescue it. Everything has been fine since I started using quad-cores. :)
     
    Upvote 0

    ctrlbrk

    Free Member
    May 13, 2021
    995
    399
    If you installed from the repo I am puzzled by the sites-enabled/sites-available directories not being there. I just had a look at a Debian Buster VPS I set up, and they are there (and I did not create them!).
    Did you install the mainline version or the stable one?

    Edit: actually it doesn't seem to make a difference. I had installed the stable version. Now I tried by installing the mainline one and yet these are the contents of /etc/nginx

    conf.d
    fastcgi.params
    mime.types
    modules (symbolic link to /usr/lib/nginx/modules)
    nginx.conf
    scgi_params
    uwsgi_params

    I followed the instuctions under Debian here

     
    Last edited:
    Upvote 0

    ctrlbrk

    Free Member
    May 13, 2021
    995
    399
    @gpietersz I have an update: I tried to install nginx by simply running sudo apt install nginx without setting up the repositories indicated in the previous post or importing the nginx signing key, and now the contents of /etc/nginx are exactly the same as the ones you listed.
     
    Upvote 0

    gpietersz

    Free Member
  • Business Listing
    Sep 10, 2019
    2,721
    2
    713
    Northwhich, Cheshire
    pietersz.net
    @ctrlbrk that explains it. You installed it from the nginx repo so you did not get the debian specific configuration which is only in Debian's own repos.

    I think the usual Debian instructions will now work for you.

    I think it is better to install from the distro's own repos unless you really need to do otherwise (e.g., you need a feature that is only in the latest version).
     
    Last edited:
    • Like
    Reactions: ctrlbrk
    Upvote 1
    Solution

    gpietersz

    Free Member
  • Business Listing
    Sep 10, 2019
    2,721
    2
    713
    Northwhich, Cheshire
    pietersz.net
    There have been no problems for the last three years, so why would I change? It was just a quirk with the initial CentOS 8 release three years ago. Anyway, I should imagine it's been fixed by now. And I don't think all the CentOS sysadmins in the world will be changing either!
    I am getting a nasty feeling you do not know what is happening to Centos.

    There will be no further stable releases of Centos, Centos 8 is already EOL and Centos 7 will be EOL from 2024. It will be replaced by CentOS stream which is rolling release. Fine for desktops (I use Manjaro Linux myself), but not good for servers IMO.

    As I understand it, ctrlbrk is setting up a local machine. I know he said 'localhost' in his original post, but from the nature of his requirements, I'm sure he means 'local' machine.

    Ah, that explains it. I think we interpreted what @ctrlbrk said differently. If it is installed on bare metal on a PC I agree with you. I assumed that it was a VM or other setup where he wanted to replicate what he would have on a server.
     
    • Like
    Reactions: UkAppCoder
    Upvote 0
    gpietersz wrote:
    I am getting a nasty feeling you do not know what is happening to Centos.

    I have got a nasty feeling that you're quite right! Excuse me for a moment while I wipe this egg off my face! LOL! :)

    Thank you very much my friend. :) I pulled out that spare machine and installed Debian last night. Will be migrating today. Will install yet another Linux on the old CentOS.

    I installed NGINX, PHP, MySQL (MariaDB), php-fpm and phpMyAdmin using the Synaptic packaging manager which came with Debian. phpMyAdmin popped up in the browser without any problems, but it was being served by Apache.

    I did read something about the fastcgi server needing to be running in order to serve PHP with NGINX, and I had this running on the CentOS. However, I started to panic after reading about the CentOS 8 problems, so I started to migrate! :)

    So, @ctrlbrk, you might like to check whether you need to start php-fpm. On my Debian the command is:

    systemctl start php7.3-fpm

    (Replace the PHP version number with your own.)

    So, my NGINX is executing PHP scripts as normal, but when I try to access phpMyAdmin, the browser is downloading instead of executing. That is, when I request:


    I receive the dialog to download the phpMyAdmin index.php. I've come across this before, so it can't be that hard to fix. Will try again later.
     
    Upvote 0

    ctrlbrk

    Free Member
    May 13, 2021
    995
    399
    So, my NGINX is executing PHP scripts as normal, but when I try to access phpMyAdmin, the browser is downloading instead of executing.
    You may want to check this out


    It may or may not apply to you since you say other PHP scripts are getting executed.
     
    Upvote 0
    You may want to check this out


    It may or may not apply to you since you say other PHP scripts are getting executed.

    Thanks, but I've been around a few sites (including that one). I tried a few suggestions for modifying the NGINX config. It's just that obviously PHP scripts can't be served from certain directories by NGINX yet. phpMyAdmin is reached via a symbolic link to a directory which is not directly under the document root. This is why PHP is working under the document root, but not elsewhere yet. As a workaround, I thought about putting phpMyAdmin under the document root somewhere, but I'm pushed for time right now.

    So, as it stands, extra directives are probably required somewhere, but since I'm unfamiliar with the NGINX way of doing things, it will have to wait.

    Doesn't matter to me anyway. There's absolutely no problem with Apache, which is what I prefer. If I really wanted to fix this quickly, I would simply contact my webhost. I know this is on my local machine, but they are always very helpful towards their customers.

    Do you have a webhost? Perhaps they could help. After all, when it comes to setting up network servers, that's where the real experts are - not in places like StackOverflow! :)
     
    Last edited by a moderator:
    • Haha
    Reactions: ctrlbrk
    Upvote 0

    gpietersz

    Free Member
  • Business Listing
    Sep 10, 2019
    2,721
    2
    713
    Northwhich, Cheshire
    pietersz.net
    Thank you very much my friend.
    You are welcome. There are probably a lot of other people who do not know which is a bit worrying.
    I pulled out that spare machine and installed Debian last night. Will be migrating today. Will install yet another Linux on the old CentOS.
    If you find you do not like Debian there are a number of drop in replacements for Centos. The founder of Centos (which was originally not run by RH) is involved in one of them. Alma Linux seems to be the most popular so far.

    I did read something about the fastcgi server needing to be running in order to serve PHP with NGINX

    Correct, but that just means you need to have have php-fpm running (as you described).

    Nginx passes the name of the file to be executed to php-fpm so you can change that directory , or use a different one for particular paths if you want to.

    I just looked at the file of an install I (eventually!) got working a few weeks ago.
     
    • Like
    Reactions: ctrlbrk
    Upvote 0
    Good Lawd are you two still on this?! LOL! :)

    I did this last Saturday. Took about 40 minutes of my attention including Debian installation. :)

    Everything works fine except phpMyAdmin index.php source code is being displayed instead of being executed.

    Can't understand why you won't just use a GUI and save yourselves a lot of trouble.

    But if you insist on using CLI only, then you could:

    * set it up first with a GUI,

    * take notes on where the relevant files are and how you configured them,

    * then just reinstall with CLI only and use your notes to set it up again?

    Complete insanity in my opinion, but hey, if that's what you want! :)

    Interesting to note that you want to use a GUI for interacting with MySQL when it has a perfectly good command line! ;)
     
    Upvote 0

    gpietersz

    Free Member
  • Business Listing
    Sep 10, 2019
    2,721
    2
    713
    Northwhich, Cheshire
    pietersz.net
    Good Lawd are you two still on this?! LOL!

    I did it weeks ago. It took me longer than than you did but most of the time was getting data out of the sites someone else had set up.

    Can't understand why you won't just use a GUI and save yourselves a lot of trouble.

    I do not put a GUI on servers. I do use a GUI for local development. I also use some of the same locally installed GUI tools (text editor and file manager in particular) to manage the server.

    Interesting to note that you want to use a GUI for interacting with MySQL

    A web GUI is a bit different as there is a lot less to install. A lot less to add. I still do not use them though. I do not use MYSQL much - far more PostgreSQL. I do development locally (with GUIs available) and changes are applied to the server with migration scripts so I do not do much on the server. I do use CLI tools the little I do: mostly initial setup which is easier with the CLI anyway.

    There is another option for database GUIs: use a locally installed GUI that connects to a remote database. If a databases can be connected to over the internet anyway (usual with "cloud" hosted DBs or DBs that need to be accessed from multiple sites) just connect, otherwise use an ssh tunnel.
     
    • Like
    Reactions: ctrlbrk
    Upvote 0
    gpietersz:
    I did it weeks ago.

    So what the hell are we doing faffing about in here?! Why didn't you just post the instructions?!

    gpietersz:
    I do use a GUI for local development. I also use some of the same locally installed GUI tools (text editor and file manager in particular) to manage the server.

    This is what I'm talking about! We know that this is a local development machine - so just use a GUI! There are about a dozen of them listed during the Debian installation process. Just select the lot, finish the installation, choose a GUI, and do the damned job! It's simple! :rolleyes:

    gpietersz:
    A web GUI is a bit different as there is a lot less to install.

    Most web GUIs are bluddy awful, including those on websites. The phpMyAdmin GUI is particularly awful. The MySQL command line is much easier for me, but again, I suppose phpMyAdmin is easier for beginners.

    Okay, that's it. Am now leaving the twilight zone! :oops:
     
    Upvote 0

    Latest Articles

    Join UK Business Forums for free business advice