Sunteți pe pagina 1din 9

How to install & setup a working Apache Php Sql Server

Page 1 of 9

Below are basic instructions which should get you an Apache Web Server up and running, which supports PHP and MySQL. The versions of software that I used for the following instructions are:Apache:- 2.2.3 Win 32 Binary with SSL [4.6Mb] My SQL:- Windows (x86) ZIP/Setup.EXE 5.0.27 [40.3M] PHP:- PHP5.2.0 zip package [8,919Kb] - 4 May 2006 Microsoft C++ 2005 Redistributable SP1

First of all, download MySql from http://dev.mysql.com/downloads/mysql/5.0.html#downloads. Open the ZIP file and extract SETUP.EXE, then double-click it to install.

Select CUSTOM install Select all options Skip Signup Configure now Standard config Include Bin directory in path Launch MySql Automatically

the path to d:\mysql5027

Install as Windows Service -->name "MySql5"

Enter a password Enable root access from remote machines

If an error message appears click "Retry"

Open Notepad and type the following and save it in the root of C:\ as my.cnf [mysqld] basedir=d:/mysql5027/ datadir=d:/mysql5027/data/ You only need to enter the following if you didn't select to Launch MySql

file://T:\apache - php - mysql\wamp install\install WAMP ssl.htm

14/01/2007

How to install & setup a working Apache Php Sql Server

Page 2 of 9

Automatically Open the COMMAND PROMPT and enter the following commands:mysqld-nt --install net start mysql5

Download the file apache_2.2.4-win32-x86-ssl.zip http://www.apachelounge.com/download/binaries/httpd-2.2.4-win32-x86-ssl.zip. Once downloaded, double-click to open the file in WinZIP. Extract the contents of the ZIP file to the folder d:\apache2

from

Open the httpd.conf (d:\apache2\conf) file into Notepad. You will need to change some entries as below:ServerRoot "d:/Apache2" Listen 80 DocumentRoot "d:/Apache2/htdocs" <Directory "d:/Apache2/htdocs"> DirectoryIndex index.htm index.php ScriptAlias /cgi-bin/ "d:/Apache2/cgi-bin/" <Directory "d:/Apache2/cgi-bin"> Then add the following lines to the END of the conf file. # BEGIN PHP INSTALLER - REMOVE ONLY ON UNINSTALL LoadModule php5_module "d:/php520/php5apache2_2.dll" AddType application/x-httpd-php .php .inc PHPIniDir "d:/php520" # END PHP INSTALLER - REMOVE ONLY ON UNINSTALL
NB. A BIZARRE SITUATION HAS ARISEN WITH THESE LATEST VERSIONS OF THE WAMP SOFTWARE, WHERE MYSQL WON'T LOAD ON SOME MACHINES. THE SOLUTION HAS BEEN TO COMMENT OUT THE PHPINIDIR LINE.

You may want to create some shortcuts

D:\Apache2\bin\ApacheMonitor.exe

D:\Apache2\conf\httpd.conf

file://T:\apache - php - mysql\wamp install\install WAMP ssl.htm

14/01/2007

How to install & setup a working Apache Php Sql Server

Page 3 of 9

With this version of Apache, you will need to download and install the Microsoft C++ Redistributable SP1 from Apache Lounge: http://www.apachelounge.com/download/vcredist_x86-sp1.exe

Download the php520-win32.zip file from http://uk.php.net/get/php-5.2.0Win32.zip/from/a/mirror. Once downloaded, extract the contents to d:\php520 Rename php.ini-dist file in the d:\php520 directory to php.ini and open it in Notepad Change the line ;extension_dir="./" to extension_dir="d:\php520\ext" Uncomment the line ;extension=php_mysql.dll Uncomment the line ;session.save_path="N;/path" session.save_path="c:\windows\temp" and change it to

Go to the System Properties Page (through Control Panel) Click the Advanced Tab Click on the button Environment Variables Under the System Variable section click on NEW Enter under Variable Name: PHPRC Enter under Variable Value: d:\php520 in the Variable Name section, find the entry for PATH and add the following to the end of the line:; d:\php520 Restart Windows Now open a command prompt window and type:d: (enter) cd apache2\bin (enter)

file://T:\apache - php - mysql\wamp install\install WAMP ssl.htm

14/01/2007

How to install & setup a working Apache Php Sql Server

Page 4 of 9

httpd -k install (enter) httpd -k start (enter) Create a text file in notepad with the following, and then save it in your htdocs folder as index.php:<?php phpinfo() ?> Then open your web-browser and type in the address bar http://localhost (if using a port other than port 80 you will need to type http://localhost:port replacing the word port with the appropriate number. If all has gone well, you should then get a page similar to this.....

In order to setup the apache server to accept connections via a secure SSL connection there are 4 things that need to be carried out:1: Change the HTTPD.CONF file to load the mod_ssl module 2: Add a second listening port to the HTTPD.CONF file 3: Setup Virtual Hosts within the HTTPD.CONF file 4: Create an Self Signed Certificate to use for testing. This can be left in place permanently if you wish, or you can purchase one from a trusted source.

