A local webserver is an absolute necessity for all people coding and using databases to test their applications before they are implemented online. If you’re coding ASP/.NET you’ll need Microsoft’s IIS (Internet Information Server) to run on your local machine. If you’re coding PHP it is likely you will run Apache. This article shows you how to setup a local environment to work with PHP and MySQL databases.
On the contrary of what people think, setting up a local ‘fake’ webserver to code and test on is pretty easy. There are a variety of packages out there you can use. For this article I have chosen XAMPP. Xampp is a software package that includes webserver software, PHP, MySQL and various other services. Know that installing the latest version of this software is rarely any good. Not only are most open source applications not ready for it, you’re at risk that your code won’t work online because most hosting companies are not up to date with these latest versions either.
To find out what your webserver is running:
Create a new file with notepad and call it “info.php”. In this file, write the following:
< ?php phpinfo(); ?>.
Upload it to your webserver and call the file. This will give you very elaborate information on PHP, MySQL, Apache version numbers.
Installing XAMPP
Download Xampp for Windows with the version number closest to that of your webserver and install it. The installation process isn’t difficult. It will ask you a couple of times if “you want to install ‘x’ as service”. Just say yes to each of those. After the installation is complete point your browser to: http://localhost. If everything went well, you see a website pulled up “XAMPP“. Choose your language to continue.
So far you are now able to code PHP on localhost. You must place all pages you make into “htdocs” [C:\Program Files\Xampp\Htdocs] or make subdirectories within htdocs. If you want to work with databases, we’ll need to configure some more. It is advised you do this step anyhow, because of security.
Configuring PHPMyAdmin/ MySQL
On Xampp’s main page menu, there is an option called PHPMyAdmin. This is the tool you use to manage your databases. If you enter it, you’ll get a few messages saying that it’s insecure to use. These messages we are going to fix.
1. Go to “Priveleges“.
2. Edit the user root.
3. Give the user root a password.
4. Shut down browser.
5. Find a file on your hard disk named config.inc in the directory xampp/phpmyadmin.
6. Open this file to edit it.
7. Find the line $cfg['PmaNoRelation_DisableWarning'] = FALSE;. Set it to TRUE.
8. Find the line $cfg['Servers'][$i]['auth_type'] = 'config';. Replace config by ‘http’.
9. Save the file.
10. Open your browser, point it to http://localhost/phpmyadmin.
11. A password dialog will show up. Insert the username (in this case ‘root’) and your chosen password.
You are now ready to use ‘localhost’.