Sunday, March 13, 2016

PHP And MySQL configuration with IIS Server

This blog describes the installation and Configuration of PHP, MYSQL and IIS (Internet Information Services) server for running the web applications.

IIS Installation:

Internet Information Services is a web server from Microsoft. Recently they are supporting to host PHP and MySql applications also.  Here we cannot install all together in a single package as WAMP. We discussed the installation of wamp in one of my previous blogs: Installing the Wamp Server
Here, with IIS we need to install each separately and configure to work together.

IIS is supported in Windows 7 (Professional & Ultimate Editions) Windows Vista (Business & Ultimate Editions) and above. It comes by default with Windows 7.  Please Note: IIS is not supported in Starter, Home Basic, Home Premium Editions.

STEPS TO CHECK WHETHER IIS IS ALREADY INSTALLED IN YOUR COMPUTER:


To Install IIS:

Step 1: 


Step 2: 




Step 3: 


Step 4: 


Step 5: 


Step 6:


Step 7:


If you want you can install later versions of IIS also. (8 or 8.5).  To install all the required packages you can use Windows wpilauncher.exe 

MySql Installation

There are a couple options for installing MySQL on Windows. It can be downloaded as ZIP file, unzipped into the directory of your choice and run via the command line or you can install it as a Windows service with all the bells and whistles. I personally like to run it as a service and let Windows manage things. Whatever option you choose, all the downloads are available from http://dev.mysql.com/downloads/mysql/

I chose the MySQL Installer 5.6 for Windows which installs everything. The installer is 32-bit but installs either the 32-bit or 64-bit version of MySQL depending on your system. There’s also the option to choose a small file that will perform a web installation or the large file if you’re not certain you’ll have a connection available.

I chose the Custom setup type from the first option screen so I could choose which components I wanted on the machine. For this use, the server itself, MySQL Workbench and Notifier, which alerts the user to any change in the server’s status, was enough. I didn’t specifically need Workbench for a joomla installation but it doesn’t take up much room and might come in handy at some point. 



If you’re installing MySQL Workbench, you might need to install the Microsoft  Visual C++ 2013 Runtime in order to complete the installation. The Installer will notify you of this or any other failing requirements and give you the chance to fix them without stopping the installation routine.



The rest of the Installation wizard screens are pretty well self-explanatory. Under Type and Networking, I chose Server Machine since this would actually be a web server and I went with the standard system account for the Windows service screen.

After the installation finishes, it will offer to open MySQL Workbench where you can ensure that you’re able to login to your new database server. Another option is to open the MySQL 5.6 Command Line Prompt from the Start menu and type in the password that you set for the MySQL root account.


You can create the required database using the commands mentioned in MySql User Manual. 

PHP Installation

You can download the Windows PHP files from http://windows.php.net/download  or http://windows.php.net/download#php-7.0 . The non-thread safe edition is required when working with IIS . 
You can download and install the latest PHP version.  I used version 7.0
After you’ve downloaded the PHP files, unzip the package to the directory of your choice on your hard drive. I chose c:\php to keep things simple. 

The package includes a php.ini-production file which you will need to rename as php.ini and copy to your c:\windows directory after making a few changes. This file holds keys and settings, many of which are commented out and can be uncommented to apply specific settings as needed.
In your favorite text editor, uncomment the following keys in php.ini by removing the semi-colon from the beginning of the line and change the settings as follows:

cgi.force_redirect = 0   (around line 753)
fastcgi.impersonate = 1 (around line 780)
Set extension_dir to the ‘ext’ folder in the path where you stored the PHP fies (i.e. ‘C:\PHPext\’). (around 736)
date.timezone should be set to the time zone of your server (around line 926)
The last setting is a string value (without quotes around it, i.e. America/New_York). You can find a list of appropriate values at http://php.net/manual/en/timezones.php.

In order for PHP to function with MySQL, you will also  need to uncomment the following lines in the Windows Extensions section.

extension=php_curl.dll
extension=php_mbstring.dll
extension=php_mysql.dll
extension=php_mysqli.dll

The php_curl.dll extension is to enable WordPress to retrieve and display product news updates. Without it, you’ll see an error message on your desktop every time you log in.

Also you can directly install this with the windows launcher attached above.

Coniguring PHP and MySql with IIS

After you’ve setup PHP, you’ll need to configure IIS to work with PHP.
First verify that the machine has been assigned the role of a web server and that CGI is installed as a service under IIS. On Windows Server, You can do this by opening the Server Manager (not the IIS Manager) and selecting Web Server (IIS) under Roles.  If this option does not exist, right-click on Roles under the Server Manager tree and add it. If Roles option is not found, you can check directly CGI option is selected. 

You need to set
Request path: *.php
Module: FastCGIModule
Executable: (path to your php-cgi.exe file)
Name: PHP

Now you are all set to run PHP, MYSQL applications through IIS. Need to restart the IIS And now create a php file and add the below code:

<?php phpinfo(); ?>

This is a basic PHP command that tells the browser to display all PHP settings. Name the file phpinfo.php and store it in your wwwroot directory. When you enter http://localhost/phpinfo.php in your web browser, IIS should return the PHP settings page. You’ll need to scroll down or search the page to ensure that it has a section for MySQL as shown in the image below.


Installing Joomla

Now you need to install Joomla content management system to run web applications. You can run the attached Joomla.exe

This installs the joomla and webmatrix. Now open the webmatric and open this joomla site in the explorer. 



Now change the settings through configuration.php file present in this directory.  Need to update the correct user name and password. Save this file. Now in the Microsoft Web Matrix, find the port for this site as below:


Click on the site :

 

Note down the port number and now restart the iis and check with the mentioned URL. Installed Joomla website should run.

Now you need to open this port from the windows firewall to access from the other ip addresses.
Firewall needs to be configured to accept incoming calls on TCP Port 80.
1. Go to windows firewall with advance security
2. Inbound Rules -> Action -> New Rule
3. Select Predefined radio button and then select the last item - World Wide Web Services(Http)
4. Click next and leave the next steps as they are (allow the connection)

Now you can access the site with the below url:
http://< ipaddress of the server>:port

That's it Happy Coding.




No comments: