{"id":13095,"date":"2023-05-05T07:25:35","date_gmt":"2023-05-05T11:25:35","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=13095"},"modified":"2023-05-05T07:25:38","modified_gmt":"2023-05-05T11:25:38","slug":"how-to-install-php-8-2-on-centos-7-rhel-7","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/how-to-install-php-8-2-on-centos-7-rhel-7\/","title":{"rendered":"How To Install PHP 8.2 on CentOS 7 | RHEL 7"},"content":{"rendered":"\n
In this PHP 8.2 tutorial we will now show you how to install PHP 8.2 on CentOS 7 and RHEL 7 based Linux systems. If you are looking into installing PHP 8.2 on Ubuntu systems<\/a>, we have a post for that as well as this post showing how to install on Debian 11 and Debian 10<\/a> Linux systems.<\/p>\n\n\n\n PHP 8.2 is a version of the PHP<\/a> programming language released in December 2022 with many new features. Here are some highlights:<\/p>\n\n\n\n CentOS<\/a> 7 \/ RHEL 7 Linux<\/a> systems rely on third-party repositories such as Remi or IUS for the installation of PHP 8.2. These repositories provide updated versions of PHP for these systems which are not available in default OS repos.<\/p>\n\n\n\n Update the package list by running the following commands:<\/p>\n\n\n\n EPEL and REMI are third-party repositories that provide additional software packages for Enterprise Linux distributions. REMI provides the latest versions of PHP.<\/p>\n\n\n\n Run this to add EPEL repository on your system:<\/p>\n\n\n\n Run this to add Remi repository on your system:<\/p>\n\n\n\n Enable REMI for PHP 8.2<\/p>\n\n\n\n You can now install PHP 8.2 on CentOS 7 | RHEL 7 using yum (Yellowdog Updater Modified) package manager.<\/p>\n\n\n\n Confirm version of PHP currently default in the system.<\/p>\n\n\n\n For example, assuming we want to install the following PHP extensions:<\/p>\n\n\n\n bz2, cli, common, curl, intl, mbstring, mysql, zip<\/p>\n\n\n\n The we would run the following command to install the above extensions:<\/p>\n\n\n\n In this section we will use Nginx as a reverse proxy to forward incoming PHP requests to PHP-FPM for execution. Therefore we need to install Nginx and FPM PHP extension on your system.<\/p>\n\n\n\n Next we start and enable nginx and php-fpm services.<\/p>\n\n\n\n You can confirm the status of services started with this command.<\/p>\n\n\n\n Set PHP-FPM to listen on a socket instead of IP and port. Open the Nginx config file and make the following modifications.<\/p>\n\n\n\n Restart php-fpm service to apply changes.<\/p>\n\n\n\n Edit Nginx config file and add the following block inside the http block to configure Nginx to forward PHP requests to PHP-FPM. This is the VirtualHost configuration sample:<\/p>\n\n\n\n Validate your nginx configurations using this command.<\/p>\n\n\n\n Install Apache httpd package.<\/p>\n\n\n\n Stop nginx service if running:<\/p>\n\n\n\n Start and enable httpd service.<\/p>\n\n\n\n In this guide, you should have been able to successfully install PHP 8.2 on your CentOS 7 or RHEL 7 Linux system using REMI third party repository. In addition we have shown you in brief how to use PHP 8.2 with Nginx and Apache. For more details on how to configure PHP 8.2 for web servers please visit this in-depth guide on how to run your PHP with Nginx or Apache web servers<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":" In this PHP 8.2 tutorial we will now show you how to install PHP 8.2 on CentOS 7 and RHEL 7 based Linux systems. If you are looking into installing…<\/p>\n","protected":false},"author":1,"featured_media":13110,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,23,9,25,16],"tags":[],"yoast_head":"\n\n
Prerequisites to Install PHP 8.2 on CentOS 7 | RHEL 7<\/h2>\n\n\n\n
Step 1: Update CentOS 7 | RHEL 7<\/h2>\n\n\n\n
$ sudo yum update -y<\/code><\/pre>\n\n\n\n
Step 2: Add EPEL & REMI Repository<\/h2>\n\n\n\n
$ sudo yum -y install https:\/\/dl.fedoraproject.org\/pub\/epel\/epel-release-latest-7.noarch.rpm<\/code><\/pre>\n\n\n\n
$ sudo yum -y install http:\/\/rpms.remirepo.net\/enterprise\/remi-release-7.rpm<\/code><\/pre>\n\n\n\n
$ sudo yum-config-manager --enable remi-php82<\/code><\/pre>\n\n\n\n
Step 3: Install PHP 8.2 on CentOS 7 \/ RHEL 7<\/h2>\n\n\n\n
$ sudo yum -y install php<\/code><\/pre>\n\n\n\n
$ php -v\n\nOutput\n\nPHP 8.2.1 (cli) (built: Jan 3 2023 18:40:55) (NTS gcc x86_64)\nCopyright (c) The PHP Group\nZend Engine v4.2.1, Copyright (c) Zend Technologies<\/code><\/pre>\n\n\n\n
Step 4: Install PHP 8.2 extensions<\/h2>\n\n\n\n
$ sudo yum install php8.2-{bz2,cli,common,curl,intl,mbstring,mysql,zip}<\/code><\/pre>\n\n\n\n
How to use PHP 8.2 with Nginx on CentOS 7 | RHEL 7<\/h2>\n\n\n\n
$ sudo yum install nginx php-fpm -y<\/code><\/pre>\n\n\n\n
$ sudo systemctl enable --now nginx php-fpm<\/code><\/pre>\n\n\n\n
$ systemctl status nginx php-fpm<\/code><\/pre>\n\n\n\n
$ sudo vim \/etc\/php-fpm.d\/www.conf\n\nFile\n\nuser = nginx\ngroup = nginx\n;listen = 127.0.0.1:9000\nlisten = \/var\/run\/php-fpm.sock\nlisten.owner = nginx\nlisten.group = nginx\nlisten.mode = 0660<\/code><\/pre>\n\n\n\n
$ sudo systemctl restart php-fpm<\/code><\/pre>\n\n\n\n
$ sudo vim \/etc\/nginx\/nginx.conf\n\nFile\n\nserver {\n listen 80;\n server_name myapp.com;\n root \/var\/www\/myapp;\n index index.php index.html;\n\n location ~ \\.php$ {\n include \/etc\/nginx\/fastcgi_params;\n fastcgi_pass unix:\/var\/run\/php-fpm.sock;\n }\n}<\/code><\/pre>\n\n\n\n
$ sudo nginx -t<\/code><\/pre>\n\n\n\n
Using PHP 8.2 with Apache on CentOS 7 | RHEL 7<\/h2>\n\n\n\n
$ sudo yum install httpd<\/code><\/pre>\n\n\n\n
$ sudo systemctl disable --now nginx<\/code><\/pre>\n\n\n\n
$ sudo systemctl enable --now httpd<\/code><\/pre>\n\n\n\n
Conclusion<\/h2>\n\n\n\n