Linux – Problems installing php5 from source in Ubuntu

apache-2.2installationlinuxPHPUbuntu

(Originally asked here: https://stackoverflow.com/questions/14977119/problems-installing-php5-from-source-in-ubuntu)

I've been trying to install php5 for a while.

I'm using.

Ubuntu 12.10
Apache 2.4.3

And the version of php I want to install is:

PHP 5.4.11

I follow the documentation in the webpage.

I install Apache (after putting the apr and apr-util folders in ./scrlib, just as the documentation says).

sudo ./configure --enable-so
sudo make
sudo make install

All of these commands output a lot of information, but no error nor warning as long as I'm aware.

Just for the record:

/usr/local/apache2/bin/httpd -l
Compiled in modules:
  core.c
  mod_so.c
  http_core.c
  event.c

mod_so.c is there, so I think the installation were alright.

Now, I attempt to install PHP (after putting the

.sudo ./configure \
  --prefix=/home/usr/local/php5/ \
  --with-mysql \
  --with-apxs2=/usr/local/apache2/bin/apxs \
  --with-xsl \
  --with-gdbm \
  --with-gd \
  --with-freetype=/usr/include/freetype2/ \
  --with-zlib-dir=/usr/include \
  --with-ttf \
  --with-jpeg-dir=/usr/lib

Everything goes fine except the following warning:

configure: WARNING: unrecognized options: --with-freetype, --with-ttf

However, those options aren't the greatest of my problems and I follow to the next steps.

sudo make

And these are the lasts lines of the output.

Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
invertedregexiterator.inc
pharcommand.inc
directorytreeiterator.inc
directorygraphiterator.inc
clicommand.inc
phar.inc

Build complete.
Don't forget to run 'make test'.

Next step.

sudo make install

Everything seems fine.

sudo cp php.ini-development /usr/local/lib/php.ini

I edit the conf file (/usr/local/apache2/conf/httpd.conf). The line…

LoadModule php5_module        modules/libphp5.so

…was already there. Just under that line I add:

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>

I restart apache:

sudo service apache2 restart

So, php5 should be already installed. I make the following script in php.

// info.php
<?php
phpinfo();
?>

And saved it in /var/www/info.php

I put the following url in my browser:

http://127.0.0.1/info.php

There's no output.

In the original question, a user asked me to check the error log (in /var/log/apache2/).

If I browse to my info.php file, the only new line added to the error.log is

[Wed Feb 20 19:49:01 2013] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico

Then they asked me to put display_errors = On in php.ini. Nothing was shown on the screen.

Finally they asked me to run php -i in the terminal. The output was the following:

The program 'php' is currently not installed. You can install it by typing: sudo apt-get install php5-cli

What am I missing? The reason that I don't use apt-get install php5 is because I want all the options I've put in the config file. The first thing that gave me problems was that I did not have the gdbm handler for databases. If you know a way in which I can use apt-get install php5 and then somehow add this new option to php5, then I also consider it a solution.

Best Answer

I see two issues here, but I suspect you have more than whats visible from what you posted.

The reason why on your terminal you get the message that php is not installed, is because the php binary is not in your default search path.

according to your --configure your php is in /home/usr/local/php5 (which i personally feel is a weird location). Now if you just enter php on the CLI, bash will not check in this directory for the php executable, so you have to run it with the whole path. it should be something like /home/usr/local/php5/bin/php i think.

If you want to make it available by default with just entering php, do this first ln -s /home/usr/local/php5/bin/php /bin/php. then Bash should be able to find it by itself if you just enter php.

The other problem is that you are using to configure parameters which simply don't exist. You can see the available configure parameters by doing ./configure --help in the source directory of php.

I forgot one: for verifying if the php module was loaded in apache or not, you can use apache's mod_info. It tells you which modules were loaded successfully. If you see in the mod_info output that the PHP module wasn't loaded, then you should probably check apaches output on startup. http://httpd.apache.org/docs/2.0/mod/mod_info.html