Install PHP (8.3, 8.2, 7.4) Nginx Ubuntu 22.04

[ad_1]

Would you like to install PHP versions like 8.1, 8.2, 8.3, and 7.4 etc. in your Ubuntu nginx system and configure it properly as well?; Now, In this tutorial, we will show you step by step how to install PHP 8.1, 8.2, 8.3, or 7.4 on the Nginx Ubuntu 22.04 system.

Ezoic

Here are six steps to install and configure PHP 8.1, 8.2, 8.3 and 7.4 on ubuntu with Nginx:

  • Step 1 – Update System Repositories
  • Step 2 – Enable PHP Repository
  • Step 3 – Install PHP 8.1, 8.2, 8.3 or 7.4 with Nginx Ubuntu
  • Step 4 – Add Extensions for PHP 8.1, 8.2, 8.3 or 7.4
  • Step 5 – Verify PHP Version
  • Step 6 – Configure Nginx with PHP 8.X

Step 1 – Update System Repositories

Updating the system repositories, you can use this:

Ezoic

sudo apt update
sudo apt upgrade

Step 2 – Enable PHP Repository

To install or add PPA repository for PHP in Ubuntu, you can use this:

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

Step 3 – Install PHP 8.1, 8.2, 8.3 or 7.4 with Nginx Ubuntu

Here commands are given according to the version of PHP, which will help us to install PHP with fpm:

Ezoic

To install PHP fpm 8.1 version, use this command:

sudo apt install php8.1-fpm

To install PHP fpm 8.2 version, use this command:

sudo apt install php8.2-fpm

For install the PHP fpm 8.3 version, use this command:

Ezoic

sudo apt install php8.3-fpm

Step 4 – Add Extensions for PHP 8.1, 8.2, 8.3 or 7.4

Here commands are given according to the version of PHP, which will be used to install PHP extensions as per requirement. Here is an example command:

sudo apt-get install php8.x-PACKAGE_NAME

For installing PHP 8.1 extensions on an Ubuntu nginx, you can use this:

Ezoic

sudo apt install php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-dev php8.1-imap php8.1-mbstring php8.1-opcache php8.1-soap php8.1-zip php8.1-redis php8.1-intl -y

For installing PHP 8.2 extensions on an Ubuntu nginx, you can use this:

sudo apt install php8.2-common php8.2-mysql php8.2-xml php8.2-xmlrpc php8.2-curl php8.2-gd php8.2-imagick php8.2-cli php8.2-dev php8.2-imap php8.2-mbstring php8.2-opcache php8.2-soap php8.2-zip php8.2-intl -y

To install PHP 8.3 extensions on an Ubuntu machine, you can use the following commands:

Ezoic

sudo apt install php8.3-common php8.3-mysql php8.3-xml php8.3-xmlrpc php8.3-curl php8.3-gd php8.3-imagick php8.3-cli php8.3-dev php8.3-imap php8.3-mbstring php8.3-opcache php8.3-soap php8.3-zip php8.3-intl -y

Step 5 – Verify PHP Version

Whatever version of php you have installed in your system with the help of the above commands. You can use this to verify this.

php -v

Output
PHP 8.1.5 (cli) (built: Dec 21 2023 10:32:13) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.5, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.5, Copyright (c), by Zend Technologies

Step 6 – Configure Nginx with PHP 8.X

This step is very important. It helps to configure Nginx with PHP step by step as per your system.

Now, run the sudo nano /etc/nginx/sites-available/default, to edit the default nginx configuration file:

sudo nano /etc/nginx/sites-available/default

Configure your Nginx server block by updating the server section as shown:

server {

# ... some other code

location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
}
}

Now configure PHP with Nginx on the php.ini file, command according to the version of PHP you have installed.

To configure PHP 8.1 FPM with Nginx:

sudo nano /etc/php/8.1/fpm/php.ini

To configure PHP 8.1 FPM with Nginx:

sudo nano /etc/php/8.2/fpm/php.ini

For configure PHP 8.3 FPM with Nginx:

sudo nano /etc/php/8.3/fpm/php.ini

Hit F6 for search inside the editor and update the following values for better performance.

upload_max_filesize = 32M 
post_max_size = 48M
memory_limit = 256M
max_execution_time = 600
max_input_vars = 3000
max_input_time = 1000

To restart nginx ubuntu web server, you can use this:

sudo systemctl restart nginx

Conclusion

This tutorial taught us how to install PHP 8.1,2,3 on versions of your Ubuntu 22.04 server with Nginx.

[ad_2]

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
Jassweb, Rai Chak, Punjab, India. 143518