Search Chirayu Software Solutions Blog

Saturday, July 12, 2014

HOW TO INSTALL LATEST PHP AND MYSQL VERSIONS ON WINDOWS SERVER 2012


In this post, we’ll show you how to install PHP and MySQL on a Windows Server 2012 cloud VPS server. This assumes a fresh server build or a server without IIS, MySQL, and PHP already installed.
A popular utility for installing PHP and MySQL applications, among various other tools on Windows machines is the Microsoft Web Platform Installer, or WebPI. While the installation of PHP and MySQL is greatly simplified using this utility, WebPI does not provide the most recent versions of PHP and MySQL. If you run older versions of any software package or utility you are vulnerable to any performance and security issues that are patched or improved upon in newer versions. With WebPI you can only install up to PHP version 5.5.3 (released 7/30/2012), which is several revisions back. Likewise, MySQL version is 5.5. We will be installing the most recent components available, PHP5.5.7 and MySQL Community Edition 5.6.15.
WebPI 1
WebPI 2
Again, it cannot be understated how great a value the WebPI provides; however, to achieve the most up to date versions, we’ll have to do this manually. Plus, you will learn a great deal about IIS, PHP, and even MySQL during the setup and configuration manually. Let’s get started!
Install IIS
Launch Server Manager, and then click “Add roles and features“. Proceed through the wizard selecting Role based installation and selecting your server. In the “Server Roles” section of the wizard, you’ll want to be sure you have ASP.NET 3.5 and CGI components installed. Make any other selections you need for your web server and then finish the wizard.
IIS Role
When completed, restart your computer to finish the installation, then we continue to installing PHP.
Install PHP
First we need to install Visual C++ Redistributable for VS 2012 U4, make sure to select the x86 version. Download the file direct from Microsoft here, then install. If you choose not do this, you will get an error when trying to start php later. There is a dependency on MSVCR110.dll and php-cgi.exe will fail to launch. Pics, because it happens:
dll error
Now, download the latest version of PHP (5.5.7 at the time of this writing), the x64 versions are experimental only, so we’ll go with x86 Non-Thread Safe. Why Non-Thread safe? Explanationhere you will also see an explanation on the left hand margin of the download site here:
http://windows.php.net/download/
For your convenience, here is a direct link to version we need:
http://windows.php.net/downloads/releases/php-5.5.7-nts-Win32-VC11-x86.zip
When the download completes, right-click on the folder and “Extract All…” to the following location “c:\php”.
PHP extract
Next, copy “c:\php\php.ini-production” to “c:\php\php.ini”. Then we need to edit the php.ini to configure a few items so that PHP will run proper on our server. See this post here on the PHP site. You need to look in the “Required directives” section and make changes to your php.ini file accordingly.
Specifically these items:
extension_dir = "path to extension directory" (should be c:\php\ext)
extension = xxxxx.dll (you need to enable any extensions you want to use in the file)
log_errors = On
error_log = "path to the error log file" (usually "C:\inetpub\temp\php-errors.log")
cgi.force_redirect = 0 (required for running under IIS)
cgi.fix_pathinfo = 1 (FastCGI needs this set)
fastcgi.impersonate = 1 (FastCGI under IIS (on WINNT based OS) supports the ability to impersonate security tokens of the calling client. Set to 1 if running under IIS.)
fastcgi.logging = 0 (causes IIS to generate an HTTP 500 exception if enabled)
Also, you should look over the “Optional directives” such as “memory_limit” and “upload_max_filesize” and make any adjustments there. For example if you are going to be running ownCloud, you’ll probably want to increase the upload size to a higher threshold.
Once you have setup your php.ini file to your liking, I highly recommend copying you php.ini file for backup purposes, naming it “php.ini.backup” or something of the sort. I also recommend repeating this procedure anytime you make a change to your .ini file and perhaps adding the date to keep historical reference to any changes made to the file.
Now we need to configure the system variable for php. Access Control Panel > System > Advanced System Settings, Advanced tab, Environmental Variables.
Env Var 1
Edit the “Path” variable and add “c:\php” to the end of the value listing.
Env Var 2
Now we need to setup the Handler Mapping in IIS Manager. Launch Handler Mapping, click Add Module Mapping in the Action panel. Use this screenshot as a guide here:
Add Module Mapping
Now we need to launch the Default Document setting in IIS manager, and then create a phpinfo page. In the Default Document module click “Add…” then specify default.php.
Default Doc
To create the phpinfo page, create a file here: “c:\inetpub\wwwroot\phpinfo.php”. Inside that file, place this text, exactly:
1
<?php phpinfo(); ?>
Now issue an IIS reset, then browse this page here on your server:
http://localhost/phpinfo.php
Your screen should look something like this:
phpinfo page
To make life a little easier for managing PHP on IIS, you can also install PHP Manager for IIS from codeplex. In fact, I highly recommend it. It will advise if you have any potential issues with you php.ini file and even give you suggestions on resolving them.
Note – This requires that you have .NET 3.5 Framework installed.
PHP Manager
If you are unable to see the PHP Manager applet in IIS Manager after installation, your server may have a pending reboot. This is usually caused by not rebooting after installing ASP.NET 3.5 earlier in the process.
At this point your PHP installation is complete! Let’s move on to MySQL.
Install MySQL
This part of the guide is perhaps the easiest. Download the latest community server, the downloads page is here:
For your convenience, the direct download link to latest version as of this writing is here:
http://dev.mysql.com/get/Downloads/MySQLInstaller/mysql-installer-community-5.6.15.0.msi
Once downloaded, launch the installer and begin the installation. It is very straightforward. I recommend installing MySQL Workbench to manage your MySQL database locally via the application. Some people do not recommend this; however the choice is up to you.
I chose a custom installation:
mysql 1
I chose to install the server and workbench:
mysql 2
You will most likely have to install another Visual C++ component here. Do so and continue with the installation.
mysql 3
Continue to follow the wizard, complete the server installation on the next page. On the page after the installation, you’ll have the option to configure the firewall rule and select the configuration type. If you are installing IIS, PHP, and MySQL, most likely you will want to choose the Server machine config. If you are running MySQL standalone, Dedicated would be a better fit.
mysql 4
On the next page, set a root password. Make extra sure you have this password documented properas you will need this password later. Then on the following page, make sure you configure MySQL to run at startup. Also if the service needs to run as a dedicated user, configure that here.
mysql 5
On the next page, configure the logging to your preferences and then complete the wizard. If you chose to install MySQL workbench it will launch after installation and you are ready to manage your server!
mysql 6
At this time I would recommend performing a computer restart, and then running Windows Update to ensure you have all the proper security patches up to date.
This completes our guide on the installation of IIS, PHP, and MySQL. Thanks for reading.
Want to try this out on Windows cloud VPS hosting? Here are our Windows VPS plans and prices. Signup now and be online in just a few minutes!
Post a Comment