YouTube Icon

Code Playground.

How to Install PHP on CentOS 8

CFG

How to Install PHP on CentOS 8

PHP is one of the most utilized worker side programming dialects. Numerous famous CMS and structures, for example, WordPress, Magento, and Laravel are implicit PHP. 

In this guide, we will examine how to introduce PHP 7.2, 7.3, or 7.4 on CentOS 8. Prior to picking which form of PHP to introduce, ensure that your applications uphold it. 

We'll likewise tell you the best way to incorporate PHP with Nginx and Apache. 

Installing PHP on CentOS 8

CentOS 8 is conveyed with PHP 7.2. This adaptation underpins the majority of the cutting edge PHP applications, however will not, at this point be effectively kept up as of November 2019. The more up to date PHP forms are accessible from the Remi vault . 

Enable the Remi repository

In case you will introduce the distro stable PHP adaptation 7.2, skirt this progression. Something else, on the off chance that you need to introduce PHP 7.3 or 7.4 empower the Remi storehouse by running the accompanying order as root or client with sudo advantages : 

sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm

The order above will likewise empower the EPEL vault . 

When the establishment is finished, run the order beneath to get a rundown of all accessible PHP renditions : 

sudo dnf module list php

The yield will show a rundown of every single accessible module, including the related stream, rendition, and establishment profiles. 

Last metadata expiration check: 0:02:11 ago on Fri 18 Oct 2019 08:31:43 PM UTC.
CentOS-8 - AppStream
Name    Stream       Profiles                     Summary                 
php     7.2 [d][e]   common [d], devel, minimal   PHP scripting language  

Remi's Modular repository for Enterprise Linux 8 - x86_64
Name    Stream       Profiles                     Summary                 
php     remi-7.2     common [d], devel, minimal   PHP scripting language  
php     remi-7.3     common [d], devel, minimal   PHP scripting language  
php     remi-7.4     common [d], devel, minimal   PHP scripting language  

Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled

The default PHP module is set to PHP 7.2. To introduce a more up to date PHP discharge, empower the fitting form: 

PHP 7.3 

sudo dnf module reset php
sudo dnf module enable php:remi-7.3

PHP 7.4 

sudo dnf module reset php
sudo dnf module enable php:remi-7.4

You are presently prepared to introduce PHP on your CentOS worker. 

Install PHP

The accompanying order will introduce PHP and probably the most widely recognized PHP modules: 

sudo dnf install php php-opcache php-gd php-curl php-mysqlnd

FPM is introduced as a reliance and utilized as a FastCGI worker. Start the FPM administration and empower it to consequently begin on boot: 

sudo systemctl enable --now php-fpm

Configuring PHP to work with Apache

On the off chance that SELinux is running on your framework, you'll have to refresh the SELinux security setting: 

sudo chcon -Rt httpd_sys_rw_content_t /var/www

On the off chance that you are utilizing Apache as your web worker, restart the httpd administration utilizing the accompanying order, and you are a great idea to go: 

sudo systemctl restart httpd

Configuring PHP to work with Nginx

Of course, PHP FPM runs as client apache. To keep away from authorization issues, we'll change the client to nginx. To do as such, alter the lines featured in yellow: 

sudo nano /etc/php-fpm.d/www.conf

/etc/php-fpm.d/www.conf

...
user = nginx
...
group = nginx

Ensure the/var/lib/php registry has the right proprietorship : 

chown -R root:nginx /var/lib/php

When done, restart the PHP FPM administration: 

sudo systemctl restart php-fpm

Next, alter the Nginx virtual host order, and add the accompanying area block so Nginx can deal with PHP documents: 

server {

    # . . . other code

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

For the new setup to produce results, restart the Nginx administration : 

sudo systemctl restart nginx

Update the SELinux security setting: 

sudo chcon -Rt httpd_sys_rw_content_t /var/www

Conclusion

PHP 7.2 is accessible for establishment from the default CentOS 8 stores. On the off chance that you need to introduce later form you have to empower the Remi vault. 

In the event that you have any inquiries or input, don't stop for a second to leave a remark.




CFG