In this tutorial we will install PHP, Apache HTTP, MySQL and phpMyAdmin on Windows 7 with examples and explanations.
Note that it will work also on Windows XP and Windows Vista.
So we will install on Windows 7:
Apache HTTP Server (httpd) 2.2.21
MySQL Community Server 5.5.16
Let's see, first of all, the list of official websites:
The download page: http://www.mysql.com/downloads/
We will take the Community Server version.
You do not need to enter your email address, just go at the bottom and click on: "No thanks, just take me to the downloads!".
OK, let's see now our system:
We are supposed to install our software in the "Program files" directory, even PHP and phpMyAdmin (to remember where they are installed).
This is a very classic installation.
Lets' start with Apache HTTP.
Download the Win32 MSI installer with the link above.
Once done, you have to execute it (double click it).
Click Next, Accept and Next, then Next again.
You see now 3 empty fields that you have to fill.
In Network Domain, enter: localdomain
In Server Name, enter: localhost
In Administrator's Email Address enter a fake or a real address (it is not important for the moment).
Let the option "for All User, on Port 80, as a Service - Recommanded" ticked and click Next.
Choose the Typical installation then click Next.
Let the classic path as it is: "C:\Program Files (x86)\Apache Software Foundation\Apache2.2" and click Install.
Click Next then Finish.
Let's open a browser such as Firefox and write this in your address bar: http://localhost/
If you see "It works!" on the web page, so Apache HTTP is installed.
Let's continue with PHP.
Create a directory in "C:\Program files (x86)" named "php".
Create a new one inside "php" named "php-5.3.8".
So we have this new directory: "C:\Program files (x86)\php\php-5.3.8".
Download the Zip PHP file, open it and copy/paste all in the "php5.3.8" directory you have just created before.
PHP is installed.
At this point, we do not have finished the full installation. It is still missing MySQL and phpMyAdmin.
But we have to test before if PHP and Apache HTTP can work together correctly.
Open the httpd.conf file that you can find in this directory: "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf".
There are lot of lines starting with the LoadModule word.
Find them and write at the end of these LoadModule lines, this new one:
LoadModule php5_module "C:/Program files (x86)/php/php-5.3.8/php5apache2_2.dll"
We can also uncomment line 118 (or about) by removing the sharp # before:
LoadModule rewrite_module modules/mod_rewrite.so
Do the same at line 175 and remove the #:
We have now to add the php type.
Find the <IfModule mime_module> section.
At the end of it, just before </IfModule>, add this new line:
AddType application/x-httpd-php .php
Near line 224, we can see this:
# # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride None
Replace None by All, like this:
# # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # Options FileInfo AuthConfig Limit # AllowOverride All
Then let's add the DirectoryIndex for page named index.php.
Go at line 244 in order to find the <IfModule dir_module> line.
Modify balises like this:
<IfModule dir_module> DirectoryIndex index.php index.html </IfModule>
Now file named index.php will replace the list of files at the root.
At this time, all our websites should have been created in the directory:
C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs
But it is not what we want.
We want to create our websites in another directory called:
We have to find the line, generally at line 183:
DocumentRoot "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs"
Let's change it by:
We have also to change the line:
<Directory "C:/Program Files (x86)/Apache Software Foundation/Apache2.2/htdocs">
Indeed, let's replace it by the new directory:
Be careful, the directory must exist or Apache HTTP will crash.
At the end of your httpd.conf file, add this line to tell to Apache where is the correct php.ini file (we will configure it in a minute):
PHPIniDir "C:/Program Files (x86)/php/php-5.3.8"
Go on your taskbar and left click on the Apache HTTP icon, click on Apache 2.2, then on Restart.
Now your http://localhost/ address will display all the files inside the "C:\www" directory or no one if the directory is empty.
If you do not have any error, let's continue.
Go on the "C:\www" directory.
Create a new file named test.php and open it.
Inside write this:
<?php phpinfo(); ?>
Reopen your browser at http://localhost/.
You can now see the file test.php.
Click test.php and normally you will see all features of your PHP installation.
It means that PHP and Apache are correctly installed.
Let's continue a bit with PHP, return to the directory:
"C:\Program Files (x86)\php\php-5.3.8"
Copy the php.ini-development file and rename it into php.ini.
Open this php.ini file and go until the Paths and Directories area (line 780).
Below find the line:
; extension_dir = "ext"
Remove the semicolon at the beginning of the line and replace the line by:
extension_dir = "C:/Program Files (x86)/php/php-5.3.8/ext"
Go now until the Dynamic Extension area (line 918).
You can see just below a block of lines starting with the ";extension=php_" expression.
If you want to activate an extension, remove the semicolon just before the line.
To our installation, let's decomment the lines:
extension=php_bz2.dll extension=php_gd2.dll extension=php_mbstring.dll extension=php_mysqli.dll
These extensions are respectively for compressing and extracting files on the fly, generating images, encoding characters, using MySQL.
If you prefer using mysql instead of mysqli, decomment the line:
If you do not know what it this, decomment both.
Others extensions can cause the crash of your Apache HTTP configuration if you decomment them without knowing what they are.
So, be careful when you choose to decomment them, try one by one and restart your server.
If it does not fail, it is OK.
We have now to set the Timezone correctly.
Of course, it depends of your country.
Go at line 1000 and remove the semicolon in front of line "date.timezone =".
Add the timezone of your choice, for example:
date.timezone = "America/Los_Angeles"
if your server is installed in the West cost.
date.timezone = "Europe/Paris"
for a server in France.
OK save this php.ini file and restart the Apache HTTP server.
Let's come back to the test.php file at the root of our server ("C:\www") to see the new features appear.
Indeed, now the timezone is correctly set and we can see the new extension such as bz2, gd, mbstring and mysqli.
Let's install MySQL now.
Execute the MSI file (double click on it).
Click Next, Accept the terms of the Licence Agreement, Next, Complete, Install.
A new window appear, click Next and Next.
You come back to the last window and a Checkbox is checked, let it checked and click Finish to launch the MySQL Instance Configuration Wizard.
This wizard opened, click on Next.
Choose Detailed Configuration and Next.
Choose Developer Machine and Next.
Choose Multifunctional Database and Next.
Let the standard configuration: C: and Installation Path.
Choose the Manual Setting and write the number of simultaneous connections you want then click Next.
Let all checked and the Port Number 3306.
Choose Best Support for Multilingualism then Next.
Select Install As Windows Servive with Service Name MySQL, let the option Launch the MySQL Server automatically selected and select also the Include Bin Directory in Windows PATH option.
You have now to choose a password, type it and retype it, then click Next.
Your username is root by default.
You will have to use it in your phpMyAdmin application, or by a command line tool.
If you have an error at step 3: Could not start the service mysql, it is because who already have a version of MySQL on your computer.
Generally go on the hidden "C:\ProgramData" directory or "C:\Users\YourName\AppData\Roaming".
If you can not see it, open a folder and click on the Organize button at the top left.
Then click the View tab, find the "Show hidden files and folders" option and select it.
Now your hidden files are displayed.
Come back to your "C:\ProgramData" directory or "C:\Users\YourName\AppData\Roaming".
If you can see the MySQL directory and that you have directories inside, rename this MySQL directory into MySQL_Save for example, and try again the installation.
Try also to remove and reinstall MySQL.
Normally it will be enough.
So MySQL is now installed.
Let's install phpMyAdmin.
Nothing hard, just open the phpMyAdmin-3.4.1-all-languages.zip file you downloaded before.
Copy all files in a new directory named phpmyadmin into "C:\www".
Open your browser at http://localhost/phpmyadmin/
You will see the connection page of phpMyAdmin.
Enter your login and password and click GO,
Click the SQL icon on the top left, just under the phpMyAdmin logo.
A window open, click Import files.
Select the file: C:\www\phpmyadmin\scripts\create_tables.sql.
You just created the phpmyadmin database, useful for advanced features.
You have now to create the user and their rights to use it.
Reclick the SQL icon under the logo, and write in the window:
GRANT SELECT, INSERT, DELETE, UPDATE ON `phpmyadmin`.* TO 'pma'@localhost IDENTIFIED BY 'pmapass';
Nothing happens apparently but you finished the phpMyAdmin installation.
If all is OK, you will be able to manage your MySQL database.
Now we will create an alias for our project.
Instead of write this address:
we will use:
Open the file "C:\Windows\System32\drivers\etc\hosts".
Inside there are a comment and several lines beginning by:
Normally you have already:
Write just under this:
Save the file.
Now open your httpd.conf, for example:
C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf
Uncomment (remove the sharp # before) the line 470 where there is this line:
Save the file.
Open the httpd-vhosts.conf file, for example you can find it in your Apache path:
C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\extra
Do not remove anything inside, just add this at the end of the file:
# ourproject <VirtualHost *:80> ServerAdmin me@ourproject DocumentRoot "C:/www/ourproject" ServerName ourproject ServerAlias ourproject ErrorLog "logs/ourproject.error.log" CustomLog "logs/ourproject-access.log" common </VirtualHost>
Then add this code too, it is necessary to see the localhost:
# localhost <VirtualHost *:80> ServerAdmin webmaster@dummy DocumentRoot "C:/www" ServerName localhost ServerAlias localhost ErrorLog "logs/localhost.error.log" CustomLog "logs/localhost-access.log" common </VirtualHost>
Save the file.
Create a file named index.php in the "C:\www\ourproject" directory and write this:
<? php echo "Eh it works :D"; ?>
Save the file.
Now restart your Apache HTTP server.
Go to this address:
And normally you are seeing:
Eh it works :D
Well done, you made it!