Local Development Environment - Part 2

Last time in Part 1 of this article we prepared our Apache web server and MailEnable mail server and assured that they are available online with a hostname of our choice that is dynamically updated with our IP via No-IP DUC.

Now in Part two we will install MySQL as the Database server, and PHP with its integration with Apache using Apache Modules and finally we’ll install TurboDBAdmin script as the online database administration script.

MySQL Database

MySQL is a free SQL database management system, one of the most famous databases available now for open source development specially with PHP, many books have been written on both, it is also known as a key of both LAMP and WAMP the two most used open source development environments. Now let’s start the installation:

  • Run the installation wizard downloaded in Part 1, and choose “Custom setup” in order to change the directory to your development path D:\development:

MySQL Custom Installation

  • “Skip Sign-UP” in the “MySQL.com Sign-Up” screen, unless you prefer to do so.
  • After the installation wizard is done check the “Configure the MySQL Server Now” box in order to start the configuration wizard.
  • In “MySQL Server Instance Configuration” choose “Standard Configuration”, then confirm that the “Install As Windows Service”, “Launch the MySQL Server automatically” and “Include Bin Directory in Windows PATH” options are checked.
  • Now in the “Security Options”, as we have our server available online, we don’t want to allow any access to our MySQL server from outside, so we will set a password for our “root” user account and disable both anonymous account and remote access from remote machines options.

MySQL Security Configuration

By setting the security options and finalizing the configuration wizard we have MySQL up and running on our local server, MySQL essential package doesn’t come with any graphical interface for the database system, so after we install PHP and integrate it with Apache we will install TurboDBAdmin as our graphical interface which will be available online as well.

PHP

I prefer the manual installation of PHP as it includes more extensions and it is more customizable, and luckily it is not difficult to do, just unzip the downloaded PHP compressed file (from Part 1) into your development directory D:\Development, and that’s it, PHP is there now, we only need to add it to the Windows PATH environment variables, and apply the PHP5Apache2 module.

To setup the Windows PATH variables go to Windows Control Panel -> System, and from the Advanced tab click on the “Environment Variables” button, in the System Variable section, edit the PATH variable and add your PHP path D:\development\php where php.exe exists, now wherever PHP is called it will be found.

Configuring Apache

In order to allow Apache to parse any PHP code placed in our web directory we have to load the PHP5 Apache2 Module, the module is available as a DLL file in our php directory under the name php5apache2.dll, we have to load it in Apache, add php file type and specify the PHP Ini Directory by adding the following lines to our httpd.conf file (located in D:\development\Apache2\conf\):

#
# Dynamic Shared Object (DSO) Support
#
# To be able to use the functionality of a module which was built as a DSO you
# have to place corresponding `LoadModule' lines at this location so the
# directives contained in it are actually available _before_ they are used.
# Statically compiled modules (those listed by `httpd -l') do not need
# to be loaded here.
#
# Example:
# LoadModule foo_module modules/mod_foo.so
#
 
LoadModule php5_module "d:/development/php/php5apache2.dll"
AddType application/x-httpd-php .php
PHPIniDir "d:/development/php"

To keep your httpd.conf clean and organized insert the above lines in the DSO Support section right after the default modules loads, and don’t forget to restart Apache after saving the changes.

To test PHP let’s create a small PHP file that call the php information function in our webroot folder D:\webroot\info.php and let’s try it http://yoursubdomain.no-ip.org:8520/info.php

<?php
  phpinfo();
?>

The phpinfo() function shows all the information about PHP on the local server in a nice html markup. Now PHP is working perfectly, you can run any PHP script not only locally but online also as you have an online web server.

TurboDBAdmin

With our secure database and the ability to run PHP scripts, we will install TurboDBAdmin which is a PHP script with some lovely Ajax touches that gives a nice interface to our database, and we will secure it using .htaccess.

To run the script just unzip the downloaded TurboDBAdmin compressed file (from Part 1) to the webroot folder as D:\webroot\turbodbadmin\, and edit the configuration file D:\webroot\turbodbadmin\php\config.php to meet your database credentials, by changing the “root” password around line 10 to the one you have created earlier during MySQL configuration wizard.

Let’s try it now: http://yoursubdomain.no-ip.org:8520/trubodbadmin, it’s working and we are able to see our database system, create tables, import, export, etc… Great but this script is available online now and anybody who knows the url can mess up our database system so let’s secure this directory using http security.

Securing TurboDBAdmin

To secure our script we will use http security by creating .htaccess and htpasswd users file into the script directory, first lets create the user file:

  • From the command prompt change directory to D:\development\Apache\bin\
    cd D:\\development\\Apache\\bin\\
  • Use the htpasswd tool provided by Apache to create your users file with the user of your choice:
    htpasswd -c D:\\webroot\\turbodbadmin\\users admin

    It will prompt you for the password to create, and creates the file for you, if you want to add other users to your users file just use the same command without “-c” option:

    htpasswd D:\\webroot\\turbodbadmin\\users username
  • Using a text editor of your choice create a new file as D:\webroot\turbodbadmin\.htaccess (notice the dot before the name):
    AuthType Basic
    AuthName "Restricted Area"
    AuthUserFile D:/webroot/turbodbadmin/users
    Require valid-user
  • Finally we have to change Apache configuration to allow AuthConfig, in httpd.conf in DocumentRoot Directory directive, you will find:
    # 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
    

    Which we have to change into:

    AllowOverride AuthConfig

    Restart Apache now and check http://yoursubdomain.no-ip.org:8520/turbodbadmin/ and finally we have our script folder secured.

