To install PHP 8.2 for Apache on Ubuntu 22.04, you can follow these steps:
Step 1 : Update your package list to ensure you have the latest information about available packages
Step 2 : Install software-properties-common
Step 3 : Add the ppa:ondrej/php repository
Run the following commands to add the repository:
Step 4 : Install PHP 8.2 and the required modules. You can install the libapache2-mod-php8.2 package, which includes the Apache module for PHP:
Step 5 : Install Additional PHP Extensions
You can install various PHP extensions based on your requirements. Here are some common ones:
These extensions include support for CGI, MySQL, cURL, XSL, GD, common utilities, XML, ZIP, SOAP, BCMath, Multibyte String, Gettext, and Imagick.
Step 6 : Verify PHP Installation
To check if PHP is installed successfully, you can run the following command:
This should display information about PHP version 8.2.
Step 7 : Configure Apache to use PHP
Apache should be configured to use PHP by default, with the libapache2-mod-php8.2 module enabled. To confirm, you can run:
Step 8 : Restart Apache
After making changes to the Apache configuration, it's necessary to restart the Apache service for the changes to take effect. Run the following command:
Step 9 : Test PHP
Create a simple PHP file to test if PHP is working with Apache. Use a text editor to create a file named info.php in the default web root directory:
Add the following content to the file:
Save the file and exit the text editor.
Step 10 : Access the PHP Info Page
Open a web browser and navigate to http://your-server-ip/info.php, replacing your-server-ip with the actual IP address or domain name of your Ubuntu server. You should see the PHP information page, confirming that PHP is working with Apache.
Congratulations! You've successfully installed PHP 8.2 for Apache on Ubuntu 22.04, and additional extensions have been added to meet common requirements.