Setting up your local development environment – PHP

Posted July 3rd, 2010 in Tehnikalije by Metod

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.

  1. $ md5sum php-5.4.8.tar.gz | grep ‘b25b735f342efbfdcdaf00b83189f183’

Extract the archive.

  1. $ tar xzf php-5.4.8.tar.gz

Go into the extracted directory.

  1. $ cd php-5.4.8

Configure for compiling

  1. $ ./configure \
  2. –prefix=/usr/local/php5.4.8 \
  3. –with-apxs2=/usr/local/apache2.2.22/bin/apxs \
  4. –with-config-file-path=/usr/local/php5.4.8/conf \
  5. –with-mysqli=mysqlnd \
  6. –with-pdo-mysql=mysqlnd \
  7. –enable-cli \
  8. –with-pear \
  9. –with-openssl \
  10. –with-iconv \
  11. –with-curl \
  12. –enable-intl \
  13. –enable-mbstring \
  14. –enable-exif \
  15. –with-zlib \
  16. –with-gd \
  17. –with-gettext \
  18. –enable-gd-native-ttf \
  19. –with-mhash \
  20. –with-pspell \
  21. –with-mcrypt \
  22. –enable-bcmath \
  23. –enable-sockets \
  24. –enable-soap \
  25. –enable-calendar \
  26. –with-png-dir=/usr \
  27. –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:

  1. # apt-get install libjpeg8-dev

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

  1. # 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

  1. $ make

If this error occures while doing “make”:

  1. /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.

  1. # 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.

  1. $ 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.

  1. # make install

Configure

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

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

Next, we configure apache to handle our PHP scripts.

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

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

  1. AddType application/x-httpd-php .php

Than in line which starts with DirectoryIndex add this.

  1. index.php

Save the file and restart apache.

  1. # /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:

  1. <?php phpinfo(); ?>

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.

Setting up your local web development environment – Apache

Posted June 25th, 2010 in Tehnikalije by Metod

This is the first on in the series of tutorials on how to set up your local web development environment on linux (I’m using Ubuntu). It is targeting those people, who don’t know their way around linux, but don’t want to use generic packages. It’s more fun. :)

Download and prepare

First, you go to the apache homepage. You download apache, check sha1, because it can get corrupted!

  1. $ sha1sum httpd-2.2.22.tar.gz | grep ‘bf3bbfda967ac900348e697f26fe86b25695efe9’

If a line is returned, the file is OK, we can proceed, else, return to step 1.

Extract the archive.

  1. $ tar xzf httpd-2.2.22.tar.gz

Move into the directory of the extracted archive.

  1. $ cd httpd-2.2.22

Configure for compiling

Next, we have to configure apache, before we compile it.

  1. $ ./configure –prefix=/usr/local/apache2 –enable-so –enable-mods-shared=all –enable-mod-rewrite

  • –prefix=/usr/local/apache2 tells apache where to install all the files needed. In this case we are installing apache to /usr/local/apache2 directory.
  • –enable-mods-shared=all tells apache to compile all modules as dynamic shared modules. We can then enable these modules in httpd.conf file, via the LoadModule directive.
  • –enable-mod-rewrite tells apache to enable mod rewrite.

Troubleshoot

If you get this error during the configuration:

  1. mod_deflate has been requested but can not be built due to prerequisite failures

This happened because we enabled all mods by default, one of which is the mod_deflate that uses the zlib library. You can simply install its headers on ubuntu.

  1. # apt-get install zlib1g-dev

The dependencies should pass.

Compile

  1. $ make

Next one must be executed as super user.

  1. # make install

Test it

Now, apache should be working. Let’s test it.

  1. # /usr/local/apache2/bin/apachectl -k start

Go to: http://localhost

You should see a “It works!” on your screen.

But when we started apache, it threw out an error:

  1. httpd: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName

Configure it

It’s time to configure it, so it won’t throw errors at us. You can use different text editor than gedit (vi, nano, mcedit … )

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

ServerAdmin → change it to your email, just for a clean configuration file.

Uncomment ServerName directive (remove # in front of it) and change www.example.com to localhost. With this, we got rid of that error from before.

DocumentRoot → change to directory in which you want to have your html, php etc. files.

<Directory “/usr/local/apache2/htdocs”> → change if you changed the DocumentRoot in the previous step.

Here we must change the line AllowOverride None to AlloweOverride All if we want mod_rewrite to function properly.

Check if the syntax of the configuration file is OK.

  1. $ /usr/local/apache2/bin/apachectl -t

If everything is OK, restart apache.

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

You’re good to go!

Post updated on February 1st, 2012 to reflect latest apache version.