There are many programs to do a majority of the hard work such as installing and configuring PHP, MySQL, and PHPMyAdmin so we should start there.
I suggest using WAMP as it has interchangeable components and is fairly easy to setup.
Installing WAMP
» Download and install WAMP – https://www.wampserver.com/en/download.php
I find it easiest to install WAMP to the suggested directory of C:wamp as your final “web” folder will be C:wampwww.
We will need to make a few changes after it has finished installing to emulate a web server a little more.
We can start by creating a folder called “example.com” in the C:wampwww folder to store the files we are testing.
Inside the example.com folder create a file called index.php and insert some random data such as “hello world” so we can see if it’s working or not.
Allowing Virtual Hosts
Allowing virtual hosts will enable multiple websites, or hosts, to run from one machine so we need to enable it in the httpd.conf file.
- Click the WAMP icon in your taskbar
- Click Apache
- Click http.conf to open the file
- Find:#Include conf/extra/httpd-vhosts.conf
- Change to:Include conf/extra/httpd-vhosts.conf
Now we have allowed virtual hosts we can create a fake website to test on so we need to tell Windows we want to see our fake domain.
Editing the hosts file
The file we need to edit is protected; it is easiest to copy the file to the dekstop then edit and copy it back, replacing the original.
Find and edit:
C:system32driversetchosts
Adding the following to the very last line of the file:
127.0.0.1 example.com
This will make sure example.com is loaded from our computer instead of the remote website.
Note: We can also copy the above line with www.example.com but it’s good practice to test offline with non-www and online with www urls.
Setting up virtual hosts
Next we need to tell PHP and associated software where the files are located on our computer and where to store the error and access files, so we need to edit another file.
Find and open:
C:wampbinApache2.2.17confextrahttpd-vhosts
Adding the following to the bottom of the file:
<virtualHost *:80> ServerAdmin admin@example.com DocumentRoot “C:/wamp/www/example.com” ServerName example.com ErrorLog “C:/wamp/logs/example.com-error.log” CustomLog “C:/wamp/logs/example.com-access.log” common </virtualHost> <virtualHost *:80> ServerAdmin admin@example.com DocumentRoot “C:/wamp/www/example.com” ServerName example.com ServerAlias www.example.com ErrorLog “C:/wamp/logs/example.com-error.log” CustomLog “C:/wamp/logs/example.com-access.log” common <directory “C:/wamp/www/example.com”> Options Indexes FollowSymLinks AllowOverride all Order Deny,Allow Deny from all Allow from 127.0.0.1 </directory> </virtualHost>
The above code will tell PHP, MySQL and PHPMyAdmin where the files are located on our computer. It handles both www and non-www urls but we won’t need both yet.
Wrapping up
The final step is click the WAMP taskbar icon and then “restart all services”.
Typing https://example.com in your browser should open our example “hello world” page
Typing https://www.example.com in your browser should show the official test page, which is useful for testing purposes if you plan to get a little more involved with coding.