This is an article where the main focus is about how to install PHP in Linux CentOS 8. The installation process exist in a virtual server with Linux CentOS 8 exist as in its operating system. This article is taking a reference from another reference with the title of ‘How to Install PHP on CentOS 8’ in this link. This article actually perform the installation in a virtual server running in a VirtualBox Application. Access the server directly or remotely. Read the article in this link with the title of ‘How to Remote CentOS Virtual Server running in a VirtualBox with a NAT Network using SSH’ to remote the virtual server using SSH method. The following are the steps for installing PHP in it :
1. First of all, install remi repository for Linux CentOS 8. This repository is important for adding a repository containing the suitable PHP package for further installation. In order to install the repository, just execute the command as follows :
[root@10 html]# sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm Last metadata expiration check: 2:35:31 ago on Wed 10 Mar 2021 03:07:40 AM EST. remi-release-8.rpm 36 kB/s | 25 kB 00:00 Dependencies resolved. ============================================================================================================================================================================ Package Architecture Version Repository Size ============================================================================================================================================================================Installing: remi-release noarch 8.3-1.el8.remi @commandline 25 k yum-utils noarch 4.0.17-5.el8 BaseOS 68 k Upgrading: centos-gpg-keys noarch 1:8-2.el8 BaseOS 12 k dnf noarch 4.2.23-4.el8 BaseOS 513 k dnf-data noarch 4.2.23-4.el8 BaseOS 149 k dnf-plugins-core noarch 4.0.17-5.el8 BaseOS 66 k libdnf x86_64 0.48.0-5.el8 BaseOS 650 k librepo x86_64 1.12.0-2.el8 BaseOS 90 k python3-dnf noarch 4.2.23-4.el8 BaseOS 526 k python3-dnf-plugins-core noarch 4.0.17-5.el8 BaseOS 221 k python3-hawkey x86_64 0.48.0-5.el8 BaseOS 111 k python3-libdnf x86_64 0.48.0-5.el8 BaseOS 756 k yum noarch 4.2.23-4.el8 BaseOS 192 k Installing group/module packages: centos-linux-release noarch 8.3-1.2011.el8 BaseOS 22 k replacing centos-release.x86_64 8.2-2.2004.0.1.el8 replacing centos-repos.x86_64 8.2-2.2004.0.1.el8 Installing dependencies: centos-linux-repos noarch 8-2.el8 BaseOS 20 k libmodulemd x86_64 2.9.4-2.el8 BaseOS 189 k unbound-libs x86_64 1.7.3-14.el8 AppStream 500 k Installing weak dependencies: python3-unbound x86_64 1.7.3-14.el8 AppStream 118 k Transaction Summary ============================================================================================================================================================================Install 7 Packages Upgrade 11 Packages Total size: 4.1 M Total download size: 4.1 M Is this ok [y/N]: y Downloading Packages: (1/17): python3-unbound-1.7.3-14.el8.x86_64.rpm 937 kB/s | 118 kB 00:00 (2/17): unbound-libs-1.7.3-14.el8.x86_64.rpm 1.1 MB/s | 500 kB 00:00 (3/17): centos-linux-release-8.3-1.2011.el8.noarch.rpm 24 kB/s | 22 kB 00:00 (4/17): centos-linux-repos-8-2.el8.noarch.rpm 26 kB/s | 20 kB 00:00 (5/17): centos-gpg-keys-8-2.el8.noarch.rpm 265 kB/s | 12 kB 00:00 (6/17): libmodulemd-2.9.4-2.el8.x86_64.rpm 356 kB/s | 189 kB 00:00 (7/17): yum-utils-4.0.17-5.el8.noarch.rpm 571 kB/s | 68 kB 00:00 (8/17): dnf-plugins-core-4.0.17-5.el8.noarch.rpm 261 kB/s | 66 kB 00:00 (9/17): dnf-data-4.2.23-4.el8.noarch.rpm 205 kB/s | 149 kB 00:00 (10/17): librepo-1.12.0-2.el8.x86_64.rpm 266 kB/s | 90 kB 00:00 (11/17): dnf-4.2.23-4.el8.noarch.rpm 373 kB/s | 513 kB 00:01 (12/17): python3-dnf-plugins-core-4.0.17-5.el8.noarch.rpm 345 kB/s | 221 kB 00:00 (13/17): python3-dnf-4.2.23-4.el8.noarch.rpm 545 kB/s | 526 kB 00:00 (14/17): python3-hawkey-0.48.0-5.el8.x86_64.rpm 412 kB/s | 111 kB 00:00 (15/17): libdnf-0.48.0-5.el8.x86_64.rpm 314 kB/s | 650 kB 00:02 (16/17): yum-4.2.23-4.el8.noarch.rpm 453 kB/s | 192 kB 00:00 (17/17): python3-libdnf-0.48.0-5.el8.x86_64.rpm 735 kB/s | 756 kB 00:01 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 420 kB/s | 4.1 MB 00:10 Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Running scriptlet: libmodulemd-2.9.4-2.el8.x86_64 1/1 Installing : libmodulemd-2.9.4-2.el8.x86_64 1/31 Upgrading : librepo-1.12.0-2.el8.x86_64 2/31 Upgrading : libdnf-0.48.0-5.el8.x86_64 3/31 Upgrading : python3-libdnf-0.48.0-5.el8.x86_64 4/31 Upgrading : python3-hawkey-0.48.0-5.el8.x86_64 5/31 Upgrading : dnf-data-4.2.23-4.el8.noarch 6/31 Upgrading : centos-gpg-keys-1:8-2.el8.noarch 7/31 Installing : centos-linux-repos-8-2.el8.noarch 8/31 Installing : centos-linux-release-8.3-1.2011.el8.noarch 9/31 Running scriptlet: unbound-libs-1.7.3-14.el8.x86_64 10/31 Installing : unbound-libs-1.7.3-14.el8.x86_64 10/31 Running scriptlet: unbound-libs-1.7.3-14.el8.x86_64 10/31 Installing : python3-unbound-1.7.3-14.el8.x86_64 11/31 Upgrading : python3-dnf-4.2.23-4.el8.noarch 12/31 Upgrading : dnf-4.2.23-4.el8.noarch 13/31 Running scriptlet: dnf-4.2.23-4.el8.noarch 13/31 Upgrading : python3-dnf-plugins-core-4.0.17-5.el8.noarch 14/31 Upgrading : dnf-plugins-core-4.0.17-5.el8.noarch 15/31 Installing : yum-utils-4.0.17-5.el8.noarch 16/31 Upgrading : yum-4.2.23-4.el8.noarch 17/31 Installing : remi-release-8.3-1.el8.remi.noarch 18/31 Obsoleting : centos-release-8.2-2.2004.0.1.el8.x86_64 19/31 Obsoleting : centos-repos-8.2-2.2004.0.1.el8.x86_64 20/31 warning: /etc/yum.repos.d/CentOS-PowerTools.repo saved as /etc/yum.repos.d/CentOS-PowerTools.repo.rpmsave Cleanup : yum-4.2.17-6.el8.noarch 21/31 Running scriptlet: dnf-4.2.17-6.el8.noarch 22/31 Cleanup : dnf-4.2.17-6.el8.noarch 22/31 Running scriptlet: dnf-4.2.17-6.el8.noarch 22/31 Cleanup : dnf-plugins-core-4.0.12-3.el8.noarch 23/31 Cleanup : python3-dnf-plugins-core-4.0.12-3.el8.noarch 24/31 Cleanup : python3-dnf-4.2.17-6.el8.noarch 25/31 Cleanup : dnf-data-4.2.17-6.el8.noarch 26/31 Cleanup : centos-gpg-keys-8.2-2.2004.0.1.el8.noarch 27/31 Cleanup : python3-hawkey-0.39.1-5.el8.x86_64 28/31 Cleanup : python3-libdnf-0.39.1-5.el8.x86_64 29/31 Cleanup : libdnf-0.39.1-5.el8.x86_64 30/31 Cleanup : librepo-1.11.0-2.el8.x86_64 31/31 Running scriptlet: librepo-1.11.0-2.el8.x86_64 31/31 Verifying : python3-unbound-1.7.3-14.el8.x86_64 1/31 Verifying : unbound-libs-1.7.3-14.el8.x86_64 2/31 Verifying : centos-linux-release-8.3-1.2011.el8.noarch 3/31 Verifying : centos-release-8.2-2.2004.0.1.el8.x86_64 4/31 Verifying : centos-repos-8.2-2.2004.0.1.el8.x86_64 5/31 Verifying : centos-linux-repos-8-2.el8.noarch 6/31 Verifying : libmodulemd-2.9.4-2.el8.x86_64 7/31 Verifying : yum-utils-4.0.17-5.el8.noarch 8/31 Verifying : remi-release-8.3-1.el8.remi.noarch 9/31 Verifying : centos-gpg-keys-1:8-2.el8.noarch 10/31 Verifying : centos-gpg-keys-8.2-2.2004.0.1.el8.noarch 11/31 Verifying : dnf-4.2.23-4.el8.noarch 12/31 Verifying : dnf-4.2.17-6.el8.noarch 13/31 Verifying : dnf-data-4.2.23-4.el8.noarch 14/31 Verifying : dnf-data-4.2.17-6.el8.noarch 15/31 Verifying : dnf-plugins-core-4.0.17-5.el8.noarch 16/31 Verifying : dnf-plugins-core-4.0.12-3.el8.noarch 17/31 Verifying : libdnf-0.48.0-5.el8.x86_64 18/31 Verifying : libdnf-0.39.1-5.el8.x86_64 19/31 Verifying : librepo-1.12.0-2.el8.x86_64 20/31 Verifying : librepo-1.11.0-2.el8.x86_64 21/31 Verifying : python3-dnf-4.2.23-4.el8.noarch 22/31 Verifying : python3-dnf-4.2.17-6.el8.noarch 23/31 Verifying : python3-dnf-plugins-core-4.0.17-5.el8.noarch 24/31 Verifying : python3-dnf-plugins-core-4.0.12-3.el8.noarch 25/31 Verifying : python3-hawkey-0.48.0-5.el8.x86_64 26/31 Verifying : python3-hawkey-0.39.1-5.el8.x86_64 27/31 Verifying : python3-libdnf-0.48.0-5.el8.x86_64 28/31 Verifying : python3-libdnf-0.39.1-5.el8.x86_64 29/31 Verifying : yum-4.2.23-4.el8.noarch 30/31 Verifying : yum-4.2.17-6.el8.noarch 31/31 Upgraded: centos-gpg-keys-1:8-2.el8.noarch dnf-4.2.23-4.el8.noarch dnf-data-4.2.23-4.el8.noarch dnf-plugins-core-4.0.17-5.el8.noarch libdnf-0.48.0-5.el8.x86_64 librepo-1.12.0-2.el8.x86_64 python3-dnf-4.2.23-4.el8.noarch python3-dnf-plugins-core-4.0.17-5.el8.noarch python3-hawkey-0.48.0-5.el8.x86_64 python3-libdnf-0.48.0-5.el8.x86_64 yum-4.2.23-4.el8.noarch Installed: centos-linux-release-8.3-1.2011.el8.noarch centos-linux-repos-8-2.el8.noarch libmodulemd-2.9.4-2.el8.x86_64 python3-unbound-1.7.3-14.el8.x86_64 remi-release-8.3-1.el8.remi.noarch unbound-libs-1.7.3-14.el8.x86_64 yum-utils-4.0.17-5.el8.noarch Complete! [root@10 html]#
2. After that, the following is the content on how to list the PHP available in the repository exist in the Linux CentOS 8. It exist in the repository installed in the previous step. Just execute the following command :
[root@10 html]# sudo dnf module list php CentOS Linux 8 - AppStream 571 kB/s | 6.3 MB 00:11 CentOS Linux 8 - BaseOS 554 kB/s | 2.3 MB 00:04 Remi's Modular repository for Enterprise Linux 8 - x86_64 272 kB/s | 739 kB 00:02 Safe Remi's RPM repository for Enterprise Linux 8 - x86_64 483 kB/s | 1.7 MB 00:03 Last metadata expiration check: 0:00:02 ago on Wed 10 Mar 2021 05:46:24 AM EST. CentOS Linux 8 - AppStream Name Stream Profiles Summary php 7.2 [d] common [d], devel, minimal PHP scripting language php 7.3 common [d], devel, minimal PHP scripting language php 7.4 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 php remi-8.0 common [d], devel, minimal PHP scripting language Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled [root@10 html]#
3. Next, reset the default installation for PHP version. Actually, according to the information in another article, the PHP installation by default will have a PHP with the version of 7.2. The following is the content is how to list the PHP available in the repository exist in the Linux CentOS 8 by executing the following command :
[root@10 html]# sudo dnf module reset php Last metadata expiration check: 0:07:47 ago on Wed 10 Mar 2021 05:46:24 AM EST. Dependencies resolved. Nothing to do. Complete! [root@10 html]#
4. After that, just change the PHP version into a higher version. Furthermore, in this context, change and enable the PHP 7.4 as in the follwoing command execution :
[root@10 html]# sudo dnf module enable php:remi-7.4 Last metadata expiration check: 0:07:54 ago on Wed 10 Mar 2021 05:46:24 AM EST. Dependencies resolved. ============================================================================================================================================================================================================================================ Package Architecture Version Repository Size ============================================================================================================================================================================================================================================ Enabling module streams: php remi-7.4 Transaction Summary ============================================================================================================================================================================================================================================ Is this ok [y/N]: y Complete! [root@10 html]#
According to the article, changing to another version of PHP is also possible. The version beside PHP 7.4 is PHP 7.3. The above context is actually upgrading into PHP 7.4.
4. Following after, just execute the actual php package and another related package as follows :
[root@10 html]# sudo dnf install php php-opcache php-gd php-curl php-mysqlnd Last metadata expiration check: 0:08:33 ago on Wed 10 Mar 2021 05:46:24 AM EST. Dependencies resolved. ============================================================================================================================================================================================================================================ Package Architecture Version Repository Size ============================================================================================================================================================================================================================================ Installing: php x86_64 7.4.16-1.el8.remi remi-modular 3.0 M php-common x86_64 7.4.16-1.el8.remi remi-modular 1.2 M php-gd x86_64 7.4.16-1.el8.remi remi-modular 93 k php-mysqlnd x86_64 7.4.16-1.el8.remi remi-modular 260 k php-opcache x86_64 7.4.16-1.el8.remi remi-modular 336 k Installing dependencies: gd x86_64 2.2.5-7.el8 appstream 144 k libsodium x86_64 1.0.18-2.el8 epel 162 k libwebp x86_64 1.0.0-1.el8 appstream 273 k libxslt x86_64 1.1.32-5.el8 baseos 250 k oniguruma5php x86_64 6.9.6-1.el8.remi remi-safe 208 k php-json x86_64 7.4.16-1.el8.remi remi-modular 76 k php-pdo x86_64 7.4.16-1.el8.remi remi-modular 143 k Installing weak dependencies: nginx-filesystem noarch 1:1.14.1-9.module_el8.0.0+184+e34fea82 appstream 24 k php-cli x86_64 7.4.16-1.el8.remi remi-modular 4.6 M php-fpm x86_64 7.4.16-1.el8.remi remi-modular 1.6 M php-mbstring x86_64 7.4.16-1.el8.remi remi-modular 528 k php-sodium x86_64 7.4.16-1.el8.remi remi-modular 89 k php-xml x86_64 7.4.16-1.el8.remi remi-modular 215 k Enabling module streams: nginx 1.14 Transaction Summary ============================================================================================================================================================================================================================================ Install 18 Packages Total download size: 13 M Installed size: 55 M Is this ok [y/N]: y Downloading Packages: (1/18): nginx-filesystem-1.14.1-9.module_el8.0.0+184+e34fea82.noarch.rpm 326 kB/s | 24 kB 00:00 (2/18): gd-2.2.5-7.el8.x86_64.rpm 534 kB/s | 144 kB 00:00 (3/18): libwebp-1.0.0-1.el8.x86_64.rpm 811 kB/s | 273 kB 00:00 (4/18): libsodium-1.0.18-2.el8.x86_64.rpm 183 kB/s | 162 kB 00:00 (5/18): libxslt-1.1.32-5.el8.x86_64.rpm 192 kB/s | 250 kB 00:01 (6/18): php-common-7.4.16-1.el8.remi.x86_64.rpm 328 kB/s | 1.2 MB 00:03 (7/18): php-7.4.16-1.el8.remi.x86_64.rpm 368 kB/s | 3.0 MB 00:08 (8/18): php-gd-7.4.16-1.el8.remi.x86_64.rpm 182 kB/s | 93 kB 00:00 (9/18): php-json-7.4.16-1.el8.remi.x86_64.rpm 232 kB/s | 76 kB 00:00 (10/18): php-fpm-7.4.16-1.el8.remi.x86_64.rpm 281 kB/s | 1.6 MB 00:05 (11/18): php-mbstring-7.4.16-1.el8.remi.x86_64.rpm 375 kB/s | 528 kB 00:01 (12/18): php-opcache-7.4.16-1.el8.remi.x86_64.rpm 322 kB/s | 336 kB 00:01 (13/18): php-pdo-7.4.16-1.el8.remi.x86_64.rpm 205 kB/s | 143 kB 00:00 (14/18): php-sodium-7.4.16-1.el8.remi.x86_64.rpm 260 kB/s | 89 kB 00:00 (15/18): php-xml-7.4.16-1.el8.remi.x86_64.rpm 255 kB/s | 215 kB 00:00 (16/18): php-mysqlnd-7.4.16-1.el8.remi.x86_64.rpm 81 kB/s | 260 kB 00:03 (17/18): oniguruma5php-6.9.6-1.el8.remi.x86_64.rpm 253 kB/s | 208 kB 00:00 (18/18): php-cli-7.4.16-1.el8.remi.x86_64.rpm 154 kB/s | 4.6 MB 00:30 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 376 kB/s | 13 MB 00:35 warning: /var/cache/dnf/remi-modular-6408ecca79e22107/packages/php-7.4.16-1.el8.remi.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 5f11735a: NOKEY Remi's Modular repository for Enterprise Linux 8 - x86_64 1.9 MB/s | 3.1 kB 00:00 Importing GPG key 0x5F11735A: Userid : "Remi's RPM repository <[email protected]>" Fingerprint: 6B38 FEA7 231F 87F5 2B9C A9D8 5550 9759 5F11 735A From : /etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el8 Is this ok [y/N]: y Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : php-json-7.4.16-1.el8.remi.x86_64 1/18 Running scriptlet: php-common-7.4.16-1.el8.remi.x86_64 2/18 Installing : php-common-7.4.16-1.el8.remi.x86_64 2/18 Installing : php-pdo-7.4.16-1.el8.remi.x86_64 3/18 Installing : php-cli-7.4.16-1.el8.remi.x86_64 4/18 Installing : php-opcache-7.4.16-1.el8.remi.x86_64 5/18 Installing : oniguruma5php-6.9.6-1.el8.remi.x86_64 6/18 Installing : php-mbstring-7.4.16-1.el8.remi.x86_64 7/18 Installing : libsodium-1.0.18-2.el8.x86_64 8/18 Installing : php-sodium-7.4.16-1.el8.remi.x86_64 9/18 Installing : libxslt-1.1.32-5.el8.x86_64 10/18 Installing : php-xml-7.4.16-1.el8.remi.x86_64 11/18 Running scriptlet: nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch 12/18 Installing : nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch 12/18 Installing : php-fpm-7.4.16-1.el8.remi.x86_64 13/18 Running scriptlet: php-fpm-7.4.16-1.el8.remi.x86_64 13/18 Installing : libwebp-1.0.0-1.el8.x86_64 14/18 Installing : gd-2.2.5-7.el8.x86_64 15/18 Running scriptlet: gd-2.2.5-7.el8.x86_64 15/18 Installing : php-gd-7.4.16-1.el8.remi.x86_64 16/18 Installing : php-7.4.16-1.el8.remi.x86_64 17/18 Installing : php-mysqlnd-7.4.16-1.el8.remi.x86_64 18/18 Running scriptlet: php-mysqlnd-7.4.16-1.el8.remi.x86_64 18/18 Running scriptlet: php-fpm-7.4.16-1.el8.remi.x86_64 18/18 Verifying : gd-2.2.5-7.el8.x86_64 1/18 Verifying : libwebp-1.0.0-1.el8.x86_64 2/18 Verifying : nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch 3/18 Verifying : libxslt-1.1.32-5.el8.x86_64 4/18 Verifying : libsodium-1.0.18-2.el8.x86_64 5/18 Verifying : php-7.4.16-1.el8.remi.x86_64 6/18 Verifying : php-cli-7.4.16-1.el8.remi.x86_64 7/18 Verifying : php-common-7.4.16-1.el8.remi.x86_64 8/18 Verifying : php-fpm-7.4.16-1.el8.remi.x86_64 9/18 Verifying : php-gd-7.4.16-1.el8.remi.x86_64 10/18 Verifying : php-json-7.4.16-1.el8.remi.x86_64 11/18 Verifying : php-mbstring-7.4.16-1.el8.remi.x86_64 12/18 Verifying : php-mysqlnd-7.4.16-1.el8.remi.x86_64 13/18 Verifying : php-opcache-7.4.16-1.el8.remi.x86_64 14/18 Verifying : php-pdo-7.4.16-1.el8.remi.x86_64 15/18 Verifying : php-sodium-7.4.16-1.el8.remi.x86_64 16/18 Verifying : php-xml-7.4.16-1.el8.remi.x86_64 17/18 Verifying : oniguruma5php-6.9.6-1.el8.remi.x86_64 18/18 Installed: gd-2.2.5-7.el8.x86_64 libsodium-1.0.18-2.el8.x86_64 libwebp-1.0.0-1.el8.x86_64 libxslt-1.1.32-5.el8.x86_64 nginx-filesystem-1:1.14.1-9.module_el8.0.0+184+e34fea82.noarch oniguruma5php-6.9.6-1.el8.remi.x86_64 php-7.4.16-1.el8.remi.x86_64 php-cli-7.4.16-1.el8.remi.x86_64 php-common-7.4.16-1.el8.remi.x86_64 php-fpm-7.4.16-1.el8.remi.x86_64 php-gd-7.4.16-1.el8.remi.x86_64 php-json-7.4.16-1.el8.remi.x86_64 php-mbstring-7.4.16-1.el8.remi.x86_64 php-mysqlnd-7.4.16-1.el8.remi.x86_64 php-opcache-7.4.16-1.el8.remi.x86_64 php-pdo-7.4.16-1.el8.remi.x86_64 php-sodium-7.4.16-1.el8.remi.x86_64 php-xml-7.4.16-1.el8.remi.x86_64 Complete! [root@10 html]#
5. And then, enable one of the php module available from the previous installation. Just execute the following command :
[root@10 html]# sudo systemctl enable --now php-fpm Created symlink /etc/systemd/system/multi-user.target.wants/php-fpm.service → /usr/lib/systemd/system/php-fpm.service. [root@10 html]#
6. Finally, restart the Webserver available to implement the change. In this article, the example is using Apache Webserver. Just execute the following command :
[root@10 html]# systemctl restart httpd [root@10 html]#