-1

http://MY_IP/phpmyadmin brings me to download a 19kb PHP file on an Ubuntu environment with Nginx 1.10.3 and php-7-fpm.

After installing Nginx with apt-get install nginx mysql-server php-fpm php-mysql -y I did this:

sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php/7.0/fpm/php.ini
sed -i 's/index index.html index.htm/index index.php index.html index.htm/g' /etc/nginx/nginx.conf
/etc/init.d/php7.0-fpm restart # MBP.
systemctl restart nginx # http://ip_address.

I than installed PMA:

cd /var/www/html
wget https://www.phpmyadmin.net/downloads/phpMyAdmin-latest-all-languages.zip
find /var/www/html -type f -iname '*phpmyadmin*.zip' -exec unzip {} \;
find /var/www/html -type d -iname 'phpmyadmin-*' -exec mv {} phpmyadmin \;
ln -s /usr/share/phpmyadmin /usr/share/nginx/html

I then navigated to http://myIpAddress/phpmyadmin and got the downloading suggestion.

nginx -t brings:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

No errors in tail /var/log/nginx/access.log.

A few errors do came when I did tail /var/log/nginx/error.log:

2017/08/09 18:50:44 [error] 1424#1424: *1 directory index of "/var/www/html/phpmyadmin/" is forbidden, client: 79.178.145.252, server: _, request: "GET /phpmyadmin/ HTTP/1.1", host: "46.101.255.64"

2017/08/09 18:57:12 [error] 1424#1424: *3 directory index of "/var/www/html/phpmyadmin/" is forbidden, client: 79.178.145.252, server: _, request: "GET /phpmyadmin/ HTTP/1.

It led me to think this is a permissions issue, so I ran:

chown www-data /var/www/html/ -R && chgrp www-data /var/www/html/ -R
find /var/www/html/* -type d -exec chmod 755 {} \; && find /var/www/html/* -type f -exec chmod 644 {} \;

Yet, it didn't help.

  • It doesn't do with clearing with browser cache, in this case.
  • I believe the problem is php-fpm related.

What else can cause this? As a freshman I don't know what else to check. I checked all logs I know. I will keep researching this but any advice would be valuable.


Update1:

Here's my Nginx configuration at /etc/nginx/sites-available/default.conf. Non code rows excluded:

server {

listen 80 default_server;
listen [::]:80 default_server;
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;

root /var/www/html;

index index.php index.html index.htm index.nginx-debian.html;

server_name _;

location / {
    try_files $uri $uri/ =404;
}

location ~ \.php$ {
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;
    include snippets/fastcgi-php.conf;
}

location ~ /\.ht {
    deny all;
}

location ~* \.(gif|jpg|png)$ {
    expires 30d;
}

}

  • What is your nginx configuration? – Tero Kilkanen Aug 9 '17 at 19:49
  • I just added it. – JohnDoea Aug 9 '17 at 19:57
  • 1
    You haven't configured Nginx to send requests to PHP. – Tim Aug 9 '17 at 20:01
  • @Tim I updated my code example. I seem to have did it now and I also tried to change server_name _; to myIpAddress _;. After both cases I restarted the server with systemctl restart nginx.service. No change. – JohnDoea Aug 9 '17 at 21:51
  • You really need to read a good tutorial. This is typically a trivial exercise. Check your Nginx logs, check your php-fpm logs. Try using a TCP socket rather than a unix socket. – Tim Aug 9 '17 at 22:10
0

Thanks to hints by Tim I found my problem: I haven't configured a TCP socket.

If found some guides on this particular issue and synthesized a solution from reading them.

This guide helped me the most. These QA sessions also helped: [1], [2].


Here's how I solved it exactly:

In /etc/php/7.0/fpm/pool.d I changed:

listen = /run/php/php7.0-fpm.sock

to:

listen = 127.0.0.1:9000

I also changed, accordingly, in /etc/nginx/sites-available/default, from:

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php7.0-fpm.sock;

}

to:

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass 127.0.0.1:9000;
}

I than allowed port 9000 in CSF-LFD in csf.conf (if your are not using CSF-LFD this is irrelevant to you but you're most probably using another Intrusion Prevention Software (IPS):

# Allow incoming TCP ports (added 9000 to TCP_IN).
# Allow outgoing TCP ports (added 9000 to TCP_OUT).

After that, I restarted PHP-FPM and Nginx:

/etc/init.d/php7.0-fpm restart
systemctl restart nginx

Then I managed to access PHPmyadmin from a browser (I also had to install mbstring for my PHPversion for that, via apt-get install php7.0-mbsting).

  • You might also need to clear your browsers cache.

That's basically it.


Note:

If after all, you couldn't upload a database file via PHPmyadmin, even though you did:

sed -i 's/post_max_size \= .M/post_max_size \= 200M/g' /etc/php/7.0/fpm/php.ini # regex dot instead any default character.
sed -i 's/upload_max_filesize \= .M/upload_max_filesize \= 200M/g' /etc/php/7.0/fpm/php.ini

Add the following row to default.conf (say, to the very end of the block, before the closing brace):

server {
    ...
    client_max_body_size 200M;
}
  • 1
    Good that you worked it out. Unix sockets are a valid way to do things, but sometimes trying TCP sockets is worth a shot. – Tim Aug 11 '17 at 3:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.