How to Install PHP 8 on Ubuntu

Prerequisites

  1. A Ubuntu server set up with sudo privileges.
  2. Completed the initial Ubuntu server setup.
  1. A running Compute Engine, see the Setting up Compute Engine Instance with Ubuntu 20.04.

Getting Started

sudo apt update
sudo apt upgrade

Add PPA for PHP 8

sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt update

Install PHP 8 for Apache

sudo apt install php8.0
php -v

Install PHP 8 FPM for Nginx

sudo apt install php8.0-fpm
php-fpm8.0 -v

Install PHP 8 Extensions

sudo apt install php8.0-extension_name
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 -y

Configure PHP 8 for Apache

sudo nano /etc/php/8.0/apache2/php.ini
upload_max_filesize = 32M 
post_max_size = 48M
memory_limit = 256M
max_execution_time = 600
max_input_vars = 3000
max_input_time = 1000

Configure PHP 8 for Nginx

sudo nano /etc/php/8.0/fpm/php.ini
upload_max_filesize = 32M 
post_max_size = 48M
memory_limit = 256M
max_execution_time = 600
max_input_vars = 3000
max_input_time = 1000
sudo php-fpm8.0 -t 
sudo service php8.0-fpm restart

Configure PHP 8 FPM Pools

sudo nano /etc/php/8.0/fpm/pool.d/www.conf
user = username 
group = username
listen.owner = username
listen.group = username

Restart PHP 8.0 FPM

sudo php-fpm8.0 -t 
sudo service php8.0-fpm restart

Upgrade to PHP 8 for Apache

sudo a2dismod php7.4
sudo a2enmod php8.0
sudo service apache2 restart

Upgrade to PHP 8 for Nginx

sudo nano /etc/nginx/sites-available/your.conf
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
fastcgi_pass unix:/run/php/php8.0-fpm.sock;
sudo nginx -t
sudo service nginx restart

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
CloudBooklet

CloudBooklet

Installation and Set Up of Web Applications on Google Cloud