MySQL, PHP and Apache Webserver
Mar 8, 01:28 PM By Eoghan O'Brien.Introduction
In order to set up an Apache Webserver running MySQL and PHP you’ll need to download the packages from they’re respective websites.
Apache is an open source web server which is completely free to download and use. At the time of writing this Apache 2.2.0 was the best version available.
PHP is completely free to download and use. When you reach the download page, look for the latest stable version ( v5.1.2 at time of writing) and download it.
MySQL is a very powerful open-source relational database, again completely free to download and use.
In order to download MySQL you must first register as a user on the site, you will then be given access to the downloads page.
Apache, MySQL and PHP can be installed in any order you like however in this tutorial I’m goin to start with PHP, then MySQL and finally Apache.
Step 1 – Installing MySQL
Unzip the file and run the setup.exe program contained therein. Follow the onscreen instructions, don’t forget to enter a password for using the command prompt and for added security. Once installed, you need to create a file called my.cnf in the root of your C: drive to indicate where you have installed MySQL. To create this file, simply open Notepad and type these three lines:
[mysqld]
basedir = c:/mysql/
datadir = c:/mysql/data/
If you don’t like the idea of a MySQL configuration file sitting in the root of your C: drive, instead, you can name it my.ini and put it in your Windows directory (e.g. C:\WINDOWS or C:\WINNT if Windows is installed on drive C:).
Step 2 – Installing PHP
The next step is to install PHP. You should have downloaded PHP for free at this stage. You’ll want the PHP 5.x zip package under Windows Binaries; avoid the installer version if you can. To test dynamic Web pages with PHP, you’ll need to equip your own computer with Web server software. (We’ll use Apache for this)
Firstly, unzip the file you downloaded from the PHP Website into a directory of your choice. I recommend C:\PHP and will refer to this directory from this point onward, but feel free to choose another directory if you like.
Next, find the files called php5ts.dll and libmysql.dll in the PHP folder and copy it to the system32 subfolder of your Windows folder
(e.g. C:\WINDOWS\system32). Now, find the file called php.ini-dist in the PHP folder and copy it to your Windows folder. Once it’s there, rename it php.ini.
Finally, open the php.ini file in your favorite text editor (use WordPad if Notepad doesn’t display the file properly). Look for a line that begins with extension_dir, set it so that it points to the ext subfolder of your PHP folder:
{color:blue}extension_dir = “C:\PHP\ext”
A little further down, you’ll see a bunch of lines beginning with
{color:blue};extension=.
These are optional extensions, disabled by default. We want to enable the MySQL extension so that PHP can communicate with MySQL. To do this, remove the semicolon from the start of the php_mysql.dll line:
{color:blue}extension=php_mysql.dll
Even further down, look for a line that starts with session.save_path and
set it to your Windows TEMP folder:
{color:blue}session.save_path = “C:\WINDOWS\Temp”
Save the changes you made and close your text editor.
Step 3 – Installing Apache
Once the setup file ( Windows Binary ) is downloaded, find the location you downloaded it to, double click it and follow the onscreen instructions. Below is a list of what you will come across and what to type in:
1.Network Domain. Enter the DNS domain in which your server is or will be registered in. Usually localhost.
2.Server Name. Your server’s full DNS name. From the example above, you would type server.mydomain.net here.
3.Administrator’s Email Address. Enter the server administrator’s or webmaster’s email address here. This address will be displayed along with error messages to the client by default.
4.For whom to install Apache Select for All Users, on Port 80, as a Service – Recommended if you’d like your new Apache to listen at port 80 for incoming traffic. It will run as a service (that is, Apache will run even if no one is logged in on the server at the moment) Select only for the Current User, on Port 8080, when started Manually if you’d like to install Apache for your personal experimenting or if you already have another WWW server running on port 80.
5.The installation type. Select Typical for everything except the source code and libraries for module development. With Custom you can specify what to install. A full install will require about 13 megabytes of free disk space. This does not include the size of your web site(s).
6.Where to install. The default path is C:\Program Files\Apache Group under which a directory called Apache2 will be created by default.
If Apache installed correctly you should have an icon (green triangle over a red feather) in your taskbar, if you don’t see this icon, restart your computer. Then open a browser and go to http://localhost/
Step 4 – Getting Apache to recognize PHP
In order to get PHP to work with Apache, we have to let Apache know that PHP is installed.
On your Start Menu, choose:
{color:red}Programs > Apache HTTP Server > Configure Apache Server > Edit the Apache httpd.conf Configuration File.
This will open the httpd.conf file (choose Notepad if you don’t have a text editor configured to edit .conf files).
All you need to do is add the following lines to the very bottom of the file:
%{color:blue}
LoadModule php5_module c:/php/php5apache2.dll
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
%
Make sure the LoadModule line points to the appropriate file in the PHP
installation directory on your system, and note the use of forward slashes (/) instead of backslashes (\).
Next, look for the line that begins with DirectoryIndex. This line tells Apache which file names to use when it looks for the default page for a given directory. You’ll see the usual index.html and so forth, but you need to add index.php to that list if it’s not there already:
{color:blue}DirectoryIndex index.html … index.php
Then save your changes and close Notepad. Restart Apache by restarting the Apache service in:
{color:red}Control Panel > Administrative Tools > Services.
Or
Left click the icon in the taskbar and select restart.
If all is well, Apache will start up again without complaint.
Nice work Eoghan! On a side note, I really like the this is not spam tick box.. nice simple way of stopping robots!