0

I'm fairly new to servers and am setting up my first web server with Nginx to use PHPMyadmin (as well as SSL, and Wordpress). The OS I'm working on is a Debian 10 Docker image.

I'm following this tutorial on how to have a LEMP stack. At the very end, I'm checking if PHP works indeed by creating a php.info page and running it afterwards (nginx and php services being started). However I keep on running onto a 404 page. When I type phpinfo() on the command line of my image, I get all the information correctly. Here are my codes.

example.com located at /etc/nginx/sites-available/

server {
    listen 443 ssl;
    listen [::]:443 ssl;

    include snippets/self-signed.conf;
    include snippets/ssl-params.conf;

    root /var/www/example.com;
    index index.php index.html index.htm;

    server_name example.com www.example;

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

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

server {
    listen 80;
    listen [::]:80;

    server_name example.com www.example.com;

    return 301 https://$server_name$request_uri;
}

server {
   listen 80;
   server_name pma.com www.pma.com;
   root /usr/share/phpMyAdmin;

   location / {
      index index.php;
   }

   location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
      access_log off;
      expires 30d;
   }

   location ~ /\.ht {
      deny all;
   }

   location ~ /(libraries|setup/frames|setup/libs) {
      deny all;
      return 404;
   }

   location ~ \.php$ {
      include /etc/nginx/fastcgi_params;
      fastcgi_pass 127.0.0.1:9000;
      fastcgi_index index.php;
      fastcgi_param SCRIPT_FILENAME /usr/share/phpMyAdmin$fastcgi_script_name;
   }
}

info.php located at /var/www/example.com/

<?php
phpinfo();
?>

I use a shell script file to install everything onto my docker image at build time.

Script

## Packages Installation ##
apt-get update -y && apt-get upgrade -y && apt-get install -qq nginx \
php-json php-xmlrpc php-xml php-soap php-fpm php-mysql php-mbstring \
mariadb-server \
wordpress \
vim wget
###########################

# wget https://files.phpmyadmin.net/phpMyAdmin/4.9.0.1/phpMyAdmin-4.9.0.1-all-languages.tar.gz
# tar -xzvf phpMyAdmin-4.9.0.1-all-languages.tar.gz

## Apache2 Removal ##
apt-get remove --purge apache2 -y
#####################

# SSL Configuration ##
service mysql start
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout \
/etc/ssl/private/nginx-selfsigned.key -out /etc/ssl/certs/nginx-selfsigned.crt \
-subj "/C=BE/ST=BRUSSELS CITY/L=Brussels/O=19 Coding School/OU=Lacollar/CN=172.17.0.2/emailAddress=lacollar@student.s19.be"
openssl dhparam -out /etc/nginx/dhparam.pem 2048
#snippets creation
#conf file editing
######################

## PHP Processor Configuration on Nginx ##
# mv /var/www/example.com /var/www/example.com.bak
mkdir /var/www/example.com
cp /var/www/html/index.nginx-debian.html var/www/example.com/index.nginx-debian.html
chown -R $USER:$USER /var/www/example.com
#copy example onto sites-available
chmod 755 /etc/nginx/sites-available/example.com
ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled
nginx -t
##########################################

# ## phpMyAdmin Installation ##
rm /phpMyAdmin-4.9.0.1-all-languages.tar.gz
# mkdir /usr/share/phpMyAdmin
mv /phpMyAdmin-4.9.0.1-all-languages /usr/share/phpMyAdmin
mv /usr/share/config.inc.php /usr/share/phpMyAdmin/
#save config.sample, copy config
mysql < /usr/share/phpMyAdmin/sql/create_tables.sql -u root
mysql -u root -e "GRANT ALL PRIVILEGES ON phpmyadmin.* TO 'pma'@'localhost' IDENTIFIED BY 'pmapass'"
mysql -u root -e "FLUSH PRIVILEGES"
#copy phpmyadmin.conf onto /etc/nginx/conf.d
mkdir /usr/share/phpMyAdmin/tmp
chmod 777 /usr/share/phpMyAdmin/tmp
chown -R www-data:www-data /usr/share/phpMyAdmin
mysql -u root -e "CREATE DATABASE app_db"
mysql -u root -e "GRANT ALL PRIVILEGES ON app_db.* TO 'app_user'@'localhost' IDENTIFIED BY 'password'"
mysql -u root -e "FLUSH PRIVILEGES"
# #############################

# IP Address display
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'

rm /tmp/configuration.sh

Since I thought the issue could not be with PHP but something else, I also tried setting up phpMyadmin (and then restarting nginx). I can't access it which makes think the issue lies within PHP.

Every help appreciated.

lcols19
  • 1
  • 1
  • What is your actual `server_name`? You seem to have used a wide variety of different names, none of which match each other. – Michael Hampton Aug 24 '20 at 17:08
  • example.com. I thought the server block for phpmyadmin required another name. – lcols19 Aug 24 '20 at 17:11
  • The server_name is what you will use in the browser to access it. If it doesn't match, you get the default, which is usually just going to give you a 403 or 404 error. – Michael Hampton Aug 24 '20 at 17:13
  • On port 443, you have server names example.com www.example That translates to what you'd type in the browser, so www.example is definately incorrect. Maybe this is a typo? Then on port 80, you have server names example.com www.example.com You are redirecting to https using whatever host name was typed in the browser on http, but your http host names do not match your https host names. Based on your current setup, https://example.com/info.php or http://example.com/info.php (should redirect to https) should give you the PHP info page. I'd also recommend reading up on nginx. – DubStep Aug 24 '20 at 18:00

0 Answers0