Setting up IIS, PHP and MySQL on AWS EC2 Windows Server


Today we’re going to setup a Windows server on IIS with PHP, MySQL and OpenSSL, enabling you to configure and host public websites with encrypted connection. I’ve divided it all in 5 simple steps after which you can start working on it easily and instantly.

Objective: Launching a Windows Server on AWS, Enabling and Configuring IIS for Public Website Hosting with PHP and MySQL.

  1. Launching Windows Instance
  2. Enabling IIS Server and Required Features
  3. Installing Additional Tools Required
  4. Testing PHP and MySQL Connection
  5. Bonus: Setting up OpenSSL for Websites

1. Launching Windows Instance

Log into your AWS Panel (or Sign Up) and from Services menu, open EC2 Panel. From Dashboard pane click Launch Instance and search for Windows Server, you can select any preferred base variant (better without Containers or SQL Server if not required by your app as we’re already going to add MySQL later).

EC2 Instance Launch Wizard

2. Enabling IIS Server and Required Features

Open Server Manager > Add Roles and Feature
From Add Roles and Features Wizard > Features > Web Server IIS (ref. to screen below)

List of Windows Server Features Installing

Either download tools on your PC and move to your server or on your server open Internet Explorer > Internet Options
Security Tab > Internet > Custom level
Security Settings - Internet Zone (window) >
Downloads > File download > Enable
Miscellaneous > Access data sources across domains > Enable
Scripting > Active Scripting > Enable

Now, from Server Manager > Tools open Internet Information Services (IIS) Manager
IIS Manager’s Action Sidebar > Click on Web Platform Components Link and Install the extension.

3. Installing Additional Tools Required

Download and install the latest PHP Manager for IIS from GitHub.
Restart IIS Manager.
Select Server from Connections > Featured View > Open Web Platform Installer
Search for “PHP” and add the latest variant in the installation queue, from Items to be installed, remove PHP Manager (as we’ve installing it separately).
Search for “URL rewrite”, add it and start installation.

4. Testing PHP and MySQL connection

Open PHP Manager > View recommendations and update the requested values and click OK.
Now click on Check phpinfo() with default Website, if everything goes well, you’ll see this output.

Getting PHP Output

Open location "C:\inetpub\wwwroot\" and place your PHP website/script in the directory. Or you can change the Physical path from IIS Manager > Sites > Your Website > Actions > Basic Settings > Physical path.

Now let’s download MySQL installer for Windows and select what features/products you want to install, we need MySQL Server only. If you want to visualize your database, select Workbench also. Once installation and setup (credentials form) is complete, we’re ready to test the connection.

Create a PHP test script with following code:

// credentials
$server = "localhost";
$user = "username";
$pass = "password";

// create connection
$conn = new mysqli($server, $user, $pass);

// check connection
if ($conn->connect_error) {
die("connection failed: " . $conn->connect_error);
echo "connected successfully";

If you see successful connection message, we’re good to go to launch our localhost projects.

5. Bonus: Setting up OpenSSL for Websites

OpenSSL is a great way to encrypt your website and secure end to end data for your users. OpenSSL supports a number of different cryptographic algorithms: Ciphers. AES, Blowfish, Camellia, Chacha20, Poly1305, SEED, CAST-128, DES, IDEA, RC2, RC4, RC5, Triple DES, GOST 28147-89, SM4.
This step is not for localhosts.

Download Win ACME Pluggable version and place the extracted files on your server. Now run file "wacs.exe".

Windows ACME Launch Screen

Choose the first option by entering letter "N". Then select the website you want the SSL for, by keeping everything recommended. You can still choose either to go with single and all website bindings. Best way to renew the certificate is to keep it in the memory and let the program update the SSL itself.

Add Comment