24 Sep

Installing a Web Server with PHP and MySQL

Whether you’re a budding web developer or a jack-of-all-trades administrator, sooner or later you’ll need to know how to get a web server up and running.

Most web servers these days run either Windows or Linux. Windows may be your choice if you’re making use of a server in an existing domain or perhaps integrating with NTFS, Active Directory or other Windows API’s – but for a dedicated, light-weight, secure and free platform; you can’t go past Linux.

Of course, there’s not just the operating system. You need to consider the HTTP Server itself, that is; Apache or Internet Information Server (IIS). Apache is the tried and tested platform and most open source PHP applications (like WordPress, Joomla etc.) are built to run natively on Apache, as they use per-folder .htaccess directives for URL re-writing.

Suffice to say (and without getting too far off-topic), If you strictly (simply?) want to run Apache/PHP/MySQL on Windows we would recommend the XAMPP bundle. The installer is easy to step through, there’s lots of support on the Apache Friends website and it’s likely the fastest path to getting these kinds of applications up and running on Windows. Conversely, if you need to implement .htaccess directives in IIS – you can do that too! These files can be converted using IIS Manager and Microsoft has a complete write up on converting these directives to web.config files for IIS.

This article will cover both CentOS 6.5 Linux with Apache and Microsoft Windows Server 2012R2 with IIS,  so you can experiment with both platforms and see which one is right for you.

Lets get started!


Windows Server 2012 R2 with IIS, MySQL and PHP  (WIMP)


Assumedly, you already have a licensed copy of Server 2012 R2, else if you’d like to trial it for 180 days; you can download it here.

IIS is installed by adding the ‘Web Server (IIS)’ role via Server Manager. Server Manager starts by defaut when you first login to Windows Server 2012 R2.



Once IIS is installed, download and run the Microsoft Web Platform Installer.

It will setup your IIS install with PHP, MySQL, FastCGI module and WinCache extensions and save you heaps of time and fuss. (…and you thought this was going to be a long, complicated thing huh?)

Select MySQL Windows 5.1, PHP 5.6.0 and PHP Manager for IIS.


The ‘PHP Manager for IIS’ management console is a nice touch, as you can change all the php.ini parameters, enable/disable extensions etc. right in the management GUI.


The binaries that the installer downloads will require the Visual C++ Runtime Libraries. So grab them and install those as well. If you’re stuck wondering why IIS isn’t parsing any php code – that’s probably why.

Reboot the server and test your installation.


CentOS 6.5 Linux with Apache, MySQL and PHP  (LAMP)


Firstly, fetch the latest CentOS-6.5-x86_64-bin-DVD1.iso from one of their mirrors.

Boot the ISO and follow the prompts to install CentOS. Select one of the “server” configurations (e.g. Basic Server). Most defaults should get you going. You can configure the network settings and operating system features (packages) from within the installer, but for the most part the defaults should get you to where you need to be.

Once the server is installed and rebooted you’ll land at the login prompt.

Login as root. If the network was configured correctly you can go straight to updating packages, else you’ll need to configure your network first.

Either launch the network configuration utility

or Set the network settings manually with vi
(for a quick refresher on using the vi editor, look here. TL;DR? Press ‘i‘ to start editing, ‘ESC :wq‘ to save and quit, and ‘ESC :q!‘ to quit without saving.)

then restart and initialize the network.

Test your network by pinging the address you configured. If for some reason your network adaptor still isn’t active, check the manual config method above and ensure the ONBOOT=yes value is set and then reboot the server. Further troubleshooting steps can be found here.

Update packages (I like to run this twice, just to be sure everything is up-to-date.)

Install Apache, MySQL, PHP and archive bundles.

…and any useful PHP extensions

Start Services

Set Services to start automatically

Secure MySQL. Set a root password and accept recommended defaults

Allow ports 80 and 443 through the server’s firewall

Add the following lines above the “-A INPUT -j REJECT …” line

Restart and initialize the firewall

That’s it!

For HTTPS/SSL access, further instructions can be found here.


Testing your Installation


For Windows and IIS, content goes in the C:\inetpub\wwwroot folder.
For Linux and Apache, content goes in the /var/www/html directory.

Create a text file called index.php in the respective folder and remove any existing content in those folders.

Edit the index.php file and type in the following code…

Save the file and point your web browser at the server – you should hopefully see something like this!


If so… Congratulations, you’re up and running!

If not, here’s a few places you might like to start troubleshooting…

  • Check your network settings on the client and server.
  • Reboot the web server.
  • Windows: Check you have the appropriate Visual C++ Runtime Libraries installed.
  • Linux: Double check the firewall rules as described above.
  • Replace the index.php with an index.html file containing the plain text “Hello World!” .. if this works then the web server is working and you know your problem lies in the PHP implementation…

Good Luck!

Related Posts