Every once in a while I need to install Apache http server on my pc or laptop to use as local test server. I also need to install Perl, PHP and mysql to have the complete environment to test scripts and applications before uploading them on a live server.
Ricocheting.com has a great tutorial for installing Apache, PHP and Perl on a Windows server. Last time I had to do a re-install on my PC, I followed their tutorial.
A few impressions and comments:
1) They recommend staying with the default installation of Apache and changing "DocumentRoot" later. I change the installation location to "C:\Apache" which defaults DocumentRoot to C:\Apache\htdocs. It is much better to do it this way. You will not need to modify the configuration file to set DocumentRoot. You will not need to dig into all the way to C:\Program Files\Apache\... to look at log files or configuration files either.
2) I loved their tip about where to install ActiveState Perl: "C:\usr". I used to install Perl to C:\Perl directory which forced me to change the shebang lines on scripts. Listen to this:
If you will be using Perl CGI programs and want to maintain some level of portability between both Linux machines and Windows machines, you will want to install Perl to the same location on your Windows machine that it is on most Linux machines.
For example, on a standard Linux machine, Perl is located at /usr/bin/perl and so every Perl program that I write begins with #!/usr/bin/perl. So, when I install Perl on a Windows machine, instead of installing it in the default location (which is E:\perl for ActivePerl) I install it in E:\usr so that the Perl executable is located at /usr/bin/perl. This allows me to write code on my Windows machine, then move it (without making any changes) to a Linux machine and have it run there. And vice versa.
Wow! I wish I had figured this out earlier... "#!/usr/bin/perl" works in windows if you install Perl in C:\usr directory. No, you do not need to have "C:\" on the shebang line. This will save a lot of time and headache.
3) The site also includes the lines required to be added in Apache configuration file to make CGI and PHP work. I will put a copy of these here:
To activate CGI:
Edit the Apache httpd.conf Configuration File and search for Options Indexes FollowSymLinks (about line 190) when you find it add ExecCGI to the end so it looks like
Options Indexes FollowSymLinks ExecCGI
To use CGI outside the cgi-bin directory, uncomment:
#AddHandler cgi-script .cgi
Also add .pl behind .cgi so 'perl' extension is also treated as cgi files.
To use PHP at the very end of the httpd.conf file add the following lines:
LoadModule php5_module "C:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/php"
Also Open php.ini in a text editor and scroll down about halfway through the file and look for doc_root then change it to point to whatever your Apache DocumentRoot is set to. In my case: doc_root = "C:\Apache\htdocs"
To get Apache to automatically look for an index.php, and index.pl search httpd.conf for DirectoryIndex (about line 212) and add the files you want Apache to look for when a directory is loaded (if it doesn't find any of these files, it displays folder contents). Mine looks like:
DirectoryIndex index.php index.pl index.html
They also have information on installing MySQL which is pretty straightforward.
There is one thing I would like to add here though: If you want to use DBD-MySQL package with Perl , you will notice that it is not included in the latest ActiveStatePerl distribution. You can't even install it using the GUI ppm. Here is what you need to do:
At the Command Prompt type:
ppm install http://theoryx5.uwinnipeg.ca/ppms/DBI-mysql.ppd
UPDATE on Jan 9, 2009 >>>
If you use ActiveState Perl 5.10, above link will not work either. The easiest way to do this is to start your Perl Package Manager, click on Edit -> Preferences and click on the Repositories tab. Type "http://cpan.uwinnipeg.ca/PPMPackages/10xx/" in Location. You just installed the Repository that has the DBD-MySQL package which will enable you to install it using your Perl ppm.
It sure will be nice to have all this info ready when I need to install Apache, Perl, PHP and MySQL on Windows next time.
Sphere: Related Content