PHP-FPM and Page 404

My Kirby site was up and running successfully. While trying to install Mailgun as my mail server, I had to restart my Digital Ocean server. After the restart, I got a 502 bad gateway error because Ubuntu could not find php-fpm.

I installed php-fpm, which made the home page work, but all other pages now return a 404 error.

I’m lost. If anyone can help, I’d really appreciate it.

I’m running Ubuntu 16.04, PHP 7.0, and nginx.

My nginx error log is empty. If any additional information would be helpful, please just ask for it.


Are you sure the .htacess file is in place? Usually when only the home page works, its because this is missing or has a malformed rule in it.

There are other reasons, but check that first. Could also try checking the PHP error log, which i think is in /usr/local/apache/logs/error_log on Ubuntu, although you may have to Google the location. Putting a phpinfo page up on the the server will tell you where the log is being written to.

Thanks for the reply. The .htaccess file is in place. It worked just before the restart. I’ll post it’s contents for clarity below. I checked and the “error_log” is listed as “no value”

I found this post that mentioned the following that I do not really understand. I’m not sure if installing php-fpm caused the break.

Since you are using PHP FPM, the mentioned files need to be writable by the user or group under which it is running. You can see which user and group these are by looking for the user and group vars in the PHP FPM config.

You then need to chown -R FPMUSER . the files in your Kirby installation. Make sure to run this at the level where the index.php is.

.htaccess contents

# Kirby .htaccess

# rewrite rules
<IfModule mod_rewrite.c>

# enable awesome urls. i.e.:
RewriteEngine on

# make sure to set the RewriteBase correctly
# if you are running the site in a subfolder.
# Otherwise links or the entire site will break.
# If your homepage is
# Set the RewriteBase to:
# RewriteBase /mysite

# In some enviroments it's necessary to
# set the RewriteBase to:
# RewriteBase /

# block text files in the content folder from being accessed directly
RewriteRule ^content/(.*)\.(txt|md|mdown)$ index.php [L]

# block all files in the site folder from being accessed directly
# except for requests to plugin assets files
#RewriteRule ^assets/plugins/([a-zA-Z0-9\.\-_%=]+)/(.*)$ site/plugins/$1/assets/$2 [L,N]
#RewriteCond $1 !^plugins/[a-zA-Z0-9\.\-_%=]+/assets/.*
RewriteRule ^site/(.*) index.php [L]

# block direct access to kirby and the panel sources
RewriteRule ^(kirby|panel\/app|panel\/tests)/(.*) index.php [L]

# make panel links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^panel/(.*) panel/index.php [L]

# make site links work
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php [L]


# Additional recommended values
# Remove comments for those you want to use.
# AddDefaultCharset UTF-8
# php_flag short_open_tag on

Well, what that post is saying is that you need to check the username that FPM is using by looking into its config file, and then set the Kirby files to belong to that user so that FPM has the rights to work with them. You do this by logging into the server via SSH from a terminal on a mac or linux. If your on windows, you will need Putty becuase windows does not have a built in SSH support (although if you have a recent version of windows 10, with the Ubuntu Terminal installed, you can use that.)

Are you sure you installed phpfpm correctly? I am not completely convinced it should be necessary to change file ownsership, becuase currently the files are owned by the user that has the right to serve them. If you change them, you might make phpfpm happy but upset something else.

I would check this guide from digital ocean and retrace your steps.

If you are on an nginx server, the .htaccess file is of no use at all. You would need an nginx configuration file for that.

@texnixe my old VPS had both Apache and Nginx installed with Apache basically passing things through to Nginx. Don’t know why they set it up that way, but they did. The .htacess was needed in that case, and I think got translated on the fly on the way to Nginx. I’m not hugely knowledgable about nginix, i didn’t really mess with it. If it aint broke, don’t fix it :slight_smile:

@christhornham If you do indeed need a Nginx config rather then an .htaccess, this gist might get you started.

And if the home page works but other pages do not, the error has nothing to do with file rights. These are only relevant when writing to file via the Panel, not for reading the files.

I’m away from my computer for a bit but just to make sure I was clear.

I had a fully functioning Kirby site. All pages worked without 404 errors.

I set up mailgun and postfix following the digital ocean tutorial.

Postfix wasn’t working and I did served power down and then power up to get it working.

After the power down no pages included the index worked. I had previously installed php-Fpm using the tutorial you linked in your last post. For some reason after the restart, php-fpm had to be reinstalled.

Once reinstalled the 502 error ended but the 404 errors began.

Thanks for clearing that up.

I retraced all of my steps. Still 404s. I’ll try some more general troubleshooting tonight. If that doesn’t work, I might rebuild a new server from scratch, and go back to Apache.


I think that’s probably best. I would consider doing it first using Vagrant locally and then repeating it on Digital Ocean. That way you will have a local environment that’s 1:1 with the live server. You can always put Virtualmin / Webmin on it to ease configuration. If i remember correctly, if you just rebuild the server with literally just ubuntu on it, then add virtualmin, it will set everything else up for you automatically (mail, postfix, php, mysql etc). Save you some time. It will do LAMP or LEMP setup for you.