Thursday, February 06, 2014

How to install PHP5.5.8 on Ubuntu

This tutorial shows you how to configure and install php5.5.8 from source code. There are several ways to install (or upgrade from PHP5.3, PHP5.4 to) PHP5.5.8, either with a compile and configure process, or through various pre-packaged methods. I choose to install PHP5.5.8 because I already have PHP5.3 installed on my current websserver, on my webserver I have apache 2.x, wordpress and other software use PHP5.3. I just don't want to break them. So I choose to install PHP5.5.8 to "/usr/local/php5.5.8", this way no existing package will be affected.

If you are upgrading from PHP5.3 or PHP 5.4, check out this post:
Upgrade from PHP5.3 to PHP 5.5 on Ubuntu 12.04 LTS
Upgrade from PHP5.4 to PHP 5.5 on Ubuntu 12.04 LTS

Download PHP5.5.8 from:
http://php.net/downloads.php (Now it is PHP5.5.9)

Prerequisite knowledge and software for compiling:
  • Basic Unix skills (being able to operate "make" and a C compiler)
  • An ANSI C compiler
  • A web server
  • Any module specific components (such as GD, PDF libs, etc.)
When  building  directly from Git sources or after custom modifications you might also need:
  • autoconf: 2.13+ (for PHP < 5.4.0), 2.59+ (for PHP >= 5.4.0)
  • automake: 1.4+
  • libtool: 1.4.x+ (except 1.4.2)
  • re2c: Version 0.13.4 or newer
  • flex: Version 2.5.4 (for PHP <= 5.2)
  • bison: Version 1.28 (preferred), 1.35, or 1.75
Configure:
The  initial  PHP  setup and configuration process is controlled by the use  of the command line options of the configure script. You could get a  list  of all available options along with short explanations running
# ./configure   --help

You can also do a
# echo "<? phpinfo()?>" | /usr/bin/php
to check enabled modules and configuration switches.
In our example we'll do a simple configure with Apache 2 and MySQL support.

Configure PHP:
# cd /tmp/php-5.5.8
# ./configure --with-apxs2=/usr/bin/apxs2 --with-mysql --prefix=/usr/local/php5.5.8/

If you see this error:
error:
configure: error: xml2-config not found. Please check your libxml2 installation.
This means libxml2-devel is missing, if you try to compile with xml2-config the -devel version of that package is needed.
"apt-get install libxml2-dev" would solve this problem.

run configure again.

If configured successfully, you would see the following message:
creating libtool
appending configuration tag "CXX" to libtool

Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

Install PHP5.5.8:
# pwd
/tmp/php-5.5.8
# make
# make test
# Make sure you don't have failed tests.
Number of tests : 12930              8607
Tests skipped   : 4323 ( 33.4%) --------
Tests warned    :    0 (  0.0%) (  0.0%)
Tests failed    :    0 (  0.0%) (  0.0%)
Expected fail   :   33 (  0.3%) (  0.4%)
Tests passed    : 8574 ( 66.3%) ( 99.6%)
---------------------------------------------------------------------
Time taken      :  193 seconds
=====================================================================

Expected fails are fine.

# make install
Installing shared extensions:     /usr/local/php5.5.8/lib/php/extensions/no-debug-non-zts-20121212/
Installing PHP CLI binary:        /usr/local/php5.5.8/bin/
Installing PHP CLI man page:      /usr/local/php5.5.8/php/man/man1/
Installing PHP CGI binary:        /usr/local/php5.5.8/bin/
Installing PHP CGI man page:      /usr/local/php5.5.8/php/man/man1/
Installing build environment:     /usr/local/php5.5.8/lib/php/build/
Installing header files:          /usr/local/php5.5.8/include/php/
Installing helper programs:       /usr/local/php5.5.8/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php5.5.8/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PEAR environment:      /usr/local/php5.5.8/lib/php/
[PEAR] Archive_Tar    - installed: 1.3.11
[PEAR] Console_Getopt - installed: 1.3.1
warning: pear/PEAR requires package "pear/Structures_Graph" (recommended version 1.0.4)
warning: pear/PEAR requires package "pear/XML_Util" (recommended version 1.2.1)
[PEAR] PEAR           - installed: 1.9.4
Wrote PEAR system config file at: /usr/local/php5.5.8/etc/pear.conf
You may want to add: /usr/local/php5.5.8/lib/php to your php.ini include_path
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XML_Util       - installed: 1.2.1
/tmp/php-5.5.8/build/shtool install -c ext/phar/phar.phar /usr/local/php5.5.8/bin
ln -s -f /usr/local/php5.5.8/bin/phar.phar /usr/local/php5.5.8/bin/phar
Installing PDO headers:          /usr/local/php5.5.8/include/php/ext/pdo/

# ls /usr/local/php5.5.8/
bin  etc  include  lib  php

Setup your php.ini:
# vi /etc/php5/apache2/php.ini
add
/usr/local/php5.5.8/lib/php
into "include_path":
Uncomments:
; UNIX: "/path1:/path2"
;include_path = ".:/usr/share/php"
to
include_path = ".:/usr/local/php5.5.8/lib/php"

Edit httpd.conf to load the PHP module:
LoadModule php5_module modules/libphp5.so

Restart Apache server:
# service apache2 restart

No comments: