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?

  • possible duplicate of Downgrade PHP Version from 5.5 to 5.4 on Ubuntu 14.04 – Panther Nov 16 '14 at 6:11
  • @bodhi.zazen It is not. The answer refers to howtoforge.com/… which is based on Ubuntu 12.04 plus, it is instructions to DOWNGRADE to Apache+fcgid+php5.4 - I do not have anything installed yet and do not need fcgid. – Francis Kim Nov 16 '14 at 6:17
  • @bodhi.zazen I also ran into issues following that answer you pointed out. – Francis Kim Nov 16 '14 at 6:20
  • What "issues"? and the question is " Downgrade PHP Version from 5.5 to 5.4 on Ubuntu 14.04" so it applies to 14.04 – Panther Nov 16 '14 at 7:07
  • @bodhi.zazen it ended up installing PHP 5.3 - and I do not need to 'Downgrade' as there is no PHP installed to start off with. – Francis Kim Nov 16 '14 at 7:08
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
  • 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 7 '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 7 '15 at 21:36
  • @jbo5112 phpbrew switch php-5.4.34 should do the trick if the previous steps were ok. – Francis Kim Mar 9 '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 4:09
  • 2
    Also had to add source ~/.phpbrew/bashrc to the end of ~/.bashrc, otherwise it would not switch – Fluffy Dec 25 '15 at 8:22
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
  • 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
  • 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 9:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.