First things first, you're going to need Apache to be installed already.
1. Download Apache from http://httpd.apache.org/download.cgi, 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:
gzip -d httpd-2.4.3.tar.bz2
tar xvf httpd-2.4.3.tar
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:
This will give you a list of the options you can change for when it installs.
4. This will install Apache:
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:
Then pointing 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 www.php.net/downloads.php and again place it in your /usr/local/src then run the following commands:
bzip2 -d php-5.4.9.tar.bz2
tar xvf php-5.4.9.tar
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:
3. The next commands actually install PHP, with the default apache install location of /usr/local/apache2:
cp php.ini-dist /usr/local/lib/php.ini
4. Open the file /usr/local/apache2/conf/httpd.conf and add the following text:
Then while in that file make sure it has a line that says LoadModule php5_module modules/libphp5.so
5. Now you will want to restart apache and verify that php is installed and woking correctly:
No make a file called test.php in your /usr/local/apache2/htdocs folder with the following line in it:
<?php phpinfo(); ?>
Now point your favorite internet browser at http://local-host/test.php and it should tell you all about your working php installation.