You can generate your own .htaccess and htpasswd files using .htaccess Tools website, it has some other nice features too.

Summary

After two parts of this article we have a complete WAMP environment, Apache 2, MySQL 5 and PHP 5 installed and working perfectly on our Win32 box, we also installed TurboDBAdmin script as our online graphical interface to administer MySQL, and secured it using Apache security.

In the next part I’ll be talking about Ruby and Rails and how to configure them on Windows as it needs a complete individual post to talk about it.

Comments

8

  1. Rida Al Barazi » Blog Archive » Local Development Environment - Part 3 said..

    [...] After we had our WAMP local server setup done in Part 1 and Part 2, and booting it online via No-IP dynamic DNS service, it’s time now to talk about installing Ruby on Rails on our server and use Apache 2 along with FastCGI as the webserver for the first option and Mongrel for the second, we will also install few ruby libraries that are commonly used and ensure that they are working and functioning properly by installing a ready rails script. [...]

  2. Adam Craven said..

    You’ve missed an important step out for installation of PHP, the configuring of the PHP.ini and MySQL.dll .

    Apart from that, excellent guide so far.

  3. Rida said..

    Thanks Adam for your comment and welcome to my modest website, as for the PHP.ini and MySQL.dll coverage I intended not to go there as the default setup normally take care of everything so it will be better keeping the tutorial as simple as possible and edit such files only when it is required.

    Did you face any problems while installing? I mean were not the default configurations enough? Please let me know so I can update the post to cover such points.

  4. Adam Craven said..

    It was more of a difficulty for people who’ve never done this before, because they’ll overlook it and just follow the tutorial step by step.

    The ‘php.ini’ has an extra extension on it, such as: ‘php.ini.default’. All it requires you do to is remove the default.ini tag and I believe the MySQL.dll was already uncommented (not 100% sure).

    Hope that helps Rida.

  5. Roger said..

    I followed the instructions step-by-step and had zero problems using the files linked to in Part 1. PHP installed perfectly with no errors and I had no problems with MySQL. Moving on to Part 3…

  6. Yortz said..

    Hi Rida, thanks for your wonderful tutorial, i am writing since i had no problems in following part 1 and 2 till the installation of turbodbadmin;actually i unzipped everything in my H:/webroot/turboadmin dir and everything seems to work except for the fact that when i open http://mydomain.no-ip.org/turboadmin it opens the main window and actually i am not able to browse anything, i just got an empty tree on the left and i cannot setup options, create tables and do anything db related through turbodbadmin.
    I’ve also created the .htaccess to protect my dir from the command prompt and modified accordingly the http.conf file in Apache.
    Result is that even if i restart Apache and log into http:/mydomain.no-ip.org/turboadmin it doesn’t ask me for any authentication and just lemme in showing me the empty tree view in turboadmin, if u can please tell me what am i doing wrong I’d appreciate.
    Thanks in advance!

  7. Yortz said..

    Ok, at your convenience Rida, i was reading something on the official turbodbadmin website trying to fixing this weird behaviour, it seems that the reason why i cannot see any db and tables could be due to this:

    http://www.turboajax.com/forum/viewtopic.php?t=19&highlight=empty+dir&sid=6509d7f0b471d9e17f74985cfbd49d4c

    I guess but i am not sure, and then i ‘ve also read this:

    http://dev.mysql.com/doc/refman/5.0/en/old-client.html

    So, after enabling debug into my turboadmin config.js file i browsed to http:/mydomain/turboadmin/troubleshoot

    and at the first check for “Test PHP configuration including db setup” i got this:

    Creating data object…ok
    Listing databases…
    Fatal error: Call to undefined function mysql_connect() in H:\webroot\turboadmin\php\adodb\drivers\adodb-mysql.inc.php on line 348

    my line 348 in the adodb-mysql.inc.php says:

    $this->_connectionID = mysql_connect($argHostname,$argUsername,$argPassword,

    So at the moment i am stuck on authenticating and getting to work correctly turbodbadmin, i know that this doesn’t fall under the explanation of setting up the development environment, but i thaught this could be useful to anybody having my same kind of problems.

    At the moment i am almost wondering to install RoR on Wamp on my system hard drive.

    Hope you can help me to solve my weird behaviour with turbodbadmin.

    Thanks in advance for your precious work in setting up this nice tutorial.

  8. Green said..

    Hi Sam! Photos i send on e-mail.
    Green

Leave a Reply

you can use these xhtml tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Articles Permanent Link