This brief tutorial shows students and new users how to use PHP 8.0 with WordPress on Ubuntu 20.04 | 18.04.
The WordPress team encourages all users to run the latest and most excellent versions of PHP. So if PHP 8.0 is fully supported, you may want to upgrade to it and make use of its newest features and enhancements that were released.
Currently, PHP 8.0 is not ready to be used with WordPress. WordPress 5.6, released in a couple of weeks this date, might support it, but developers are still calling WordPress 5.6 “beta compatible” with PHP 8.0.
If PHP 8.0 works with core WordPress functions, I doubt all themes and plugins will work without issues.
If you haven’t installed WordPress, search our website to learn how to install it on Ubuntu.
Upgrade to PHP 8.0 with Nginx
If you’re running Nginx on Ubuntu to support WordPress, the steps below show you how to upgrade to PHP 8.0-FPM.
This post assumes that you’re running PHP 7.4 or previous.
Ubuntu does not have PHP 8.0-FPM packages available in its default repositories. To install the latest versions of PHP on Ubuntu, you may have to add third-party repositories.
Simply run the commands below to add the below repository to Ubuntu.
sudo apt-get install software-properties-common sudo add-apt-repository ppa:ondrej/php
Then update and upgrade to PHP 8.0-FPM
sudo apt update
Next, run the commands below to install PHP 8.0-FPM and related modules.
sudo apt install php8.0-fpm php8.0-common php8.0-mysql php8.0-gmp php8.0-curl php8.0-intl php8.0-mbstring php8.0-xmlrpc php8.0-gd php8.0-xml php8.0-cli php8.0-zip
After installing PHP 8.0-FPM, run the commands below to open Nginx’s PHP default configuration file.
sudo nano /etc/php/8.0/fpm/php.ini
The lines below are a good setting for most PHP-based CMS… Update the configuration file with these and save.
file_uploads = On allow_url_fopen = On short_open_tag = On memory_limit = 256M cgi.fix_pathinfo = 0 upload_max_filesize = 100M max_execution_time = 360 date.timezone = America/Chicago
Restarting the Nginx web server and PHP script would be best whenever you change the PHP configuration file.
To do so, run the commands below:
sudo systemctl restart nginx.service
sudo systemctl restart php8.0-fpm.service
After that, run the commands below to enable PHP 8.0 support for Nginx.
Open the current WordPress virtual host site configuration file and enable the PHP block to use PHP 8.0-FPM.
Ubuntu default site configuration file can be found at
sudo nano /etc/nginx/sites-available/default
Then edit the PHP block session:
# Add index.php to the list if you are using PHP index index.php index.html index.htm index.nginx-debian.html; # pass PHP scripts to FastCGI server # location ~ \.php$ { include snippets/fastcgi-php.conf; # # # With php-fpm (or other unix sockets): fastcgi_pass unix:/var/run/php/php8.0-fpm.sock; # # With php-cgi (or other tcp sockets): # fastcgi_pass 127.0.0.1:9000; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one
After that, restart the Nginx HTTP server to use PHP 8.0-FPM.
sudo systemctl restart nginx.service
Finally, run the commands below to remove all PHP 7.4-FPM packages.
sudo apt-get purge `dpkg -l | grep php7.4| awk '{print $2}' |tr "\n" " "`
Doing that will prompt you to accept the changes to your system. Then type Y to continue. When done, PHP 8.0-FPM should be enabled, and PHP 7.4-FPM should be removed entirely from Ubuntu.
If you’re running PHP 7.3 or previously, replace 7.4 with your specific PHP version number to remove it from Ubuntu.
Upgrade to PHP 8.0 with Apache2
Skip the above steps if you’re running WordPress on an Apache2 HTTP server.
Apache2 runs on PHP 8.0, while Nginx runs on PHP 8.0-FPM.
Again, Ubuntu may not have PHP 8.0 packages available in its default repositories. To install PHP 8.0 on Ubuntu to support WordPress, you may need to run the commands below to add a third-party repository.
sudo apt-get install software-properties-common sudo add-apt-repository ppa:ondrej/php
After adding the repository above, update and install PHP 8.0
sudo apt update
Next, run the commands below to install PHP 8.0 and related modules.
sudo apt install php8.0 libapache2-mod-php8.0 php8.0-common php8.0-mysql php8.0-gmp php8.0-curl php8.0-mbstring php8.0-xmlrpc php8.0-gd php8.0-xml php8.0-cli php8.0-zip
After installing PHP 8.0, run the commands below to open Apache’s PHP default configuration file.
sudo nano /etc/php/8.0/apache2/php.ini
The lines below are a good setting for most PHP-based CMS… Update the configuration file with these and save.
file_uploads = On allow_url_fopen = On short_open_tag = On memory_limit = 256M cgi.fix_pathinfo = 0 upload_max_filesize = 100M max_execution_time = 360 date.timezone = America/Chicago
For Apache2 and PHP 8.0, you must turn off previous versions of PHP and enable Apache2 to use the latest version.
First, run the commands below to disable PHP 7.4.
sudo a2dismod php7.4
Now that PHP 7.4 is disabled, run the commands below to enable PHP 8.0.
sudo a2enmod php8.0
After enabling PHP 8.0, run the commands below to restart Apache2, and PHP 8.0 should be used to support WordPress.
sudo systemctl restart apache2.service
Finally, run the commands below to remove all PHP 7.4 packages.
sudo apt-get purge `dpkg -l | grep php7.4| awk '{print $2}' |tr "\n" " "`
That’s it!
Conclusion:
- PHP 8.0 offers numerous improvements and new features that enhance WordPress performance.
- It’s essential to ensure compatibility with themes and plugins before upgrading.
- Following the steps provided, you can successfully upgrade to PHP 8.0 using either Nginx or Apache2 on Ubuntu.
- Always configure PHP settings appropriately to optimize your WordPress site’s functionality.
- Remember to remove outdated PHP versions to maintain a clean and efficient server environment.
- Regularly check for updates and compatibility to maximize the benefits of using the latest PHP version.
Leave a Reply to Atul Host Cancel reply