I still use CentOS as my distro of choice on any new server and whilst things are getting better CentOS and RHEL still don’t have up to date versions of PHP available inside the default yum repos. A couple of years ago I posted about Howto install PHP Mcrypt on CentOS using EPEL which is one of my sites most popular posts!
So CentOS and PHP, as you can see below (taken from DistroWatch) CentOS is a bit outdated with it’s PHP versions which as a PHP developer can be a pain in the ass!
PHP Current Version | CentOS 7.0-1406 | CentOS 6.6 |
---|---|---|
5.6.4 | 5.4.16 | 5.3.3 |
However there is yet again hope! This time we need 2 additional repos. First up we need EPEL and secondly we need Remi a French guy who is king of PHP repos!
Repo Installation
Open up a SSH connection to your server and run the following commands (make sure you run as sudo if you need to):
For CentOS 7 (including EPEL install)
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm rpm -Uvh remi-release-7*.rpm epel-release-7*.rpm
If you already have EPEL installed:
wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm rpm -Uvh remi-release-7*.rpm
For CentOS 6 (including EPEL install)
wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm rpm -Uvh remi-release-6*.rpm epel-release-6*.rpm
If you already have EPEL installed:
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm rpm -Uvh remi-release-6*.rpm
Enabling the Repo
Now we need to make sure the repo is enabled and select which version you want to install. We need to head over to /etc/yum.repos.d
you should inside see a file called remi.repo
.
Open the file in your favourite editor (Nano, Pico, Vi etc), you’ll see a number of sections. We need to make sure that the first section [remi]
is enabled:
[remi] name=Les RPM de remi pour Enterprise Linux 6 - $basearch #baseurl=http://rpms.famillecollet.com/enterprise/6/remi/$basearch/ mirrorlist=http://rpms.famillecollet.com/enterprise/6/remi/mirror enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Note the line enabled=1
make sure this is set! Now technically you can actually go ahead and install PHP, but you will only get PHP 5.4.*. Which might be want to you want is so skip ahead to the next section!
If we want PHP 5.5 or PHP 5.6 we need to do a bit more work, further down in the repo.repo
file you will see two additional sections [remi-php55]
and [remi-php56]
, decide which PHP version you want to install and then enable the correct. So for PHP 5.6 we would change to:
[remi-php56] name=Les RPM de remi de PHP 5.6 pour Enterprise Linux 6 - $basearch #baseurl=http://rpms.famillecollet.com/enterprise/6/php56/$basearch/ mirrorlist=http://rpms.famillecollet.com/enterprise/6/php56/mirror # WARNING: If you enable this repository, you must also enable "remi" enabled=1 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
Once you made your changes save your modified file and quit your editor.
Installing PHP
Now I’m assuming you don’t already have PHP installed, this bit is super simple.
sudo yum install php php-gd php-mysql php-mcrypt
So the above assumes you want MySQL, GD and Mcrypt support in your PHP, but you should see something like the below depending on which version of PHP you are trying to install:
================================================================================================================================ Package Arch Version Repository Size ================================================================================================================================ Installing: php x86_64 5.5.20-2.el6.remi remi-php55 2.6 M php-gd x86_64 5.5.20-2.el6.remi remi-php55 72 k php-mysqlnd x86_64 5.5.20-2.el6.remi remi-php55 3.6 M Installing for dependencies: php-cli x86_64 5.5.20-2.el6.remi remi-php55 3.7 M php-common x86_64 5.5.20-2.el6.remi remi-php55 1.0 M php-pdo x86_64 5.5.20-2.el6.remi remi-php55 112 k php-pear noarch 1:1.9.5-3.el6.remi remi 375 k php-pecl-jsonc x86_64 1.3.6-1.el6.remi.5.5.1 remi-php55 47 k php-pecl-zip x86_64 1.12.4-1.el6.remi.5.5 remi-php55 269 k php-process x86_64 5.5.20-2.el6.remi remi-php55 57 k php-xml x86_64 5.5.20-2.el6.remi remi-php55 208 k Transaction Summary ================================================================================================================================ Install 11 Package(s)
As you can see PHP is installing version 5.5.20-2.el6.remi from the remi-php55 repo! Once you have hit Y to confirm the install restart apache and magical unicorns you have a better version of PHP!
You can also change your mind in the future by going back into the remi.repo
file and enable a different PHP version and then run yum update
and if you have moved from 5.5 to 5.6 it will upgrade PHP for you. If you want to downgrade for any reason you will need to remove PHP (sudo yum remove php*
) and then reinstall the PHP modules you want.
Hope this helps!
I’m facing this issue in installation..
Loaded plugins: product-id, refresh-packagekit, rhnplugin, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
There was an error communicating with RHN.
RHN Satellite or RHN Classic support will be disabled.
Error communicating with server. The message was:
Temporary failure in name resolution
Could not retrieve mirrorlist http://cdn.remirepo.net/enterprise/6/php56/mirror error was
14: PYCURL ERROR 6 – “Couldn’t resolve host ‘cdn.remirepo.net'”
Error: Cannot retrieve repository metadata (repomd.xml) for repository: remi-php56. Please verify its path and try again
DOES NOT WORK
updates | 3.4 kB 00:00
No package php available.
No package php-gd available.
No package php-mysql available.
No package php-mcrypt available.
Error: Nothing to do
root@tra [/usr/local/src]#
Hi Jeff, thanks for your comment. As you may have noticed, this post is 3 years old. As such it may no longer be applicable.
Thanks so much! It’s so great, everyone should check version at: http://dl.fedoraproject.org/pub/epel/7/x86_64/e/{pel-release-}{version} before using EPEL.
Now I see current version is epel-release-7-10.noarch.rpm
thanks for document , i have using php 5.6 with apache 2.4 , i need to install mysqli extension , i have done with below commands
$ cd extname
$ phpize
$ ./configure
$ make
# make install# its seem installed correctly
and also i have added path in php.ini , but still its not install mysqli , php -i | grep mysqli is geven mysqli with details, plz help me to do correctly .
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
This fails on Centos7_64
Is there a new location?
Connecting to dl.fedoraproject.org (dl.fedoraproject.org)|209.132.181.23|:80… connected.
HTTP request sent, awaiting response… 404 Not Found
2017-03-17 09:31:12 ERROR 404: Not Found.
Change it to: epel-release-7-9.noarch.rpm
paste this url http://dl.fedoraproject.org/pub/epel/7/x86_64/e/
to your browers, and Ctrl+f ,input the file name “epel-release”to find the correct rpm
Very Usefull
Thank you
Do you think REMI or the Webtatic REPO provide better PHP rpms?
my system in centos 6.7 installed and I want update php5.3.3 to 5.4 or above but not update how to solve my problem
i wold like to upgrade php 5.5 to 5.6 or 7 shold i remove first the 5.5 version before install?
Wonderful and useful tutorial. This also worked well on Oracle Linux UEK 6 x64. I was able to get PHP 5.6 installed and working immediately.
Thanks for the great post. I used your post to upgrade to php 5.4 on a CentOS 6 system. Unfortunately it broke my installation of mod_suphp. It doesn’t even seem to be using suphp anymore. If I change the file permissions on my index.php to 777 it works and shows the user as “apache”. If I change the permissions to 711 (as they should be for suphp) I get an error that the file can’t be read due to permission errors.
Any ideas how I can get suphp running again?
You may need to reinstall suphp as it perhaps isn’t referenced in the php.ini?? I’ve not used suphp personally, try reinstalling.
Dude. THANK YOU!!!!
How can you install opcache using your guide?
Thanks a lot!!! Great Article
Thanks for your blog I manage to install php, php-mysql and php-mcrypt but i failed in php-gd there is an error message.
[root@localhost ~]# yum install php-gd
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Resolving Dependencies
–> Running transaction check
—> Package php-gd.x86_64 0:5.6.17-1.el7.remi will be installed
–> Processing Dependency: gd-last(x86-64) >= 2.1.1 for package: php-gd-5.6.17-1.el7.remi.x86_64
–> Processing Dependency: libt1.so.5()(64bit) for package: php-gd-5.6.17-1.el7.remi.x86_64
–> Processing Dependency: libgd.so.3()(64bit) for package: php-gd-5.6.17-1.el7.remi.x86_64
–> Running transaction check
—> Package gd-last.x86_64 0:2.1.1-2.el7.remi will be installed
—> Package php-gd.x86_64 0:5.6.17-1.el7.remi will be installed
–> Processing Dependency: libt1.so.5()(64bit) for package: php-gd-5.6.17-1.el7.remi.x86_64
–> Finished Dependency Resolution
Error: Package: php-gd-5.6.17-1.el7.remi.x86_64 (remi-php56)
Requires: libt1.so.5()(64bit)
You could try using –skip-broken to work around the problem
You could try running: rpm -Va –nofiles –nodigest
[root@localhost ~]#
Firstly it looks like you’re using RHEL not CentOS which I haven’t tested these instructions against. However the error is
Requires: libt1.so.5()(64bit)
I would start there as you look to be missing that as a dependency.Worked like a treat! Thanks heaps! 😀
Thanks for this guide. However I get stuck at the last bit:
[root@hosted-by yum.repos.d]# sudo yum install php php-gd php-mysql php-mcrypt
Loaded plugins: fastestmirror
Setting up Install Process
Loading mirror speeds from cached hostfile
* base: centos.mirror.transip.nl
* epel: mirror.nl.leaseweb.net
* extras: centos.mirror.transip.nl
* remi: rpms.remirepo.net
* remi-php56: rpms.remirepo.net
* remi-safe: rpms.remirepo.net
* updates: centos.mirror.transip.nl
* webtatic: uk.repo.webtatic.com
remi | 2.9 kB 00:00
remi-php56 | 2.9 kB 00:00
No package php available.
No package php-gd available.
No package php-mysql available.
No package php-mcrypt available.
Error: Nothing to do
Thanks for the post, I did it.
Hi, thanks for the article!
Unfortunately i can’t update, because once i type the last command (sudo yum install or sudo yum update) i get the following error:
Could you please help me fix it?
Thanks 🙂
It looks like Roundcube is the problem here it’s got some dependencies that can’t be fixed using newer versions of PHP. I would make sure you update your Roundcube installation first. Remove the repo added in this article, Update Roundcube and then try the steps again to get PHP up to date. Might be worth heading over to the Roundcube site to see if anyone else has had issues with PHP5.4+
Thanks for your Reply! I updated Roundcube, but i am getting the same exact error 🙁
Any other hints? I’m getting crazy 🙁
Thanks ! Amazing
This was really helpful. I’m pretty sure this information doesn’t exist in one place like this anywhere else on the Internet!
I did have one issue, which confuses me. All the installs went just as described on my CENTOS 7 Vagrant image as localhost. However after I started apache and add a basic `phpinfo` file in the DocumentRoot, the php code isn’t parsed and the contents (source) of the php file are just outputted to my user agent.
Interestingly when I installed php 5.4 using:
`sudu yum install php`
…I did NOT have this problem. (however my app requires 5.6)
On the command line I see php is installed:
{{{
[vagrant@localhost ~]$ php -v
PHP 5.6.12 (cli) (built: Aug 6 2015 17:06:46)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2015 Zend Technologies
[vagrant@localhost ~]$
}}}
Did you make sure you restarted Apache after installing?
Great Solution
Thanks for this, saved me a whole heap of pain!
Thanks, this was exactly what I was looking for. Might add I had to run mysql_upgrade after “yum update”.
On Centos 6.6 at least in my case usign Plesk 12 better not use the yum install php it will causes the plesk entire crash, that happened to me and I had to reinstall my VPS. The solution worked for me was install repos as you explain and then make a “yum update” this will update your php 5.3.x version to 5.4.x,
Cheers.
Yeah if you already have PHP installed you can simply enable the repos and update to get the latest version or the one you specify.
Excellent et ça fonctionne !!!