file://T:\apache - php - mysql\wamp install\install WAMP ssl.htm

14/01/2007

How to install & setup a working Apache Php Sql Server

Page 5 of 9

Before we start, we need to create some new folders as below:d:/Apache2/htdocs/80 d:/Apache2/htdocs/443 d:/Apache2/conf/ssl Now let's address the 3 points relating to the HTTPD.CONF file. Open the file into NOTEPAD and then:1: Uncomment the line (by remove the #) #LoadModule ssl_module modules/mod_ssl.so 2: Below the existing line Listen 80 add Listen 443 3: Assuming your website's address is http://www.website.com and the document root is d:/Apache2/htdocs then add the following to the end of your HTTPD.CONF file NameVirtualHost *:80 <VirtualHost *:80> ServerName www.domain.tld ServerAlias domain.tld *.domain.tld DocumentRoot "d:/Apache2/htdocs/80" </VirtualHost> <VirtualHost *:443> ServerName www.domain.tld DocumentRoot "d:/Apache2/htdocs/443" SSLEngine On SSLCertificateFile conf/ssl/domain.crt SSLCertificateKeyFile conf/ssl/domain.key </VirtualHost> Now save the file. 4: To create the certificate and key, copy the file openssl.cnf from d:/Apache2/conf/ to a new directory c:\openssl\ssl. Now open a DOS window and change the directory to d:/apache2/bin folder. type the following:openssl req -new -out domain.csr (enter) You will then be asked to enter the following information (I have added examples in black capitals):Enter PEM pass phrase: ABRACADABRA Verifying - Enter PEM pass phrase: ABRACADABRA ----You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----Country Name (2 letter code eg. AU) UK State or Province Name: CHESHIRE

file://T:\apache - php - mysql\wamp install\install WAMP ssl.htm

14/01/2007

How to install & setup a working Apache Php Sql Server

Page 6 of 9

Locality Name (eg, city): STALYBRIDGE Organization Name (eg, company): PIPS UK Organizational Unit Name (eg, section): RESEARCH Common Name (eg, your name): PHIL STEELS Email Address: PHIL@DOMAIN.TLD

Please enter the following 'extra' certificate request A challenge password: HUMPTYDUMPTY An optional company name: PIPSNET

attributes

to

be

sent

with

your

openssl rsa -in privkey.pem -out domain.key (enter) Now enter the passphrase (ABRACADABRA) you gave in the previous command. openssl x509 -in domain.csr -out domain.crt -req -signkey domain.key -days 365 (enter)

Now copy the files to the domain.key and domain.crt from the d:/Apache2/bin folder to the d:/Apache2/conf/ssl folder Restart your apache server. Any files that you had in the root of d:/Apache2/htdocs which were used to test the basic installation of apache, must now be moved into the 80 folder, as this is now the root of the unsecured web-pages. Any pages that are to be treated as secure must be now stored in the 443 folder.

If you wish to use the domain's mentioned in this article for testing purposes, it will be necessary to add an entry into the HOSTS file (which can be found in the c:\windows\system32\drivers\etc\ folder) just add the following text to the end of the file:172.19.0.16 www.domain.tld

remember to substitute 172.19.0.16 with the actual IP address of the PC you are using for hosting. Modifications made to conf since basic installation Since the initial install, I have added support for icons, designed my own custom error pages, setup several virtual hosts. I will detail these below:Icons add the following line into your httpd.conf file:Include conf/icons.conf Click icons.conf to download my conf file. You can modify this to suit your own applications. I also created all new icons based on the actual icons that the files are associated with. Virtual Hosts I am now hosting several websites on our server using the Virtual Hosts facility within Apache. Add the following line to your httpd.conf file:-

file://T:\apache - php - mysql\wamp install\install WAMP ssl.htm

14/01/2007

How to install & setup a working Apache Php Sql Server

Page 7 of 9

