Installing a Web Server with PHP

Simple Home Web Server

website hosting

Web server is an application that is usually installed on a dedicated computer. The purpose of such application is to listen for web requests and serve web pages, images and other files. When we use a browser to browse the web, our browser and computer communicate with remote web server where the pages are stored and download them from there.

Web servers as dedicated computers are mainly located at web hosting companies like Hostgator. Dedicated web hosting companies serve most of the websites we usually visit. However, some web servers are also located at companies. They are used to serve private websites to the outside world or just for internal purposes like intranet. But a web server can be installed also at home on almost any computer.

Home Web Server

desktop pcYou can use such web server for web development or for serving some real web pages. This is easier than most of people think. It means only installing a suitable server package and putting pages or corresponding web files into appropriate directory where they can be accessed. Usually, web server (Apache) application is not enough. Most websites also need PHP preprocessor and MySQL database. Fortunately, there are many packages that contain everything needed to run a website.

The first choice is AMP web server package that is available for Windows (as WampServer), MAC (as MAMP, Linux (as LAMP) or Cross-platform (as XAMP).

Another solution for Windows is EasyPHP:

ampInstallation of Apache–MySQL–PHP package is pretty simple - just follow the instructions that come with the package. After the installation is finished you should get a working web server. To check if it is working simply type the IP address in the address bar of the browser - something like http://127.0.0.1/ (127.0.0.1 is the IP address of the local computer you are working on - local loop address). If you have installed web server on another computer then you will have to replace 127.0.0.1 with IP address of that computer. You should get the content of the www directory or some default welcome page.

Once the web server is installed you can put your files (html, php, css, js, jpg, etc.) into www or some other directory used by the server. These files are immediately accessible with the web browser (Firefox, Chrome, Explorer, etc). Some websites will also need MySQL database. You can easily configure it by using phpMyAdmin. This is a free software tool intended to handle the administration of MySQL over the web. Usually it is already installed by the AMP package.

Troubleshooting

If you dot get the welcome page or empty directory there are few things that can prevent your web server from working. First check if there are any error messages present in the installation log file or displayed when you start the server.

If there are no obvious error messages you should check if firewall is blocking your web server. If this is the case you will have to enable it for network access.

Another common problem is using some application that also implements web server and uses port 80 (Skype is one such application). 80 is the default port for web and you should leave it as it is unless you know what you are doing. You must first find out which application is causing conflict. Try to close all suspected applications until your web server runs without errors and you are able to access its pages. An alternative solution is to set different port either for web server or other application that uses default port 80. If you change port number, for example to 8080, your pages will be located at http://127.0.0.1:8080/

The final check if your webserver is working properly is to create a simple text file with some text. Name this file index.php and put it into the www dierctory of your server (check web server documentation for details). When you navigate to your server address you shoud get a web page with your text.

windows mac linux

You can also access your web pages from the Internet. All you have to do is to configure your router to redirect port 80 on the WAN port to the port and IP address of the computer where your web server is running. Check router documentation for details.