Home » Web development » Step by step guide to build local Apache PHP MySQL development environment on windows

Step by step guide to build local Apache PHP MySQL development environment on windows

A php developer would offcourse like to test the php file before deploying on the webserver.A local Apache PHP MySQL development environment on windows allows you to test your code as you develop your web application before publishing it to the web. This article will guide you through setting up a local Apache PHP MySQL development environment on windows
Step 1. Download the installation files

First of all we will need to download and install the windows version of the installers for each of the below componments:

Apache
Apache is the HTTP (Web) server software. http://httpd.apache.org/download.cgi

PHP
PHP is the general-purpose scripting language, especially suited for Web development, that we will be using. http://www.php.net/downloads.php

MySQL Server
MySQL is the database server/software we will be using.

http://dev.mysql.com/downloads/mysql/5

Step 2: Apache Setup
We are targeting here Apache 2.2 version ,But this will be almost same for all the version

a) Run the installer wizard and click through each step until you reach the Server Information window and give the options below respectively and in the given order in each of the fields, unless you have any specific requirements as to how your web server is setup: 1.localhost,
2.localhost and
3.admin@localhost

b) Click through the wizard which will install and start the apache web server as a windows service.
c) In the windows status bar you will now see a pink colored feather with a green colored play button indicating Apache is up and running. Point your browser to http://localhost/ and you should get a page indicating its working.

d) Apache would be installed the default directory C:\Program Files\Apache Software Foundation\Apache2.2

More Information about Apache

Bin directory It contains the various binary files like httpd.exe ab.exe

1.httpd.exe which is the Apache webserver itself, which is spawned to several child processes while serving as many simultaneous incoming clients requests as required by MaxClients directive;

2.ab.exe is a benchmarking tool that comes with Apache allowing you to see how well your application can perform per time unit

Conf directory This folder contains  various configuration files

1.httpd.conf – most of the server directives are located in this file and for easy access you should associate the .conf file type with a user friendly editor, i.e. anything other than the default Notepad.

2.httpd-vhosts.conf – contains directives that would allow you use your local server as virtual host, i.e. able to run several servers on your PC.

Htdocs directory the default web server root, this is where the http://localhost/ is mapped, i.e. if you don’t reconfigure it in httpd.conf above
logs It contains access and error logs, when trying to address various issues related to your server or even your application

Step 3: Install PHP
This guide will assume the PHP version is version 5.x.

a) Create a folder on your machine for PHP. For example, c:\php. Extract all of the files from the zip file to the c:\php directory.

b) Copy the file called c:\php\php.ini-recommended to c:\php\php.ini

c) The next step is to Configure PHP.The configuration amounts to editing the php.ini file. The common values to tweak are as follows and all of these variables are well documented in the php.ini file

max_execution_time whenever you have scripts that run for too long and the server returns various unexpected results which you think is due to not being able to run through the whole process
display_errors This  enable to see error messages from your PHP pages, Search for the line display_errors, and make sure the value is set to On.
extension_dir This  point out the directory where the following extensions are located by uncommenting this variable and assign the absolute location of the folder, and the complete line should read as follows

extension_dir = “C:\PHP\ext”

Dynamic extensions section contains various additional modules that you want to be loaded with, and the commented once are those that comes prepackaged with PHP and can be found in the ext directory in your PHP folder. If you want to activate any just remove the commenting as you should do with the following extensions:

extension php_curl.dll
extension php_gd2.dll
extension php_mbstring.dll
extension php_mysql.dll
extension php_mysqli.dll
extension php_pdo.dll
extension php_pdo_mysql.dll
extension  php_xsl.dll

Step 3: Configure Apache to run PHP as a Module

To configure Apache to run PHP, the httpd.conf file needs to be modified. This file is located in the apache installation directory under the conf folder. Open the httpd.conf file in notepad and do the following:

A. Add the following line after all of the LoadModule statements:

LoadModule php5_module “c:/php/php5apache2_2.dll”

B. Search for AddType, and add the following after the last AddType line:

AddType application/x-httpd-php .php

C. Add the PHP location to the end of the httpd.conf file. For example, at the end of the file, add the following:

PHPIniDir “c:/php”

D. Restart Apache

Now, the apache web server needs to be restarted. You can do this either via the Apache service located in the services control panel or via the Start -> All Programs -> Apache . . . -> Control Apache Server menu option.

Step 5: Install Mysql

As per the below article

Mysql installation on Windows

Step 6. Run a test PHP page to verify that PHP is running

  1.  create a php file with the following contents:

<?php phpinfo(); ?>

Save the file as “phpinfo.php” in the “htdocs” directory in the Apache installation directory, if you used the default installation path it would be:

C:\Program Files\Apache Software Foundation\Apache2.2\htdocs

Now, in your browser, type:

http://localhost/phpinfo.php

You should see the a PHP information page displayed.

If PHP is not running, you may check the Apache error log for further information about the errors. The error logs are located in the “logs” directory in the apache installation directory.

Step 7: Verification of mysql from php

Connect to mysql command line client with root password and create a webtest database

mysql > Create database webtest;

Then create a user

mysql > CREATE USER t1@’localhost’ IDENTIFIED BY ‘password’;

create a php file with the following contents:

<?php
mysql_connect(‘localhost’, ‘t1’, ‘password’) or die(‘Could not connect the database : Username or password incorrect’);
mysql_select_db(‘db_name’) or die (‘No database found’);
echo ‘Database Connected successfully’;
?>

Save the file as “phptest_mysql.php” in the “htdocs” directory in the Apache installation directory, if you used the default installation path it would be:

C:\Program Files\Apache Software Foundation\Apache2.2\htdocs

Now, in your browser, type:

http://localhost/phptest_mysql.php

If all of the input data(db_name, username, password, hostname) are right, then the output is like;
Database Connected successfully

Hope you like this post on Step by step guide  to build local Apache PHP MySQL development environment on windows.Please do provide  the feedback

 

See also  Useful PHP string functions

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top