Upgrading WordPress to PHP 7: Configuration Changes
I upgraded my Ubuntu server to 16.04 and WordPress stopped working. Ubuntu 16.04 ships with PHP 7, and my nginx configuration still pointed to the old PHP 5 socket path.
The php-fpm socket moved from /run/php/php5-fpm.sock to /run/php/php7.0-fpm.sock. If your nginx config hardcodes the old path, requests to PHP files hang or return errors. WordPress won't load, the admin panel breaks, and you get gateway timeout errors.
Install the PHP 7 packages WordPress needs:
sudo apt install php-fpm php-mysql php7.0-xml
php-fpm provides the FastCGI process manager, php-mysql adds MySQL database support, and php7.0-xml handles XML parsing for WordPress's RSS feeds and XML-RPC.
PHP has a setting called cgi.fix_pathinfo that's enabled by default. It's a security risk—it lets attackers execute arbitrary PHP code by crafting specific URLs. Open /etc/php/7.0/fpm/php.ini, find ;cgi.fix_pathinfo=1, and change it to cgi.fix_pathinfo=0. This blocks a common attack vector. Restart PHP-FPM with sudo systemctl restart php7.0-fpm.
nginx configuration
Point nginx to the new PHP 7 socket. Edit /etc/nginx/nginx.conf and add this upstream block inside the http section:
upstream php {
server unix:/run/php/php7.0-fpm.sock;
}
This creates a named upstream called php pointing to the PHP 7 socket. Your site configs can reference php instead of hardcoding the socket path.
Here's a reusable WordPress config that works with this upstream. Save it as global/wordpress.conf:
# WordPress single blog rules.
# Designed to be included in any server {} block.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off;
log_not_found off;
expires max;
}
# Pass all .php files onto a php-fpm/php-fcgi server.
location ~ [^/]\.php(/|$) {
if (!-f $document_root$fastcgi_script_name) {
return 404;
}
include snippets/fastcgi-php.conf;
fastcgi_pass php;
}
The rewrite ensures /wp-admin URLs get the trailing slash (WordPress requires this). The static asset location block sets aggressive caching and stops logging 404s for missing images. The PHP location block checks if files exist before passing to php-fpm using the php upstream.
Include this in your WordPress site's server block with include global/wordpress.conf;. Test with sudo nginx -t and reload with sudo systemctl reload nginx.
PHP 7 ran roughly twice as fast as PHP 5.6 and used less memory. For WordPress sites handling real traffic, the upgrade meant lower server costs and faster page loads. Ubuntu 16.04 forcing the upgrade was painful for unprepared servers, but the performance gains made the hassle worthwhile.
Years later, I moved away from WordPress entirely. Building a static blog turned out to be faster and simpler than managing PHP, databases, and server configurations.