Today we are going to learn about PHP Compilation for Ubuntu. I installed Ubuntu 14.04 and PHP 5.5 came pre-installed with the system but my problem was that I had to make use of ZendOptimizer which supports PHP upto 5.4 only therefore I decided to go manually compile PHP 5.4 and install over Ubuntu.
Step 1 : Install fresh copy of Ubuntu 14.04
Step 2: sudo apt-get update
Step 3: sudo apt-get install build-essential
Step 4: sudo apt-get install openssl libssl-dev openssl-blacklist openssl-blacklist-extra bison autoconf automake libtool re2c flex apache-prefork-dev
Step 4a. sudo apt-get install libxml2-dev libssl-dev libbz2-dev libcurl3-dev libdb5.1-dev libjpeg-dev libpng-dev libXpm-dev libfreetype6-dev libt1-dev libgmp3-dev libc-client-dev libldap2-dev libmcrypt-dev libmhash-dev freetds-dev libz-dev libmysqlclient15-dev ncurses-dev libpcre3-dev unixODBC-dev postgresql-server-dev-9.1 libsqlite-dev libaspell-dev libreadline6-dev librecode-dev libsnmp-dev libtidy-dev libxslt-dev libt1-dev
Step 5: wget http://in1.php.net/distributions/php-5.4.28.tar.bz2
For Step 5 you can use any mirror location for getting the PHP source files which is near to your location.
Step 6: ./configure –with-config-file-path=/etc/php5/apache2 \
–with-pear=/usr/share/php \
–with-bz2 \
–with-curl \
–with-gd \
–enable-calendar \
–enable-mbstring \
–enable-bcmath \
–enable-sockets \
–with-libxml-dir=/usr \
–with-mysqli \
–with-mysql \
–with-openssl\
–with-regex=php \
–with-zlib \
–with-apxs2
Step 7: make
Step 8 make install
Now PHP 5.4.28+ is installed over the server
Note: In order to compile PHP 5.4.28+ on your ubuntu server you will also require to download and build apache2 webserver right from the source instead of using the one supplied by the Ubuntu distribution. This will automatically install apxs2 and will help in the compilation of the PHP. I will be soon posting on method over how to build and install apache2 over Ubuntu
I have Ubuntu 14.04 as well with a LEMP Stack. Running Magento and MySQL. I have downloaded the php-5.4.29.tar.bz2 and extracted it, but do not know what else to configure.
Also what about the php 5.5.9 that comes pre-installed? dont we need to remove that?
Hello Nasir,
Yes you need to uninstall PHP 5.5.9, you can use Synaptics Package Manager to do that easily.
Once you have uninstalled you can compile as I have described in the post
Yes you need to remove pre-installed PHP
I dont have a GUI to access Synaptics Manager, only root access through ssh. Anyhow, there are multiple php5-fpm, php5-common, etc… Should i remove all of the php 5? Also how do i avoid it updating the PHP version?
Yes you should remove all php5-*
If you don’t install php via apt you don’t need to worry about update as ubuntu doesn’t update it
For removing php5.5.* you can use next command:
sudo apt-get remove –purge `dpkg -l | grep php | grep -w 5.5 | awk ‘{print $2}’ | xargs`
I did as per your instruction I got this after the make install
root@ip:/opt/php-5.3.28# make install
Installing PHP SAPI module: cgi
Installing PHP CGI binary: /usr/local/bin/
Installing PHP CLI binary: /usr/local/bin/
Installing PHP CLI man page: /usr/local/man/man1/
Installing build environment: /usr/local/lib/php/build/
Installing header files: /usr/local/include/php/
Installing helper programs: /usr/local/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/lib/php/
[PEAR] Archive_Tar – already installed: 1.3.11
[PEAR] Console_Getopt – already installed: 1.3.1
[PEAR] PEAR – already installed: 1.9.4
Wrote PEAR system config file at: /usr/local/etc/pear.conf
You may want to add: /usr/local/lib/php to your php.ini include_path
[PEAR] Structures_Graph- already installed: 1.0.4
[PEAR] XML_Util – already installed: 1.2.1
/opt/php-5.3.28/build/shtool install -c ext/phar/phar.phar /usr/local/bin
ln -s -f /usr/local/bin/phar.phar /usr/local/bin/phar
Installing PDO headers: /usr/local/include/php/ext/pdo
Thats when I check php -v it show
-su: /usr/bin/php: No such file or directory
How to fix it.
Thanks for the tutorial !
In step 4 – I had to change ‘apache-prefork-dev’ to ‘apache2-prefork-dev’
Using the original version I got an error: unable to locate package apache-prefork-dev
# here’s my copy, configures cleanly
# Compiling & Installing PHP for Ubuntu 14.04
# Install fresh copy of Ubuntu 14.04
# sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install openssl libssl-dev openssl-blacklist openssl-blacklist-extra bison autoconf automake libtool re2c flex apache-prefork-dev
sudo apt-get install libxml2-dev libssl-dev libbz2-dev libcurl3-dev libdb5.1-dev libjpeg-dev libpng-dev libXpm-dev libfreetype6-dev libt1-dev libgmp3-dev libc-client-dev libldap2-dev libmcrypt-dev libmhash-dev freetds-dev libz-dev libmysqlclient15-dev ncurses-dev libpcre3-dev unixODBC-dev postgresql-server-dev-9.1 libsqlite-dev libaspell-dev libreadline6-dev librecode-dev libsnmp-dev libtidy-dev libxslt-dev libt1-dev
wget http://in1.php.net/distributions/php-5.4.28.tar.bz2
./configure -with-config-file-path=/etc/php5/apache2 \
-with-pear=/usr/share/php \
-with-bz2 \
-with-curl \
-with-gd \
-enable-calendar \
-enable-mbstring \
-enable-bcmath \
-enable-sockets \
-with-libxml-dir=/usr \
-with-mysqli \
-with-mysql \
-with-openssl \
-with-regex=php \
-with-zlib \
-with-apxs2
make
make install
Great article! Needed it to place an old project on a new server. works perfectly
This article has been very useful ! Thanks a lot.