3

As most of us ubuntu users know, 12.04 comes with it's own version of Perl and PHP (5.3.10).

Recently I compiled apache 2.2.22 and PHP 5.4.5 from source, and when I open a terminal to php -v, it shows 5.4.5.

However in phpinfo() it shows the preinstalled 5.3.10 which means apache2 is using that version. Do I have to remove 5.3.10? Or configure apache2 so that it uses php 5.4.5?

If I'm supposed to configure it, please do tell me how, and what to sudo nano. BTW it is only for learning HTML/CSS/PHP, and I'm on Ubuntu 12.04 Desktop.

devav2
  • 36,312
  • 1
    If you are only learning php, there is no need to compile php from source. Just install apache2, and libapache2-mod-php5 – Nemo Sep 10 '12 at 19:18
  • 1
    I am aware of that, but still I want to know how am I supposed to make apache2 use php 5.4.5, so that I can learn with that updated version. Besides, learning more on setting up a server is a plus :) – Tracy Iquiña Sep 14 '12 at 16:55
  • If it's only for learning, you'll have more than enough material to focus on when using 5.3. Otherwise, head here: http://askubuntu.com/questions/109404/how-do-i-install-php-5-4-0 – Mateng Nov 19 '12 at 21:41

1 Answers1

1

It's not a good practice to upgrade Ubuntu packages manually, it's recommended to wait for the upgrade of the specific package that comes natively with the Ubuntu upgrades.

However, if you must use this approach, here's a walkthrough on how to upgrade your PHP to v5.4.x via PPA: http://www.zimbio.com/Ubuntu+Linux/articles/D_AsJR2qAL6/How+Upgrade+PHP+5+4+Ubuntu

Since you have reported "php -v" and phpinfo() version discrepancy, "php -v" gives you the version of the cli installation of php, while phpinfo() will give you the version which got installed as Apache module.

If you are not using cli php anywhere, you should be fine with running php scripts off Apache. But ideally you should fix this. I think the issue is this that your Apache and libapache2-php5-mod have been installed via ubuntu packages while you have compiled php from source. When you installed libapache2-php5-mod via apt-get install, it would have taken the relevant php package from the repo as a dependency, as seen in packages.ubuntu.com/hardy/libapache2-mod-php5 You will need to uninstall Apache, and then install apache from source instead of using the ubuntu repos to do what you wish to do.

I recommend you not to install PHP from source, but to use the PPA approach from above.

Mateo
  • 8,104
madjoe
  • 714
  • Sorry for the really late reply. I've solved this problem by purging the default apache2 and php, manually uninstalling the compiled php (thanks to whereis command), and compiling both apache2and php from source with the required dependencies. I had to copy the development version of php.ini from somewhere in the source files for it to work. To make the process more manageable, I used checkinstall instead of make install. By the way, thanks for helping. – Tracy Iquiña Jan 29 '13 at 05:43