The scenario: quickly setup either a home web server, or a little home intranet, or both, on Windows XP.
Software:
Apache
MySQL
PHP
phpMyAdmin
Joomla
The following is my recommended way to install these programs. The order does matter. Apache should be installed before PHP.
Apache 2.2
Download Apache 2.2
Download and install Apache from http://httpd.apache.org/download.cgi. Look for the “Win32 Binary (MSI Installer)” version.
The file will be something like apache_2.2.4-win32-x86-no_ssl.msi You could even install an earlier version if you want to. Many people still prefer to use 1.3 versions.
Install Apache
To install simply double click the msi file:
You can install it where you like, such as in a “Server” directory. Somewhere special or more convenient is probably better than putting it in “Program Files” with everything else. So, for example, my Apache will go to C:\Server\Apache2
You’ll be prompted to fill out some basic “Server Information.” You can easily change it later. Now, since your just going to be installing for a local network, you can name it anything you want to. It can even be just a single word.
Network Domain: myplace.net
Server Name: myplace.net
Admin Email: your email address
On the next setup message, check the box for All Users, on Port 80, as a Service
After installing, Apache2 will be reading to go.
Start Apache
Look for the icon in the System Tray. Right click on that to start Apache or else bring up the “Monitor Apache Servers” and start using that. The little icon should turn green when it has started.
If you get “The requested operation has failed!” error while starting Apache, use the “Test Configuration” shortcut in the Start Menu to find the error. You’ll see any error in a command terminal. Often people get that when that tinker with the httpd.conf file.
Test Apache
You have at least 3 or more ways to test. Open a browser and type in: http://127.0.0.1/ or http://localhost/
You can even try http://your_computer_name/ or http://your_computer_ip_address_on_network/ (I’ll cover the fifth way–using the domain name or myplace.net you invented–below.)
If your browser shows “It works!” everything is fine.
Configure Apache
The file that loads and says “It works!” is located in the C:\Server\Apache2\htdocs directory. That directory is the default for all of your web pages. However, you can select another location. To do this, just open C:\Server\Apache2\conf\httpd.conf with a text editor. What you need to change is DocumentRoot. Once you have done that, find the <Directory “C:\Server\Apache2\htdocs”> reference and change that to the same location as DocumentRoot.
To get apache to automatically look for an index.php, search httpd.conf for DirectoryIndex and add the files you want apache to look for when a directory is loaded.
<IfModule dir_module>
DirectoryIndex index.php index.html default.html main.php
</IfModule>
There is more to do with the httpd.conf file, but that will do for now. Restart apache for the changes to take effect. Always remember to restart Apache after you edit httpd.conf or you will have a frustrating and perhaps confusing time trying to get things to work.
MySQL 5
Download MySQL 5
You can download and install MySQL from http://www.mysql.org/downloads/mysql/5.0.html Just make sure you get a Windows Essentials (x86) binary version.
The file will be something like mysql-essential-5.0.41-win32.msi You could even install an earlier version if you want to. Although I’m not sure how that will affect PHP. MySQL 5 seems fine to me.
Install MySQL
To install simply double click the msi file.
As with Apache, you can install it where you like, such as in a “Server” directory. For convenience, I put mine in the same directory where Apache is located. So, for example, my MySQL will go to C:\Server\MySQL.
You’ll be prompted to choose a few settings. If you want to change the directory choose the Custom Setup. The rest are as follows:
- Skip Sign-Up
- Select “Configure the MySQL Server now”
- Select “Detailed Configuration”
- Select “Server Machine”
- Select “Multifunctional Database”
- Select “InnoDB Tablespace Settings” – leave everything default
- Select “Decision Support (DSS)/OLAP”
- Make sure “Enable TCP/IP Networking” is checked and leave the port number at 3306
- Select “Multilingual” (if you think you need it)
- Select “Install As Windows Service”
- Enter your root password and leave “Enable root access from remote machines” unchecked
- Select “Execute” and installation will be complete.
Test MySQL
This step can be done after installing PHP. We’ll download phpMyAdmin and use that for a quick test.
PHP 5
Download PHP 5
Download and install PHP from http://www.php.net/downloads.php. Grab the newest 5.x.x Windows Binary zip package.
The file will be something like php-5.2.3-Win32.zip.
Install PHP
To install simply unzip the file, then copy the \php directory to where you like, such as in a “Server” directory. For convenience, I put mine in the same directory where Apache and MySQL are located. So, for example, my PHP will go to C:\Server\PHP
Rename e:\php\php.ini-dist to php.ini
Configure PHP
Open php.ini with a text editor and search for doc_root. Change the pathing of that to point to your Apache DocumentRoot dircectory. Now search a little further down for the extension_dir. Change the pathing to the \ext directory in your \php directory, i.e. C:\Server\PHP\ext. Next, search for ;extension=php_mysql.dll and remove the ; in front of that line.
That’s all I’ve needed to do with php.ini.
Configure Apache for PHP
There are a number of ways to run PHP in Apache. Some people install it as a module, but I’ve had problems with that. Instead I use the following method, which, like the module install, is described in the PHP install.txt file.
I installed it as a CGI binary by inserting these three lines into Apache’s httpd.conf. I put each of these lines where other ScriptAlias, AddType and Actions are to keep things consistent.
ScriptAlias /php/ “c:/php/”
AddType application/x-httpd-php .php
Action application/x-httpd-php “/php/php-cgi.exe”
Warning
By using the CGI setup, your server is open to several possible attacks. Please read our CGI security section to learn how to defend yourself from those attacks.
If that warning is of concern to you, then perhaps install PHP as a module. However, if you just going to run a local network, or you going to put other checks in place, don’t worry about it.
At this point, we might as well sort out CGI as well. If it isn’t there already in <IfModule alias_module> (where you should have put ScriptAlias /php/ “c:/php/”), put this:
ScriptAlias /cgi-bin/ “C:/Server/Apache/cgi-bin/”
Now look for this section in httpd.conf and add a PHP Directory instruction, like this:
-
- “C:/Server/Apache/cgi-bin” should be changed to whatever your ScriptAliased
- CGI directory exists, if you have that configured.
-
<Directory “C:/Server/Apache/cgi-bin”>
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
<Directory “C:/Server/php/”>
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
Restart Apache to see if you get any errors.
Test PHP
You could load phpMyAdmin now, but for a quick test first, open a new text document and copy in these lines:
<?php
phpinfo();
?>
Call the file phpinfo.php and save it to Apache’s htdocs directory. Now, try http://localhost/phpinfo.php. It will be obvious to you if it is working or not. If you now want to do a quick test of MySQL and PHP together, copy this into a new text file and call it phpsql.php. Edit the login info. accordingly.
<?php
// hostname or ip of server (for local testing, localhost should work)
$dbServer=’localhost’;// username and password to log onto db server
$dbUser=’root’;
$dbPass=”;
// name of database
$dbName=’test’;
$link = mysql_connect(”$dbServer”, “$dbUser”, “$dbPass”) or die(”Could not connect”);
print “Connected successfully<br>”;
mysql_select_db(”$dbName”) or die(”Could not select database”);
print “Database selected successfully<br>”;
// close connection
mysql_close($link);
?>
Now, try http://localhost/phpsql.php
You could install ActivePerl, if you wanted to and configure that to work with Apache as well, but that’s beyond the scope of this brief setup. And besides, it isn’t necessary.
Configure Server
This brief how-to assumes that you are running your home server from one machine and your home intranet from another. If you want to put both on the same machine, search for information of running virtual hosts with Apache. I presume that’s how it’s done. You will also have to decide which of the two networks will have the default web port 80. The other one then have to run from a different port.
Home web server
Your home web server is probably working right now. To see if it is, type in your IP address and your should see the same thing as when you type in http://localhost/. If you would like a free domain name to use, follow this brief instruction.
In httpd.conf we already have the ServerName = myplace.net. You need to change that to the domain you select to use.
Home intranet server
In httpd.conf we already have the ServerName = myplace.net. If you have a web server running on another machine using port 80, then we need to use, for example, ServerName = myplace.net:8080. Don’t forget to change the listen instruction: Listen 8080
You can either rename your computer name to myplace.net or do this to use myplace.net as a URL:
Edit your “hosts” file located at C:\Windows\System32\drivers\etc. You will see this line in the file:
127.0.0.1. localhost
Under that, add this line:
127.0.0.1 myplace.net
Assuming that on machine with Apache has a local network address of 192.168.1.111, put that in the “hosts” files of all other network machines.
192.168.1.111 myplace.net
Now test it by running http://myplace.net or http://myplace.net:8080
Security
To restrict access to your network to certain machines modify the follow section in httpd.conf:
<Directory “C:/Server/Apache/htdocs”>
. . .
Order deny,allow
Deny from all
Allow from localhost
Allow from 192.168.1
</Directory>
Use the Allow instruction to specify IPs, or a part thereof for a range of IPs, as I did in the example.
phpMyAdmin
Install phpMyAdmin
Download and install phpMyAdmin from http://www.phpmyadmin.net/home_page/downloads.php. Unzip it to C:\Server\Apache2\htdocs. To install, follow the install instructions at the official wiki, which is here: http://wiki.cihar.com/pma/Quick_Install. The quickest way is to perhaps create a /config directory in your . . ./htdocs/phpmyadmin. Then run http://localhost/phpmyadmin/scripts/setup.php.
When it’s installed, just run http://localhost/phpmyadmin.
In preparation for the next stage, create a new SQL database. For our example, we’ll install Joomla, so create a database called joomla. Once that is done, you’ll need to set the permissions or nothing will work. From the main phpMyadmin page, select permissions, and then select either root or a user you might have set up. Choose the database you created and check the permissions for that user. The easiest thing is to just “Check All.”
Security
Remember that the rest of the world can now see your server. You’ll need security to protect people from accessing phpmyadmin and creating havoc for you. In your httpd.conf file, add this to lock everyone out:
<Directory “C:/Server/Apache/htdocs/phpmyadmin”>
AllowOverride None
Options None
Order deny,allow
Deny from all
Allow from 127.0.0.1
Allow from 192.168.1
</Directory>
Restart Apache.
Joomla
Install Joomla (or PHP Fusion or Wordpress, or whatever).
Joomla, which began as an Australian project called Mambo, is perhaps one of the best open source CMS or content management systems you can get. It is found at http://www.joomla.org/. Just grab the latest zip package: http://joomlacode.org/gf/download/frsrelease/111/262/Joomla_1.0.12-Stable-Full_Package.zip. Unzip it into your . . ./htdocs directory, for example, or into into . . ./htdocs/joomla.
You have already set up a database, so now simply got to http://localhost/ and follow the install instructions.
In the configuration.php file, you can use myplace.net or myplace.net:8080 at the live_site name.
I don’t think I left anything out but please let me know if I have.
- Skip Sign-Up
- Select “Configure the MySQL Server now”
- Select “Detailed Configuration”
- Select “Server Machine”
- Select “Multifunctional Database”
- Select “InnoDB Tablespace Settings” – leave everything default
- Select “Decision Support (DSS)/OLAP”
- Make sure “Enable TCP/IP Networking” is checked and leave the port number at 3306
- Select “Multilingual” (if you think you need it)
- Select “Install As Windows Service”
- Enter your root password and leave “Enable root access from remote machines” unchecked
- Select “Execute” and installation will be complete.