Tutorial: Apache 2.0.49 and PHP 4.3.7!
DISCLAIMER: I'm already aware that there are pages on how to install Apache and PHP together, both static binary and dynamic shared-module, but I haven't seen one here so I figured I'd put one out for those looking to get into PHP and web-serving.
What this covers
How to install both Apache 2.0.49 and PHP 4.3.7 with optional database configurations.
What operating system you will need
You will need to be running a linux distribution of sorts (Redhat, Slackware, Debian ... just to name a few). Anything up-to-date will suffice just fine and it doesn't matter that you probably will only be serving to yourself since this is a tutorial for one to learn.
What do you mean, serving?
When you have a service like a web server, an ftp server, a telnet server (ick ick), an ssh daemon, etc...you will need to be able to reach the outside world (internet). Most common ports are 21 for FTP, 22 for SSH, 23 for telnet, 25 for SMTP, and 80 for a web server. Chances are, one's ISP will not allow such serving from the router level however there are certain ways around that that I won't divulge here. For now, being able to see your own web page from your own intranet (not to be confused with internet), you'll be on your way to learn more about serving out.
What if I already run apache?
That's great because then you already have an idea of web serving, however, there are steps that have to be taken if you're trying to actually serve out dynamic pages that are based off of PHP. We'll get to that later though.
Ok, what software do I need to get?
For now, all you need is Apache 2.0.49 (we're going to work with the Apache 2.0.x release, not 1.3.x) and PHP 4.3.7 (the last major relase of PHP 4).
You'll have to either use sudo or log in as root (sudo su -, enter password) to do the following.
The above will install Apache 2.0.49 with the enable-so variable set to enabled into the default directory /usr/local/apache2.
$ /home/kellert > su -
root's password entered
# /root >tar zxvf httpd-2.0.49.tar.gz
# /root >cd httpd-2.0.49
# /root/httpd-2.0.49 >./configure --enable-so
... configuration goes along here ...
# /root/httpd-2.0.49 >make
# /root/httpd-2.0.49 >make install
Continuing on, now for the installation of PHP.
The above will install PHP 4.3.7 and will be set to run under Apache, using Apache 2's apxs. If you are using a database such as PostgreSQL or mySQL, you would add the option '--with-pgsql' or '--with-mysql' but that's much later on if you're just starting now. With PHP installed into /usr/local/lib/php, you now have the entire package including all of the PEAR structures.
# /root/httpd-2.0.49 >cd ..
# /root >cd php-4.3.7
# /root/php-4.3.7 >./configure --with-apxs2=/usr/local/apache2/bin/apxs
... configuration goes along here ...
# /root/php-4.3.7 >make
# /root/php-4.3.7 >make install
# /root/php-4.3.7 >[b]cp php.ini-dis /usr/local/lib/php.ini
At this time, you now have Apache 2.0.49 and PHP 4.3.7 installed. Now all you have to do is muck with the httpd.conf configuration file and crank her up!
At this point, your httpd.conf should be set up. If you have already changed your httpd.conf because of previous installations, etc, then you will only have to do the above otherwise if you're looking for cgi, virtual hosts, etc, that's a whole other tutorial, hehe.
# /root/php-4.3.7 >cd /usr/local/apache2/conf
# /usr/local/apache2/conf >vi httpd.conf
# LoadModule foo_module module/mod_foo.so
LoadModule php4_module modules/libphp4.so
Enter wherever you want:
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
All should be good and you should only have to do the following:
If it's correct, you'll get nothing and be returned to the command line, otherwise it'll tell you where the errors are.
# /usr/local/apache2/conf >../bin/apachectl start
To test your new php skillz!
# /usr/local/apache2/conf >cd ../htdocs
# /usr/local/apache2/htdocs >vi index.php
In the above file, index.php, put the following:
If you're successful, you'll be able to see the PHP information page which will display a veritable plethora of information about PHP, how it was configured, the coloring scheme, etc etc and etc.
At this point, you're ready for some tutorials and some easy programs. I recommend the following sites for php knowledge.
www.php.net - has everything you need including tutorials and function lookups, etc.
www.phpfreaks.com - another very good site with forums for everything from installation to advanced work to code snippets to people seeking work, etc.
I hope this tutorial is helpful and while I'm not very adept at writing them, I did want everyone who's looking for dynamic page content to be able to learn like I did. It's a very easy step to take once you're comfortable with apache and php to get into database management and from there, your journey into real dynamic content has just begun.
And just a shameless plug for my favorite database: long live PostgreSQL! Hee hee...
EDIT: if there's anyone else that can offer advice to those learning PHP and Apache, I'd appreciate the input!