Home > Apache, Perl, PHP, software > INSTALLATION 2014: APACHE2.2, PHP5.4 and MYSQL5.6

INSTALLATION 2014: APACHE2.2, PHP5.4 and MYSQL5.6

December 26th, 2014

 

APACHE HTTP SERVER 2.2.25
apache logoPHP 5.4.27
php logoMYSQL 5.6.14
mysql logoFOR WINDOWS 8, 7, AND XP

 

INTRODUCTION

Installing AMP (Apache/MySQL/PHP) on Windows is not a difficult task, however, it is not that straight forward, either.

 

After all the steps of this tutorial, we’ll be able to host our web site on our PC running Windows. We can display our php page by typing URL like http://www.mycompany.com/index.php into the browser. We are hosting our web site! We also will have access to MySQL database.

 

SITE FOR DOWNLOADS
    1. Go to Apache Http Server 2.2.25
      Click Binary.
      Then, download -(MSI Installer): httpd-2.2.25-win32-x86-openssl-0.9.8y.msi

 

    1. PHP 5.4.27
      VC9 x86 Thread Safe (2014-Apr-03 06:32:22): php-5.4.27-Win32-VC9-x86.zip
      We may also need Microsoft Visual C++ 2008 SP1 Redistributable Package (x86) for this PHP and Apache combination.

 

  1. MySQL 5.1.50
    mysql-installer-web-community-5.6.14.0.msi

 

STEP 1. APACHE 2.2.25 INSTALL
    1. Run the Apache installer package, “httpd-2.2.25-win32-x86-no_ssl.msi”
    1. Click “Next”.apache installer
    1. In the “Server Information” dialog box, enter localhost (without the quotes) for the Network Domain as well as for the Server Name and whatever email address we wish for the “Administrator’s Email Address” field.
      The installer uses the information we enter to create a default Apache configuration file for us. We can always go back and manually change these values in our configuration file if we change our mind later.
      Leave the default setting of for All Users, on Port 80, as a Service as it is. Click “Next” when we’re done.Server Infomation
    1. When asked about the Setup Type, select “Typical” and click “Next”.Typical Setup
    1. In the Destination Folder dialog, allow the installer to install to the default folder. So, just click “Next”Destination Folder
    1. Finally click the “Install” button to allow the installer to set up Apache.Apache Install ButtonWhen it is done, click the “Finish” button.

    1. Once Installation is complete, verify the installation by clicking on the Apache Icon in the taskbar (far left), as shown below.Task Bar(note) There may be a problem related to port:80, then we may want to restart our machine.
      We can also verify our installation of Apache by opening http://localhost/ in our browser. Or we can just type in “localhost” for the URL.

It works!

  1. Congratulations for a successful installation of Apache. We still have to configure Apache, but we will do it in the later steps.
STEP 2. PHP 5.4.27 INSTALL AND CONFIGURATION
    1. Extract PHP package
      Now it’s time to install PHP5. Open the zip file & extract all our files to C:\php. Navigate to C:\php
    1. Make php.ini file
      Rename php.ini-development to php.ini
    1. Edit the php.ini file
      • Edit 1
        Find extension_dir = “./” and replace it with

        extension_dir = "C:/php/ext"
      • Edit 2
        We’re going to uncomment by removing the “;” from the extension to activate it.
        Here are the extensions to be uncommented.
        Search for each one them and remove the semicolon “;”

        ;extension=php_gd2.dll 
        ;extension=php_mbstring.dll 
        ;extension=php_mysql.dll 
        ;extension=php_mysqli.dll 
        

        The First extension enables the Image GD library of PHP.
        The Second enables mbstring.
        The Third and forth enables us to use MySQL database.

        Save the php.ini file.

    1. Setup PHP Environment
      Let’s setup the PATH environment variable.
      Start->Control Panel->System->Advanced System Settings
      then go to the Advanced tab, click on the Environmental Variables button,
      then scroll down in system variables to find PATH,
      Edit it Add C:\php;
    1. Restart the System
      We must reboot a windows system after setting the Path variable.
      If we move on past that point without rebooting apache may have trouble finding our MySQL extensions.
      Now we have PHP configured.
  1. Let’s move on to configuring Apache.
STEP 3. APACHE CONFIGURATION

Go to
C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\

