How to Install PHP 7 on CentOS 7 (Red Hat/Fedora family)
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.
#PHP 7.0.1 released, RPMs already available in #remirepo 4 #fedora #rhel & #centos via…
ADVANCE WARNING: RedHat intends to transition theRHEL/Fedorafamily from the popular package?manageryumto its next iteration,DNF(dnf), short fordandified yum. It supportsRPM,libsolv, andhawkeylibraries. DNF (which inherited some qualities from both yum and aptitude) has been released forFedorawithuser and admin guidesalready up to date, so feel free to get acquainted with it. Use it the way you would work with yum.Iforwhenthis change may?impactCentOSorAmazon Linuxisn’t clear yet.?You can enable DNF in Fedora 18 and later, then install the binary using good old-fashioned yum; for other distributions you have tocompile DNF from source.
To get your hands on a working installation of PHP 7, you can use either the old yum or dnf (when in doubt, consult thecommand 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 withsudoto 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=remioption 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
or
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[1]: 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 this post: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.
來(lái)源:https://www.cloudinsidr.com/content/how-to-install-php-7-on-centos-7-red-hat-rhel-7-fedora/