How to install the latest version of Apache 2, OpenSSL, PHP 5 and MySQL 5 on Windows and set up virtualhost
There are lot of good step-by-step guides for installing Apache (A), MySQL (M) and PHP (P) on Windows, there are also boundle products around (WAMP, XAMPP). But most of these articles were about installing older version of AMP on Windows, or the boundled products are not using the latest version of Apache, MySQL and PHP.
This short guide is for people with some experience on installing AMP on Linux or older version of AMP on Windows.
1, Download Microsoft Visual C++ 2005 Redistributable Package (x86) from Microsoft, and install it.
http://www.microsoft.com/downloads/details.aspx?familyid=32bc1bee-a3f9-4c13-9c99-220b62a191ee
2, Download the latest version of Apache with OpenSSL (e.g., http://www.apachelounge.com/download/binaries/httpd-2.2.4-win32-x86-ssl.zip) from Apache Lounge:
3, Extract Apache-OpenSSL to c:\
4, Download the latest version of PHP, zip version (not installer version) from http://www.php.net/get/php-5.2.1-Win32.zip/from/a/mirror. Unzip it to c:\
5, Download the latest version of MySQL 5.0 Community Server from MySQL (http://dev.mysql.com/downloads/mysql), e.g.,
http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-noinstall-5.0.37-win32.zip/from/http://mirror.x10.com/mirror/mysql/
6, Install MySQL.
7, After installing all software, find httpd.conf file under C:\Apache2\conf, put the following lines:
PHPIniDir "C:\PHP\"
LoadModule php5_module "C:\PHP\php5apache2_2.dll"
ScriptAlias /php/ "c:/PHP/"
AddType application/x-httpd-php .php
8, Add virtualhost names to C:\WINDOWS\system32\drivers\etc\hosts, e.g.,
127.0.0.1 localhost
127.0.0.1 roller wordpress
127.0.0.1 mediawiki tikiwiki
127.0.0.1 oscommerce zencart
9, Add virtual hosts to httpd.conf
<VirtualHost 127.0.0.1:80>
ServerName zencart
ServerPath /
DocumentRoot C:\web\zencart
<Directory "C:\web\zencart">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
DirectoryIndex index.php index.html index.sh default.jsp
</VirtualHost><VirtualHost 127.0.0.1:80>
ServerName osc
ServerPath /
DocumentRoot C:\web\oscommerce
<Directory "C:\web\oscommerce">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
DirectoryIndex index.php index.html index.sh default.jsp
</VirtualHost>
10, Download OpenSSL for Windows from http://www.slproweb.com/products/Win32OpenSSL.html, install it. Then make a self-signed SSL certificate.
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
cp server.key server.key.org
openssl rsa -in server.key.org -out server.key
openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt
cp server.crt c:\apache2\ssl\ssl.crt
cp server.key c:\apache2\ssl\ssl.key
11, Configure virtualhost for https (httpd.conf )
Listen 443
<VirtualHost 127.0.0.1:443>
ServerName zencart
SSLEngine on
SSLCertificateFile c:\apache2\ssl\ssl.crt
SSLCertificateKeyFile c:\apache2\ssl\ssl.key
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown
CustomLog logs/ssl_request_log \
"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
CustomLog C:\Apache2\logs\zencart.log combined
ErrorLog C:\Apache2\logs\zencart-error.log
ServerPath /
DocumentRoot C:\web\zencart
<Directory "C:\web\zencart">
DirectoryIndex index.php index.html index.shtml default.jsp
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
uncomment the following line in httpd.conf
LoadModule ssl_module modules/mod_ssl.so
12, put the following line to php.ini file (in c:\PHP direcotry).
extension_dir=”C:\PHP\ext”
13, Uncomment MySQL modules in php.ini file:
extension=php_mysql.dll
extension=php_mysqli.dll
14, Start Apache, you can test your MySQL connection using the following PHP script:
<?php/* Set your host and login parameters */
$user=”grantdb”;
$password=”xxx”;$host=”localhost”;
?>
<html>
<head>
<title>MySQLinfo and PHPinfo</title>
</head>
<body>
<div align=”center”>
<?php
if(!extension_loaded(“mysql”)){
echo (“<br><font color=red><b>php MySQL extension not loaded !!</font>
<br><br>Check in php.ini if extension=php_mysql.dll is enabled, and that the extension_dir = is pointing to your php/ext folder.
<br><br>Copy libmySQL.dll from your Mysql/bin folder to c:/windows.</b><br><br><br>”);
phpinfo();
die;
}
$link = mysql_connect($host, $user, $password);
if (!$link) {
echo (‘<br><font color=red><b>Could not connect to the Mysql server !!</font><br><br>’ . mysql_error() . ‘<br><br><b>Did you set the correct host and login parameters in mysqlinfo.php ? <br><br><br>’);
phpinfo();
die;
}
else
{
if( $user == ‘root’ ) {
if( $password == ”) {
echo “<font color=red><b>Your user and password are the install default (user:root and password is blank), change it !!</b></font><br><br>”;
}
}
?><a href=”#var”><b>MySQL Server variables and settings</b></a>
<a href=”#phpinf”><b>PHP info</b></a><br><br>
<?php
printf(“<font color=navy>User <b>$user</b> connected to the MySQL server at <b>$host</b><br><br></b>Mysql version:</b><b> %s\n”, mysql_get_server_info());
?>
</b></font>
</div><br><br><center><font color=green><b>MySQL Runtime Information</b></font><br>
<TABLE border=0 bgcolor=”#ffffff” border=”0″ cellspacing=”0″ cellpadding=”0″>
<TD VALIGN=TOP border=”0″ bgcolor=”#ffffff” border=”0″ cellspacing=”0″ cellpadding=”0″>
<br><br>
<?php
$result = mysql_query(‘SHOW GLOBAL STATUS’, $link);
$p = 0;
while ($row = mysql_fetch_assoc($result)) {
$p ++;
if ($p==123){
echo ‘<br><br></td><TD VALIGN=TOP><br><br>’;
}
echo ‘ ‘ . $row['Variable_name'] . ‘ = ‘ . $row['Value'] . ” <br>”;
}
?>
</td></tr></table><br><a name=”var”><a href=”#top”><br><b>Back to top</b></a><br><br><br><font color=green><b>MySQL Server variables and settings</b></font><br>
<table border=0 bgcolor=”#ffffff” border=”0″ cellspacing=”0″ cellpadding=”0″>
<td valign=top>
<br><br>
<?php
$p = 0;
$result = mysql_query(‘SHOW VARIABLES’, $link);
while ($row = mysql_fetch_assoc($result)) {
$p ++;
if ($p==111){
echo ‘<br><br></td><td valign=top><br><br>’;
}
echo ‘ ‘ . $row['Variable_name'] . ‘ = ‘ . $row['Value'] . ” <br>”;
}
}
echo ‘</td></tr></table><br><a name=”phpinf”><br><a href=”#top”><b>Back to top</b></a><br><br><font color=green><b>Php info()</b><br>’;
phpinfo();
?>
</font><a href=”#top”><b>Back to top</b></a>
</center>
</body>
</html>
15, if you don’t see MySQL connection, you can copy php.ini file from C:\php directory to c:\windows, and copy libmySQL.dll from C:\MySQL\bin to c:\windows.
Tags: Windows