We may need to turn off UAC for editing.

    1. httpd.conf Editing
      • Edit 1
        Uncomment:

        #LoadModule rewrite_module modules/mod_rewrite.so 
        =>
        LoadModule rewrite_module modules/mod_rewrite.so
      • Edit 2
        Add the following below the previous edit

        #PHP5
        LoadModule php5_module "C:/php/php5apache2_2.dll" 
        PHPIniDir "C:/php"
        

        Note: We may get “Apache :: The Requested Operation has Failed” when we try to restart Apache, one of the reason may be a mismatch between php and Apache. While I am writing this, php 5.5.5 is available, and it has php5apache2_4.dll. So, I lowered the version 5.4.27, and then, everything seemed to be working fine.

      • Edit 3
        Search for

        AddType application/x-gzip .gz .tgz

        Add the following below the searched line. The lines define a MIME (Multipurpose Internet Mail Extensions) type for files ending with a file extension of .php and .phps so they will be processed by the PHP parser on request.

        AddType application/x-httpd-php .php 
        AddType application/x-httpd-php-source .phps 
        
      • Edit 4
        Search for

        DirectoryIndex index.html

        Replace it with

        DirectoryIndex index.html index.php 
        
      • Edit 5
        Uncomment:

        #Include conf/extra/httpd-vhosts.conf
        =>
        Include conf/extra/httpd-vhosts.conf 
        
    1. Virtual Hosting SetupNote: we can skip this step. But in that case, we may want to comment the line (we did uncomment in the previous section Edit5), otherwise we may have permission issues:
      Include conf/extra/httpd-vhosts.conf 
      ==>
      #Include conf/extra/httpd-vhosts.conf
      

      We are about to make our server to host our domain for Apache Development project.
      We can name our own but here I am going to use apacheserver.dev as a domain name.
      So, after we finished this step, we’ll be able to type in our URL on the web browser:
      http://www.apacheserver.dev/,
      then we get our home page from the http server installed on our machine.
      But we need to setup the directory structure to realize the Virtual Hosting.

      • Directory Tree Setup
        Make directory:

        C:/server/www/apacheserver.dev/public_html
      • httpd-vhosts.conf Editing
        Open the file in:

        C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\extra

        Replace the contents with

        <virtualhost *:80> 
        DocumentRoot "C:/server/www/apacheserver.dev/public_html" 
        ServerName Apacheserver.dev 
        ServerAlias www.apacheserver.dev 
        <directory "C:/server/www/apacheserver.dev/public_html"> 
        AllowOverride All 
        Options Indexes FollowSymLinks 
        Order allow,deny 
        Allow from all 
        </directory> 
        </virtualhost> 
        
      • Apache Webserver Restart
        Let’s restart Apache server and check if it restarted successfully.

.

STEP 4. PHP TESTING WITH APACHE

In the previous step 3, we made directory structure,
C:\server\www\apacheserver.dev\public_html\.
This is where we will be putting all our html and script files and our webserver will use those files.

Let make a php file and name it index.php
and put it inside the C:\server\www\apacheserver.dev\public_html\ directory.

If you skipped the vhost setup, then the index.php should be place under C:\Program Files\Apache Software Foundation\Apache2.2\htdocsdirectory.

<?php phpinfo(); ?>

Then type localhost as URL for our browser. Then, we’ll get the information about the PHP we’ve just installed.
PHP Infomation

NOTE

This is a note for the case when php is not running. This sounds strange and it rarely happens, especially, when I reinstall apache. In this case, we may get a warning message something like this:

PHP Warning:  PHP Startup: Unable to load dynamic library 'C:\\Program Files\\PHP\\ext\\php_openssl.dll' - The operating system cannot run %1.\r\n in Unknown on line 0 ...

The fix for this:

So I copied libeay32.dll to the Apache2.2/bin directory. Problem solved. No error messages and running phpinfo confirms that OpenSSL is present and enabled.

How does it fix the issue? I haven’t look into it but it works.

STEP 5. MAKING WINDOWS RECOGNIZE HTTP://WWW.APACHESERVER.DEV

This step is not necessary, but it’s a nice feature to add.

To make Windows recognize our domain on Apache webserver,
we need to edit hosts file in C:\Windows\System32\drivers\etc directory.

Add the following two lines to the hosts file.

127.0.0.1 	apacheserver.dev
127.0.0.1 	www.apacheserver.dev

Then type in apacheserver.dev or www.apacheserver.dev as an URL,
then we’ll get the same php information as when we type in localhost as an URL.

STEP 6. MYSQL INSTALL
  • Double-click the MySQL installer mysql-installer-web-community-5.6.14.0.msi.MySql Setup WizardMySql Setup Wizard

    MySql Setup Wizard

    Then click the “Execute” button.

    STEP 7. MYSQL CONFIGURATION

    Configuration process is straight forward:
    Configuration

    Configuration2

    Configuration3

    Configuration4

    Complete

    STEP 8. MYSQL WITH APACHE AND PHP

    Type in localhost into the URL input box of our browser. Scroll down the page, and if we get the following information from phpinfo() output, MySQL is on our system.
    MySQL Info

    STEP 9. CONGRATULATIONS!

    We’ve got all three, Apache, PHP, and MySQL!

    STEP 10. LET’S ENJOY THIS MOMENT FOR A WHILE

    We know we successfully installed for our MySQL projects. As a final step, we want to check they are talking to each other. So, let’s check our development environment is indeed successfully built. To do that, we’re going to execute a PHP script which supposed to talk to MySQL server running on our system. The script file name is mysqlAvailability.php and we may want to put it intoC:\Server\www\apacheserver.dev\public_html directory:

    <html>
    <head><title>MyQSL, talk to me.</title></head>
    <body>
    <h2>
    
    <?php
    $connection = mysql_connect("localhost", "root", "bogopass")
    or die ("Sorry, MySQL is not talking to us");
    echo ("Congratulations, MySQL started talking to us!");
    ?>
    
    </h2>
    </body>
    </html>
    

    Whe we put http://localhost/mysqlAvailability.php into a browser address field, the PHP parser executes the script code, and the following comes up if everything works.
    mysql_talk_to_me

    MySQLWorkBench.png

 

 

 

Apache, Perl, PHP, software , ,

  1. Hans
    January 20th, 2015 at 07:54 | #1

    each time i used to read smaller articles or reviews
    which as well clear their motive, and that is also
    happening with his piece of writing which I am reading
    here.

  1. No trackbacks yet.