Setting up your local development environment – PHP

Setting up your local development environment – PHP

Last time we went through steps needed for setting up apache. Now we will set up PHP. I encourage you to read the article on multiple PHP versions, which takes use of PHPFarm that makes things a lot easier. Plus you get to have multiple PHP versions installed.

Download and prepare

First few steps are practically the same as for the apache. Download the source and check md5.

$ md5sum php-5.4.8.tar.gz | grep 'b25b735f342efbfdcdaf00b83189f183'

Extract the archive.

$ tar xzf php-5.4.8.tar.gz

Go into the extracted directory.

$ cd php-5.4.8

Configure for compiling

$ ./configure \
--prefix=/usr/local/php5.4.8 \
--with-apxs2=/usr/local/apache2.2.22/bin/apxs \
--with-config-file-path=/usr/local/php5.4.8/conf \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-cli \
--with-pear \
--with-openssl \
--with-iconv \
--with-curl \
--enable-intl \
--enable-mbstring \
--enable-exif \
--with-zlib \
--with-gd \
--with-gettext \
--enable-gd-native-ttf \
--with-mhash \
--with-pspell \
--with-mcrypt \
--enable-bcmath \
--enable-sockets \
--enable-soap \
--enable-calendar \
--with-png-dir=/usr \
--with-jpeg-dir=/usr

You don’t need all of these extras, they just might be useful to you. Some of the more important ones are:

  • –prefix=… sets the location of the PHP installation.
  • –with-apxs2=… sets the location of the apxs binary of the apache. Adjust accordingly.
  • –with-config-file-path=… sets the location of the php.ini configuration file. I just set it so it is more clear where the .ini file will be.
  • –enable-cli whether or not you want to use php from the command line.

You can read more about the configuration options in the PHP manual.

On Ubuntu 11.04, the configuration might fail with error messages about libjpeg and/or libpng. What you can do is the following:

# apt-get install libjpeg8-dev

Install the libjpeg8-dev package. This will solve the libjpeg error message.

# ln -s /usr/lib/x86_64-linux-gnu/libpng.so /usr/lib/libpng.so

Create a symbolic link to the libpng.so in the /usr/lib directory. This will solve the libpng error message.

Compile

$ make

If this error occures while doing “make”:

/usr/bin/ld: cannot find -lltdl collect2: ld returned 1 exit  status

Just install the libltdl-dev package. Should be something similar for other linux distributions.

# apt-get install libltdl-dev

It is a good practice to run tests and report any possible bugs by running this command. It however is not mandatory to do it.

$ make test

This might take a while. After tests are through, there might be a fail or two, so you can decide if you want to report those or not.

Let’s go on and install it. This command must be run as super user.

# make install

Configure

Now we have to copy the php.ini to the appropriate directory.

# cp php.ini-recommended /usr/local/php5.4.8/conf/php.ini

Next, we configure apache to handle our PHP scripts.

# gedit /usr/local/apache2.2.22/conf/httpd.conf

Find a line which starts with AddType and add this below.

AddType application/x-httpd-php .php

Than in line which starts with DirectoryIndex add this.

index.php

Save the file and restart apache.

# /usr/local/apache2.2.22/bin/apachectl -k restart

Test

Go to your documents root directory. In previous tutorial we used /var/www directory for this.

In this directory create a file named test.php and put this in it:

Now go to http://localhost/test.php

If you see a lot of data about your PHP installation, you have succeeded.

Enjoy!

Post updated on November 12th, 2012 to reflect newest updates.

3 Responses so far.

  1. thinkt4nk says:

    By the way, I recently found this article based on the -lltdl error, and while I wasn’t able to install libtdl-dev on CentOS with that package name, I was able to hunt down the correct yum package. If you’re working on a yum system, you can just as easily download the lib with the following command.

    yum install libtool-ltdl-devel

  2. hippyjim says:

    Any help on this anywhere? I’m behind a proxy and Google only wants to give me phpfarm’s licence for any search I do for phpfarm behind a proxy.

  3. […] PHPFarm – How to run multiple versions of PHP on the same computer Multiple PHP versions with Apach2, FastCGI, PHPFarm on Ubuntu Setting up your local development environment PHP […]