4

ppa:ondrej/php5-oldstable does not support PHP 5.4 for Ubuntu 13.10 and higher. There seems to be no official or a stable way to install PHP 5.4 instead of 5.5 on Ubuntu 14.04 LTS currently. I've seen most answers on StackOverflow/Exchange but in the end, they are mostly all outdated.

How can I install PHP 5.4 on Ubuntu 14.04 LTS directly from a repository?

Francis Kim
  • 261
  • 1
  • 2
  • 8

3 Answers3

12

Install requirements for phpbrew

apt-get update
apt-get upgrade
apt-get build-dep php5
apt-get install -y php5 php5-dev php-pear autoconf automake curl build-essential libxslt1-dev re2c libxml2 libxml2-dev php5-cli bison libbz2-dev libreadline-dev
apt-get install -y libfreetype6 libfreetype6-dev libpng12-0 libpng12-dev libjpeg-dev libjpeg8-dev libjpeg8  libgd-dev libgd3 libxpm4 libltdl7 libltdl-dev
apt-get install -y libssl-dev openssl
apt-get install -y gettext libgettextpo-dev libgettextpo0
apt-get install -y php5-cli
apt-get install -y libmcrypt-dev
apt-get install libicu-dev

Install phpbrew

curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew
chmod +x phpbrew
sudo mv phpbrew /usr/bin/phpbrew

Initialise phpbrew, update and install PHP 5.4

phpbrew init
phpbrew known --update
phpbrew update

Here we choose PHP 5.4.34, but you can change this to any version that is available as listed by the above commands - like 5.5.22.

phpbrew install 5.4.34 +default

Update your shell config file by adding the following to the end of your ~/.bashrc or ~/.zshrc (basically the shell you're using, default to .bashrc)

source ~/.phpbrew/bashrc

Close your terminal to take effect, and restart it.

Switch the default PHP version to 5.4

phpbrew switch php-5.4.34

If it shows Invalid Argument, try phpbrew switch 5.4.34 instead.

Check your PHP version

php -v
Vadorequest
  • 117
  • 1
  • 1
  • 7
Francis Kim
  • 261
  • 1
  • 2
  • 8
  • 1
    You should run the install command as phpbrew install -j N 5.4.34 +default where N is the max number of CPU cores for compiling. That way your hugely wide multi-core system is put to more use and finishes faster. – jbo5112 Mar 07 '15 at 21:29
  • I completed everything as root (even restarting apache2 and php5-fpm services), but my web server still reports that it's running php 5.5. What am I missing? – jbo5112 Mar 07 '15 at 21:36
  • @jbo5112 phpbrew switch php-5.4.34 should do the trick if the previous steps were ok. – Francis Kim Mar 09 '15 at 23:38
  • 1
    I've run phpbrew switch php-5.4.38 (current version I compiled), restarted apache2 and php5-fpm, and checked the output of phpinfo() in my web server. Just running php -v works fine, but the web server still says "PHP Version 5.5.9-1ubuntu4.6". I assume I still have to update some system config file for php5-fpm. – jbo5112 Mar 10 '15 at 04:09
  • For using php fpm, I needed to shut down the system php5-fpm service php5-fpm stop and then run phpbrew fpm start. – jbo5112 Mar 25 '15 at 04:53
  • for me one thing was missing here:
    apt-get install libicu-dev
    
    

    I got an error when trying to install a php version and the log said:

    configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.

    – IARI Jul 14 '15 at 12:08
  • Had to also install libreadline-dev and libmcrypt-dev – Fluffy Dec 25 '15 at 08:12
  • 2
    Also had to add source ~/.phpbrew/bashrc to the end of ~/.bashrc, otherwise it would not switch – Fluffy Dec 25 '15 at 08:22
  • You rock but getting error if I try to install php-5.5.0 (404 Not Found) because php-5.5.0.tar.gz not found in www.php.net/get/....; Any solution ? – Nullpointer Apr 13 '16 at 13:32
0

If it shows Invalid Argument, try over and over again nothing, the only thing that help is these two line and in this order:

source ~/.phpbrew/bashrc && phpbrew list
phpbrew switch 5.4.45
Mark Kirby
  • 18,529
  • 19
  • 78
  • 114
zvika
  • 1
  • Welcome to Ask Ubuntu! Your answer may be a bit late as the OP already accepted the other answer. Your help is of course appreciated, however you might be better served by focusing your efforts on the unanswered questions – Wayne_Yux Dec 14 '15 at 15:52
0

Make sure phpbrew is located in:

/usr/local/bin

not

/usr/bin
techraf
  • 3,316
  • Welcome to Ask Ubuntu! ;-) you can edit existing answers to improve them. 2 reviewers will review your edits and approve if deemed useful! (I would!) ;-) – Fabby Apr 14 '16 at 09:39