Step‑by‑Step Guide to Installing and Configuring PHP 8 on Ubuntu for Apache and Nginx
This tutorial explains how to update an Ubuntu server, add the ondrej/php PPA, install PHP 8 and its extensions, configure php.ini for both Apache and Nginx, adjust performance settings, and restart services to fully enable PHP 8 on a Linux VPS or cloud instance.
This guide shows how to install the latest PHP 8 release (published 26 Nov 2020) on any Ubuntu 20.04 or 18.04 VPS, cloud server, or dedicated host, and configure it for Apache and Nginx.
Update system packages
sudo apt update
sudo apt upgradeThese commands refresh the package index and upgrade installed packages to the newest versions.
Add the PHP 8 PPA
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt updateAfter adding the repository you can install PHP 8.
Install PHP 8 sudo apt install php8.0 Verify the installation with: php -v Install PHP 8 for Apache sudo apt install php8.0 For Nginx, install the FPM package: sudo apt install php8.0-fpm Check the FPM version: php-fpm8.0 -v Install additional extensions sudo apt install php8.0-extension_name Common extensions can be installed in one command:
sudo apt install php8.0-common php8.0-mysql php8.0-xml php8.0-curl php8.0-gd php8.0-imagick php8.0-cli php8.0-dev php8.0-imap php8.0-mbstring php8.0-opcache php8.0-soap php8.0-zip -yConfigure PHP 8 for Apache
Edit the Apache php.ini file: sudo nano /etc/php/8.0/apache2/php.ini Recommended performance settings (search with F6 in the editor):
upload_max_filesize = 32M
post_max_size = 48M
memory_limit = 256M
max_execution_time = 600
max_input_vars = 3000
max_input_time = 1000After saving, restart Apache: sudo service apache2 restart Configure PHP 8 for Nginx (FPM)
Edit the FPM php.ini file: sudo nano /etc/php/8.0/fpm/php.ini Apply the same performance values as above, then restart PHP‑FPM:
sudo php-fpm8.0 -t
sudo service php8.0-fpm restartConfigure the PHP‑FPM pool
Edit the pool configuration to set the user and group: sudo nano /etc/php/8.0/fpm/pool.d/www.conf Replace www-data with your desired username in the lines:
user = username
group = username
listen.owner = username
listen.group = usernameSave with CTRL+X then Y.
Upgrade Apache to use PHP 8
sudo a2dismod php7.4
sudo a2enmod php8.0
sudo service apache2 restartUpgrade Nginx to use PHP 8 FPM
Edit the site configuration and change the fastcgi_pass socket from the old version to the new one:
sudo nano /etc/nginx/sites-available/your.conf # old line
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
# replace with
fastcgi_pass unix:/run/php/php8.0-fpm.sock;Test the Nginx configuration and restart:
sudo nginx -t
sudo service nginx restartAfter completing these steps, PHP 8 is installed, configured, and active on both Apache and Nginx.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
php Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
