Centos 8
------
PHP on CentOS 8 / RHEL 8
dnf install epel-release -y
dnf module install -y httpd
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm -y
dnf module list php
dnf -y install dnf-plugins-core
PHP 7.3
sudo dnf module reset phpsudo dnf module enable php:remi-7.3
PHP 7.4
sudo dnf module reset phpsudo dnf module enable php:remi-7.4
Enable latest PHP Module Stream (remi-7.4)
dnf -y module enable php:remi-7.4
OR
dnf module install php:remi-7.4
following dnf command to install PHP 7.4,
dnf install php php-cli php-common php-opcache php-gd php-curl php-mysqlnd -y
dnf -y install php php-mysql php-xml pcre php-common php-mbstring php-pear curl unzip --> Rainloop
dnf install php-ldap php-imagick php-common php-gd php-imap php-json php-curl php-zip php-xml php-mbstring php-bz2 php-intl php-gmp --> Roundcube
# sudo yum install php-xxx
php -v
systemctl start php-fpm
systemctl enable php-fpm
-------------------------------------------
# vi /etc/php.ini
…………
846 upload_max_filesize = 32M
694 post_max_size = 48M
409 memory_limit = 256M
388 max_execution_time = 600
405 max_input_vars = 3000
398 max_input_time = 1000
923 date.timezone = Asia/Dhaka
………
systemctl enable --now php-fpm
dnf module install -y httpd
systemctl enable --now php-fpm httpd
systemctl restart httpd
ERROR
The operation would result in switching of module 'php' stream '7.2' to stream 'remi-7.4'
Error: It is not possible to switch enabled streams of a module.
It is recommended to remove all installed content from the module, and reset the module using 'dnf module reset <module_name>' command. After you reset the module, you can install the other stream.
# dnf module reset php
yum module list php
Sample outputs:
Last metadata expiration check: 0:00:05 ago on Mon Dec 16 13:28:05 2019. CentOS-8 - AppStream Name Stream Profiles Summary php 7.2 [d] 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
Enable default version
The default PHP version locked to PHP 7.2. It would be best if you ran enable command to set the desired PHP version. In other words, to enable PHP version 7.4, run:
sudo yum module list php
sudo yum module reset php
sudo yum module enable php:remi-7.4
## verify it php set to 7.4 ##
sudo yum module list php
Configuring PHP to work with Apache
If SELinux is running on your system, you’ll need to update the SELinux security context:
chcon -tR httpd_sys_rw_content_t /var/www
If you are using Apache as your web server, restart the httpd service using the following command, and you are good to go:
systemctl restart httpd
Configuring PHP to work with Nginx
By default, PHP FPM runs as user apache. To avoid permission issues, we’ll change the user to nginx. To do so, edit the lines highlighted in yellow:
nano /etc/php-fpm.d/www.conf
/etc/php-fpm.d/www.conf
...
...
user = nginx
group = nginx
Copy
Make sure the /var/lib/php directory has the correct ownership:
chown -R root:nginx /var/lib/php
Once done, restart the PHP FPM service:
systemctl restart php-fpm
Next, edit the Nginx virtual host directive, and add the following location block so that Nginx can process PHP files:
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;
}
}
Copy
For the new configuration to take effect, restart the Nginx service:
systemctl restart nginx
Update the SELinux security context:
chcon -tR httpd_sys_rw_content_t /var/www
dnf -y update
sudo dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
sudo yum -y install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
dnf module list | grep php
dnf -y install dnf-plugins-core
dnf config-manager --set-enabled remi-php73
dnf config-manager --set-enabled remi
dnf module install php:remi-7.3
dnf update
# php -v
systemctl enable --now php-fpm
dnf module install -y httpd
systemctl enable --now php-fpm httpd
For PHP version 7.3, execute:
sudo yum module list php
sudo yum module reset php
sudo yum module enable php:remi-7.3
## verify it php set to 7.3 ##
sudo yum module list php
# vi /etc/php.ini
memory_limit = 512M; upload_max_filesize = 50M; post_max_size = 80M;
date.timezone = Asia/Dhaka
-------