Installing PHP on Linux

It can be really helpful to have PHP installed on your home computer. Especially if you're still learning. So today I'm going to walk you through how to do so on a PC with linux.

First things first, you're going to need Apache to be installed already.

1. Download Apache from, this will assume you download the latest version as of this publication, which is 2.4.3.

If you use a different one, be sure to change the commands below (since we use the name of the file).

2. Move this to your src folder, at / usr/local/src, and run the following commands, which will un archive the zipped source, in a shell:

cd /usr/local/src
gzip -d httpd-2.4.3.tar.bz2
tar xvf httpd-2.4.3.tar
cd httpd-2.4.3

3. The following command is semi-optional. If you don't mind the default options, which installs it to /usr/local/apache2, you can skip to step 4. If you're interested as to what can be customized, then run this command:

./configure --help

This will give you a list of the options you can change for when it installs.

4. This will install Apache:

./configure --enable-so
make install

Note: if you get an error that says something like this: configure: error: no acceptable C compiler found in $PATH, then you need to install a C compiler. This probably won't happen, but if it does, Google "install gcc on [insert your brand of linux]"

5. Yay! Now you can start up and test Apache:

cd /usr/local/apache2/bin
./apachectl start

Then point your browser to http://local-host and it should tell you "It Works!"

Note: if you changed where Apache installed, you should adjust the above cd command accordingly.

Now that you have Apache installed, you can install and test PHP!

Again, this assumes you're downloading a certain file, which is a certain version of PHP. And again, this is the latest stable release as of writing this. That file is named php-5.4.9.tar.bz2

1. Download php-5.4.9.tar.bz2 from and again place it in your /usr/local/src then run the following commands:

cd /usr/local/src
bzip2 -d php-5.4.9.tar.bz2
tar xvf php-5.4.9.tar
cd php-5.4.9

2. Again, this step is semi-optional as it deals with configuring php before you install it. So, if you want to customize the installation, or see how you can customize it:

./configure --help

3. The next commands actually install PHP, with the default apache install location of /usr/local/apache2:

./configure --with-apxs2=/usr/local/apache2/bin/apxs
make install
cp php.ini-dist /usr/local/lib/php.ini

4. Open the file /usr/local/apache2/conf/httpd.conf and add the following text:

SetHandler application/x-httpd-php

Then while in that file make sure it has a line that says LoadModule php5_module modules/

5. Now you will want to restart apache and verify that php is installed and woking correctly:

/usr/local/bin/apache2/apachectl restart

No make a file called test.php in your /usr/local/apache2/htdocs folder with the following line in it:

phpinfo(); ?>

Now point your favorite internet browser at http://local-host/test.php and it should tell you all about your working php installation.