Run Multiple PHP Versions with Nginx on Ubuntu

You can run multiple php versions on Ubuntu without any issues. But you require multiple PHP versions if applications are built in different PHP versions like php 7.1 and php 7.2. 

Here, we will installPHP7.4, and PHP8.1 on the server.

sudo apt-get update && sudo apt-get upgrade

First, we will add PPA using the command below

sudo add-apt-repository ppa:ondrej/php

 Install PHP 8.1 with this command.

sudo apt install php8.1

Also install required php modules.

sudo apt install php8.1-cli php8.1-fpm php8.1-common php8.1-curl php8.1-gd php8.1-mbstring php8.1-mysql php8.1-xml

To configure php version on

server {

    listen 80;

    root /var/www/php81;

    index index.php;



    location ~* \.php$ {

        # With php-fpm unix sockets

        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;

        include         fastcgi_params;

        fastcgi_param   SCRIPT_FILENAME    $document_root$fastcgi_script_name;

        fastcgi_param   SCRIPT_NAME        $fastcgi_script_name;



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s