Step by Step Install PHP 7 on latest Centos 7 VPS


Limited Time Promo, Get Free $20 credit from Vultr, click the banner to get it.

This title taken from my friend question who want to teach him about install latest php version (current version is 7.0.12) but also need to do it in simple copy and paste way ūüôā

I use Vultr $20 instance that will become a server for my friend (he is ios programmer that need lamp server for his project).

Lets get start!

Check available memory

free -m

total        used        free      shared  buff/cache   available
Mem:           1839          89        1331          16         418        1599

Create Swap

Create 4GB swap because the vps instance use 2GB memory : (in general swap space is twice of memory)

fallocate -l 4G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile

Make permanent swap

echo ‘/swapfile¬†¬† swap¬†¬†¬† swap¬†¬†¬† sw¬† 0¬†¬† 0’ >> /etc/fstab

Swappiness and Cache Pressure

echo ‘vm.swappiness = 10’ >> /etc/sysctl.conf
echo ‘vm.vfs_cache_pressure = 50’ >> /etc/sysctl.conf

Setup PHP 7

By default Centos 7 use PHP 5.4 and to change its into PHP 7 you’ll need repository that provide or support PHP 7. I use ius.io repository.

rpm -Uvh https://centos7.iuscommunity.org/ius-release.rpm
yum update

To see available PHP 7 extension just use this command :

yum list | grep php70

mod_php70u.x86_64                        7.0.12-1.ius.centos7           ius
php70u-bcmath.x86_64                     7.0.12-1.ius.centos7           ius
php70u-cli.x86_64                        7.0.12-1.ius.centos7           ius
php70u-common.x86_64                     7.0.12-1.ius.centos7           ius
php70u-dba.x86_64                        7.0.12-1.ius.centos7           ius
php70u-dbg.x86_64                        7.0.12-1.ius.centos7           ius
php70u-debuginfo.x86_64                  7.0.12-1.ius.centos7           ius
php70u-devel.x86_64                      7.0.12-1.ius.centos7           ius
php70u-embedded.x86_64                   7.0.12-1.ius.centos7           ius
php70u-enchant.x86_64                    7.0.12-1.ius.centos7           ius
php70u-fpm.x86_64                        7.0.12-1.ius.centos7           ius
php70u-fpm-httpd.noarch                  7.0.12-1.ius.centos7           ius
php70u-fpm-nginx.noarch                  7.0.12-1.ius.centos7           ius
php70u-gd.x86_64                         7.0.12-1.ius.centos7           ius
php70u-gmp.x86_64                        7.0.12-1.ius.centos7           ius
php70u-imap.x86_64                       7.0.12-1.ius.centos7           ius
php70u-interbase.x86_64                  7.0.12-1.ius.centos7           ius
php70u-intl.x86_64                       7.0.12-1.ius.centos7           ius
php70u-json.x86_64                       7.0.12-1.ius.centos7           ius
php70u-ldap.x86_64                       7.0.12-1.ius.centos7           ius
php70u-mbstring.x86_64                   7.0.12-1.ius.centos7           ius
php70u-mcrypt.x86_64                     7.0.12-1.ius.centos7           ius
php70u-mysqlnd.x86_64                    7.0.12-1.ius.centos7           ius
php70u-odbc.x86_64                       7.0.12-1.ius.centos7           ius
php70u-opcache.x86_64                    7.0.12-1.ius.centos7           ius
php70u-pdo.x86_64                        7.0.12-1.ius.centos7           ius
php70u-pdo-dblib.x86_64                  7.0.12-1.ius.centos7           ius
php70u-pear.noarch                       1:1.10.1-2.ius.centos7         ius
php70u-pecl-amqp.x86_64                  1.7.1-1.ius.centos7            ius
php70u-pecl-amqp-debuginfo.x86_64        1.7.1-1.ius.centos7            ius
php70u-pecl-apcu.x86_64                  5.1.6-1.ius.centos7            ius
php70u-pecl-apcu-debuginfo.x86_64        5.1.6-1.ius.centos7            ius
php70u-pecl-apcu-devel.x86_64            5.1.6-1.ius.centos7            ius
php70u-pecl-apcu-panel.noarch            5.1.6-1.ius.centos7            ius
php70u-pecl-imagick.x86_64               3.4.1-2.ius.centos7            ius
php70u-pecl-imagick-debuginfo.x86_64     3.4.1-2.ius.centos7            ius
php70u-pecl-redis.x86_64                 3.0.0-2.ius.centos7            ius
php70u-pecl-redis-debuginfo.x86_64       3.0.0-2.ius.centos7            ius
php70u-pecl-smbclient.x86_64             0.8.0-1.ius.centos7            ius
php70u-pecl-smbclient-debuginfo.x86_64   0.8.0-1.ius.centos7            ius
php70u-pecl-xdebug.x86_64                2.4.1-1.ius.centos7            ius
php70u-pecl-xdebug-debuginfo.x86_64      2.4.1-1.ius.centos7            ius
php70u-pgsql.x86_64                      7.0.12-1.ius.centos7           ius
php70u-process.x86_64                    7.0.12-1.ius.centos7           ius
php70u-pspell.x86_64                     7.0.12-1.ius.centos7           ius
php70u-recode.x86_64                     7.0.12-1.ius.centos7           ius
php70u-snmp.x86_64                       7.0.12-1.ius.centos7           ius
php70u-soap.x86_64                       7.0.12-1.ius.centos7           ius
php70u-tidy.x86_64                       7.0.12-1.ius.centos7           ius
php70u-xml.x86_64                        7.0.12-1.ius.centos7           ius
php70u-xmlrpc.x86_64                     7.0.12-1.ius.centos7           ius
uwsgi-plugin-php70u.x86_64               2.0.14-1.ius.centos7           ius
uwsgi-plugin-php70u-debuginfo.x86_64     2.0.14-1.ius.centos7           ius

I choose standard lamp extension plus a few program (mariadb database and lynx text browser)

yum install php70u-mysqlnd mod_php70u php70u-cli php70u-mcrypt php70u-gd php70u-opcache mariadb-server php70u-json lynx

Enable all services

systemctl enable httpd
systemctl enable mariadb

Check  PHP version

php -v

PHP 7.0.12 (cli) (built: Oct 14 2016 09:23:01) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.12, Copyright (c) 1999-2016, by Zend Technologies

Restart server

reboot

p.s : if you get blocked then you need to check your firewall

To open port 80

firewall-cmd –get-active-zones
firewall-cmd –zone=public –add-port=80/tcp –permanent
firewall-cmd –reload
firewall-cmd –zone=public –list-all

 


Limited Time Promo, Get Free $20 credit from Vultr, click the banner to get it.