Installing PHP on the Red Hat family—Fedora, RHEL, CentOS 7—is a must for cyber security and it’s not rocket science. With a few easy steps, you too can bring your PHP based web applications to the next level.
PHP 7 brings such profound improvements that the lucky 7 as a version number seems more than justified. The upgrade is easy, painless, and takes just a couple of quick steps. Here is how to do it.
[tweet “#PHP 7.0.1 released, RPMs already available in #remirepo 4 #fedora #rhel & #centos via @cloudinsidr thnx @RemiCollet”]
RedHat has completed the transition of RHEL/Fedora from yum to its next iteration, DNF (dnf), short for dandified yum. It supports RPM, libsolv, and hawkey libraries. DNF (which inherited some qualities from both yum and aptitude) has been released for Fedora with user and admin guides. Use it the way you would work with yum.
To get your hands on a working installation of PHP 7, you can currently use either the old yum or dnf (here is the command reference).
In Remi’s RPM repository, PHP RPMs have been renamed php70 in order to allow installation alongside the default PHP of your CentOS/RHEL/Fedora (if there is one on your system). The FPM service (php70-php-fpm) listens on the default port 9000 so it may need adjusting should another version of PHP be already running.
Follow these steps to install PHP 7 on CentOS with php-fpm, the server API or SAPI of choice for NGINX, using the Remi repository, on x86_64. You must be root (sudo su , otherwise prepend the relevant commands with sudo to execute them as root).
Step 1. Get yourself the REMI repo
Install the Remi repository (#remirepo for #fedora, #rhel and #centos) with these commands (you must be root, see the paragraph above):
wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm sudo rpm -Uvh remi-release-7*.rpm
Step 2. Install PHP 7
Install PHP 7 from the remi repository:
yum --enablerepo=remi-php70 install php70-php
Step 3. Install PHP extensions
Install PHP modules using the remi repository (the example is a recommended configuration):
yum --enablerepo=remi-php70 install php70-php-pear php70-php-bcmath php70-php-pecl-jsond-devel php70-php-mysqlnd php70-php-gd php70-php-common php70-php-fpm php70-php-intl php70-php-cli php70-php php70-php-xml php70-php-opcache php70-php-pecl-apcu php70-php-pecl-jsond php70-php-pdo php70-php-gmp php70-php-process php70-php-pecl-imagick php70-php-devel php70-php-mbstring php70-php-mcrypt
To find out which other extensions are available, use search with yum:
yum search php70
Speaking of extensions: ereg, mssql, sybase_ct and mysql have been removed from PHP.
In order to enable the remi repository only during software installation (that is: only when you need it), use the –enablerepo=remi option with yum. For example like this:
sudo yum --enablerepo=remi install php-tcpdf
To update your already installed packages using the Remi repository, you would enter this command:
yum --enablerepo=remi update remi-release
Step 4. Start PHP
To start PHP (once) use this command:
service php70-php-fpm start
systemctl start php70-php-fpm
Step 5. Enable automatic launch of PHP 7 on system startup
Enable automatic launch of the PHP interpreter on system startup on CentOS 7/Red Hat/Fedora, use this command:
systemctl enable php70-php-fpm
The output of this command should resemble this line:
ln -s '/usr/lib/systemd/system/php70-php-fpm.service' '/etc/systemd/system/multi-user.target.wants/php70-php-fpm.service'
You can verify the current status of PHP 7 using this command:
systemctl status php70-php-fpm [root@ip-16-0-0-170 centos]# systemctl status php70-php-fpm php70-php-fpm.service - The PHP FastCGI Process Manager Loaded: loaded (/usr/lib/systemd/system/php70-php-fpm.service; enabled) Active: active (running) since Thu 2015-12-10 05:29:25 UTC; 2s ago Main PID: 2102 (php-fpm) Status: "Ready to handle connections" CGroup: /system.slice/php70-php-fpm.service ├─2102 php-fpm: master process (/etc/opt/remi/php70/php-fpm.conf) ├─2103 php-fpm: pool www ├─2104 php-fpm: pool www ├─2105 php-fpm: pool www ├─2106 php-fpm: pool www └─2107 php-fpm: pool www Dec 10 05:29:25 ip-12-3-4-170.ec2.internal systemd: Started The PHP FastCGI Process Manager.
This output also shows you that php-fpm pools, while running, have not been configured yet.
If you also want to set up MySQL/MariaDB, you may want to read: High-Stakes, High-Security LEMP Setup: Nginx with MariaDB/MySQL, and PHP 7.x on CentOS 7 (RHEL/Fedora) with SELinux
Subscribe to our newsletter and we will keep you up to date.
- How to fix PHP sessions to ensure security
- How to check your current PHP configuration settings without exposing your server.
Here is what you can do now: why don’t you visit the Amazon wishlist of @RemiCollet and say Thank you: http://amzn.to/1MjuS2N for compiling PHP for you! The Donations page is here: http://rpms.remirepo.net/