Include conf/vhosts.conf Click vhosts.conf to download my conf file. A problem arose (which is common to all SSL modules) in that the secured domain (https://www.domain1.co.uk) works fine but if i were to type https://www.domain2.co.uk this would automatically serve the files for domain1 - even though I had specifically set the domains in the VirtualHost configurations!! After much googling (unsuccessfully) Tom Donovan (from the ApacheLounge Forums) came up with a solution for me using the RewriteEngine command. Below is the full entry for the SSL Virtual Host:-

<VirtualHost *:443> ServerName www.domain10.co.uk ServerAlias *.domain10.co.uk domain10.co.uk DocumentRoot "d:/Apache2/htdocs/443" SSLEngine On SSLCertificateFile conf/ssl/domain10.crt SSLCertificateKeyFile conf/ssl/domain10.key # redirect any SSL requests to hosts other than www.domain10.co.uk back to non-SSL http://hostname <IfModule rewrite_module> RewriteEngine on RewriteCond %{HTTPS} on RewriteCond %{HTTP_HOST} !www.domain10.co.uk RewriteRule .* http://%{HTTP_HOST}$0 [R=permanent] </IfModule> </VirtualHost>

Basically, what this command does is looks at 2 conditions which must both be fullfilled for the rule to be executed. So, if HTTPS is used, and the domain entered does NOT equaly www.domain10.co.uk then command line is re-written with http:// instead. This doesn't stop the warning that the certificate doesn't match the website from popping up, but in my case, I can live with that! Custom Error Pages I wanted to create some new customer error pages, and also to email me about any 404 pages or documents that aren't found, so I can then investigate. Add the following line to your httpd.conf file:Include conf/error.conf The contents of the errordoc.conf file is below:Alias /error/ "d:/Apache2/error/" <Directory "d:/Apache2/error"> AllowOverride None Options IncludesNoExec AddOutputFilter Includes html AddHandler type-map var Order allow,deny Allow from all LanguagePriority en

file://T:\apache - php - mysql\wamp install\install WAMP ssl.htm

14/01/2007

How to install & setup a working Apache Php Sql Server

Page 8 of 9

ForceLanguagePriority Prefer Fallback </Directory> ErrorDocument ErrorDocument ErrorDocument ErrorDocument ErrorDocument ErrorDocument ErrorDocument ErrorDocument ErrorDocument ErrorDocument ErrorDocument ErrorDocument ErrorDocument ErrorDocument ErrorDocument ErrorDocument ErrorDocument 400 401 403 404 405 408 410 411 412 413 414 415 500 501 502 503 506 /error/BAD_REQUEST.html.var /error/UNAUTHORIZED.html.var /error/FORBIDDEN.html.var /error/404.php /error/METHOD_NOT_ALLOWED.html.var /error/REQUEST_TIME_OUT.html.var /error/GONE.html.var /error/LENGTH_REQUIRED.html.var /error/PRECONDITION_FAILED.html.var /error/REQUEST_ENTITY_TOO_LARGE.html.var /error/REQUEST_URI_TOO_LARGE.html.var /error/UNSUPPORTED_MEDIA_TYPE.html.var /error/INTERNAL_SERVER_ERROR.html.var /error/NOT_IMPLEMENTED.html.var /error/BAD_GATEWAY.html.var /error/SERVICE_UNAVAILABLE.html.var /error/VARIANT_ALSO_VARIES.html.var

So far I have only created the 404 error page, but intend to do the others soon. The contents of the 404 page are as follows:<html> <head> <title>Error 404 - Document Not Found</title> </head> <body> <font face="verdana, helvetica, arial" size=2> <font size=4>Error 404 - Page Not Found</font> <br><br><br> Sorry, the page you are looking for cannot be found at the moment. <br><br> An email has been generated and sent to the webmaster of this site to let him know. <br><br><br> <hr width=500> <font size=1> <?php // get environment variables from user $ip = gethostbyname(@$REMOTE_ADDR); $netbios = gethostbyaddr($ip); $ip_addr = getenv("REMOTE_ADDR"); $agent = getenv("http_user_agent"); $name = gethostbyaddr($_SERVER['REMOTE_ADDR']); $domain = getenv("HTTP_HOST"); $url = getenv("SCRIPT_NAME"); $hostinfo = getenv("SERVER_SOFTWARE"); $user = getenv("HTTP_USER_AGENT"); $from = getenv("HTTP_REFERER"); $time = getenv($_SERVER['REQUEST_TIME']); // Display Server Information //echo 'IP: <b>' . $ip_addr .' / ' . $name . '</b><br>'; echo 'Refferer Page: <b>' .$from . '</b><br>'; echo 'Domain: <b>' .$domain . '</b><br><br>'; echo '<b>' .$user . '</b><br>';

file://T:\apache - php - mysql\wamp install\install WAMP ssl.htm

14/01/2007

How to install & setup a working Apache Php Sql Server

Page 9 of 9

echo '<br>';

//send email with error information $txt = "IP: " . $ip_addr ." / " . $name . "\n\n" . "Refferer Page: " .$from . "\n\n" . "Domain: " .$domain . "\n\n" . "Page: " .$url . "\n\n" . "Time: " .$time . "\n\n" . $hostinfo . "\n\n" . $user . "\n\n" . "\n\n"; $strFrom = "sentfrom@domain1.com"; $headers = "From: $strFrom\r\n"; ini_set("SMTP", "post.demon.co.uk"); ini_set("smtp_port", "25"); mail("admin@domain1.com","404 - $domain ",$txt,$headers); ?> </body> </html> Below is an example email that was sent recently to me.
IP: 81.x.x.194 / 81-x-x-194.dsl.pipex.com Refferer Page: index.htm Domain: www.domain1.co.uk Page: /error/404.php Apache/2.2.3 (Win32) mod_ssl/2.2.3 OpenSSL/0.9.8d PHP/5.2.0 Mozilla/4.0 (compatible; GoogleToolbar 4.0.1020.2544-big; Windows XP 5.1; MSIE 7.0.5730.11)

These instructions are January 2007, Phil Steels

file://T:\apache - php - mysql\wamp install\install WAMP ssl.htm

14/01/2007

S-ar putea să vă placă și