How to Install PHP 8.1 for Nginx on Ubuntu 23.04

To install PHP 8.1 for Nginx on Ubuntu 23.04, follow the steps below.

Step 1 : Update

Step 2 : Find PHP version

Step 3 : Install PHP 8.1 core components

Step 4 : Install commonly used PHP extensions

- mysql: MySQL database support

- curl: cURL library for URL handling

- xsl: XSL module for PHP

- gd: GD Graphics Library for image processing

- common: Common files for PHP

- xml: XML module for PHP

- zip: ZIP archive support

- soap: SOAP module for PHP

- bcmath: BCMath arbitrary precision mathematics

- mbstring: Multibyte string support

- gettext: Gettext module for PHP

- imagick: ImageMagick module for PHP

Step 5 : Verify PHP version

Step 6 : Create a new Nginx configuration file for the domain (example.com)

Add the following configuration inside the file, adjusting paths and settings as needed:

Save the file and exit the text editor.

Step 7 : Create a symbolic link to enable the new configuration

Step 8 : Test Nginx configuration

Step 9 : Restart Nginx

Step 10 : Test PHP by creating a info.php file

Add the following content:

Step 11 : Visit your domain to see the info.php results.

Congratulations! You have successfully installed PHP 8.1 for Nginx on Ubuntu 23.04.