Logo

How to Install PHP 8.2 for Apache on CentOS 7

Apr 03, 2024

To install PHP 8.2 for Apache on CentOS 7, follow the steps below.

Step 1 : Ensure your system is up to date by running:

sudo yum update

Step 2 : Import the Remi repository for PHP:

sudo yum install yum-utils
sudo yum install https://rpms.remirepo.net/enterprise/remi-release-7.rpm

Step 3 : Enable the PHP 8.2 repository:

sudo yum-config-manager --enable remi-php82

Step 4 : Install PHP Core

sudo yum install -y php

Step 5 : Install PHP Extensions

sudo yum install install -y php-{mysqlnd,curl,gd,mcrypt,json,pear,common,xml,zip,devel,xsl,soap,bcmath,mbstring,gettext,imagick}

These are commonly used PHP extensions:

- php-cli: Command line interface for PHP.

- php-mysqlnd: MySQL Native Driver - A MySQL database client for PHP.

- php-curl: Client URL Library for PHP - Allows you to connect and communicate to different types of servers with different protocols.

- php-gd: GD Graphics Library - Allows you to create and manipulate images using various functions.

- php-mcrypt: Encryption functions - Provides encryption and decryption functions.

- php-json: JSON extension - Allows you to work with JSON data.

- php-pear: PEAR framework - PHP Extension and Application Repository, used for managing and distributing PHP packages.

- php-common: Common files for PHP.

- php-xml: XML extension - Allows you to work with XML data.

- php-zip: ZIP extension - Allows you to work with ZIP archives.

- php-devel: Development files for PHP.

- php-xsl: XSL extension - Allows you to work with XSL transformations.

- php-soap: SOAP extension - Allows you to work with SOAP web services.

- php-bcmath: BCMath Arbitrary Precision Mathematics extension - Provides arbitrary precision mathematics functions.

- php-mbstring: Multibyte String extension - Provides multibyte string functions.

- php-gettext: Gettext extension - Allows you to internationalize your PHP applications.

- php-imagick: ImageMagick extension - Allows you to create, edit, and compose bitmap images.

Step 6 : Check the installed PHP version:

php -v

Step 7 : Restart Apache to apply changes:

sudo systemctl restart httpd

Step 8 : Create a PHP info file:

sudo nano /var/www/html/info.php

Add the following content to the file:

<?php
phpinfo();
?>

Step 9 : Now, visit your domain followed by "/info.php" in a web browser to view PHP information.

Congratulations! You have successfully installed PHP 8.2 for Apache on CentOS 7.