“update/publish post failed” problem solved under WordPress
I’m using nginx+php-fpm for my wordpress blog site. After I modified my permalinks setting under Settings, I suddenly found that all my posts’ links are broken! All I got was just a 404 error.
And when I tried to update posts published earlier or tried to publish new posts, I always got errors like “update post failed” or “publish failed”.
I tried to disable all my active wordpress plugins in case one of them caused this situation, especially plugins like W3 Total Cache or Yoast SEO or sitemap plugin. No help at all.
After searching for a while for possible answers and solutions to this problem, I realized that this problem was related to nginx configuration. Most of the time problems caused by modifying permalinks are related with nginx misconfiguration if you’re using it.
Here I’d like to give one save-for-all solution to nginx configuration if you’re using nginx+php-fpm server stack.
location / {
if (!-e $request_filename){
rewrite ^(.*)$ /index.php$1 last;
}
}
location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/dev/shm/php-cgi.sock;
}
This code snippet will help you a lot whenever you meet problems related with php url routing analysis. It uses PATH_INFO parameter in nginx. As a result it enables your php site’s url routing analysis to be compatible with php-fpm and apache2. Try it out.
I’ll give a more detailed explanation when I have time later.
I learnt it the hard way when I tried to transfer a rather old php site from LAMP to LNMP last time. It cost me nearly 4 evenings debugging and solving the problem.