0

thanks for looking into my question.

I'm setting up a VPS using Ubuntu and Nginx, with the goal of hosting multiple WordPress websites. So far I've managed to get Phpmyadmin running on the subdomain pma.mydomain.com, and it's handling php like it should.

However, when I created all necessary items for hosting a website on the main domain (directory, server block, WP-files) it will not render the php. Either it displays a blank page (when looking at the source of the page, you see raw php code), or it tries to download the php file.

It's a fresh install - mysql, php8.1 is working and running, ufw firewall is not blocking any ports, the nginx.conf is (probably?) allright (hence the working phpmyadmin subdomain). Did I use the wrong php-code in the mydomain.conf? (see below). I'm totally lost at this point. Thanks in advance. Sorry about the certbot making it more difficult to read.

server {

listen 80;
listen [::]:80;
root /var/www/mydomain;
index index.php index.html index.htm index.nginx-debian.html;
server_name mydomain.com www.mydomain.com;

access_log /var/log/nginx/mydomain_access.log;
error_log /var/log/nginx/mydomain_error.log;


client_max_body_size 100M;

location ~ / {
try_files $uri $uri/ /index.php;
}

location ~ \.php$ {
include snippets/fastcgi-php.conf;
include fastcgi_params;
fastcgi_pass unix:var/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
}

    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot


    add_header Strict-Transport-Security "max-age=31536000" always; # managed by Certbot


    ssl_trusted_certificate /etc/letsencrypt/live/mydomain.com/chain.pem; # managed by Certbot
    ssl_stapling on; # managed by Certbot
    ssl_stapling_verify on; # managed by Certbot

}
server {
    if ($host = mydomain.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


listen 80;
listen [::]:80;
root /var/www/mydomain/;
index index.php index.html index.htm index.nginx-debian.html;
server_name mydomain.com www.mydomain.com;

access_log /var/log/nginx/mydomain_access.log;
error_log /var/log/nginx/mydomain_error.log;


client_max_body_size 100M;

location ~ / {
try_files $uri $uri/ /index.php;
}

location ~ \.php {
include snippets/fastcgi-php.conf;
include fastcgi_params;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME \$document_root\$fastcgi_script_name;
}




}
  • Make sure `php8.1-fpm` is started as a service and that it uses a sock file instead of localhost port 9000 – Machavity Oct 14 '22 at 12:19
  • @Machavity Doesn't the file above determine that? It's set correctly here, right? If it's another file where I should pooint it to a sock file, wouldn't the subdomain where phpmyadmin is running also be effected by that? – Ramon Linssen Oct 14 '22 at 13:01
  • To be clear, PHP-FPM will **either** listen on a sock file **or** a port. You need to double check that you're using the right one there. If your PMA instance is working, you might want to compare the two – Machavity Oct 14 '22 at 13:11

0 Answers0