OpenSource For You

Setting Up Apache and PHP on Windows

Developers can easily run or test their scripts in Windows before they put them out on the Internet, if they have Apache and PHP installed on their systems. This article is a tutorial on how Apache and PHP can be set up in Windows.

-

Web servers are computers that are usually set up in a facility called a data centre. These servers are maintained and operated by hosting companies, to store websites, so that people can visit them on the Internet. The files stored on a Web server are read by browsers, which convert these files into images and text for viewing. Your browser communicat­es with the Web server to bring you informatio­n from the Internet. The purpose of Web servers is to serve files, as requested. A server can send the same file, or a different one, to hundreds of users at the same time.

Web server software

Web servers typically run two types of operating systems —Linux or Microsoft Windows. Most of the Web servers today operate on Linux and most websites are hosted by Linux servers. It is confusing that these software programs are also referred to as servers. So you must distinguis­h between servers that refer to hardware and those that refer to software. Web servers also run other software programs in the background. Such software is useful for creating websites.

Basically, the Web server software receives your request to access a Web page. It runs a few security checks on your HTTP request and takes you to the Web page requested. Depending on the page you have requested, the server may be asked to run a few extra modules while generating the document to serve you. It then serves you the document you requested. The process is an example of the client/server model. All computers that host websites must have Web server programs and Apache is one such program.

An introducti­on to Apache

Apache is the most widely used Web server software. Developed and maintained by the Apache Software Foundation, it is open source software available for free. It can be highly customised to meet the needs of diverse environmen­ts through the use of extensions and modules. Most WordPress hosting providers use Apache as their Web server software.

The Apache HTTP server is software (or a program) that runs in the background under an appropriat­e operating system; it supports multi-tasking, and provides services to other applicatio­ns that connect to it, such as client Web browsers. It was first developed to work with Linux/UNIX operating systems, but was later adapted to work under other

systems, including Windows and Mac. The Apache binary running under UNIX is called HTTPd (short for HTTP daemon), and under win32 is called Apache.exe.

In this tutorial, we will install Apache and PHP in Windows in order to run your system as localhost (server). The system prerequisi­tes to do so are:

Download and install Visual C++ redistribu­table 2015 Download Apache24

Download PHP 5.6

Downloadin­g and installing Visual C++ redistribu­table 2015

Let’s first install Visual C++ redistribu­table. The earlier packages like Visual C++ redistribu­table 2012 will give an error of a missing vcruntime1­40.dll file; so it would be better if the newer version, Visual C++ redistribu­table 2015, is installed, which will solve most of the issues. Most computers nowadays have it pre-installed. Neverthele­ss, I will lead readers through the step-by-step procedure of the installati­on.

First, download Visual C++ redistribu­table 2015 from the Windows official site.

Next, download the preferred version, i.e., if your system is 32-bit then download the x86 version, or download x64 for a 64-bit system. Proceed to install after the download is complete.

Installati­on wizard of Visual C++ redistribu­table 2015

Read the terms and conditions of the licence, click on the tick mark to accept these, and then click on Next. Click on Close when the installati­on finishes.

Downloadin­g and installing Apache

We can download the latest version of Apache from https:// www.apacheloun­ge.com/download/. Download it based on your system’s requiremen­ts (32-bit or 64-bit).

Extract it and put it in the C:\ folder.

Downloadin­g and installing PHP

Download PHP from http://windows.php.net/download. In the dropdown, Binaries and Source Releases, there will be many versions of PHP. The latest release is PHP 7, but I strongly suggest that you download PHP 5.6 because it is more common and will be installed in most of the servers and by the hosting services providers. You can use PHP 7 in the future but, as of now, we are coding something so we can continue with the PHP 5.6 thread safe release.

Download the Zip file and unzip it. Place it in a newly created folder named PHP inside the C:\ drive.

Running Apache and PHP in your system as localhost

Let’s access the Apache24 folder that we moved to the C:\ drive earlier. Then, get into the conf folder and edit the httpd. conf file using Notepad or your favourite text editor.

Scroll down to the bottom of the file and add the following lines:

Next, find DirectoryI­ndex (you can use Ctrl+f) and change index.html to index.php.

What we are doing here is telling Apache that the first file we need is a PHP file and not an HTML one. Save the changes.

Now, search for ServerName (Ctrl+f ). Initially, it is commented; so uncomment it. We are changing this because we will use it for our browser search. Instead of

 ??  ??
 ??  ?? Figure 1: Visual C++ redistribu­tion installati­on step 1
Figure 1: Visual C++ redistribu­tion installati­on step 1
 ??  ?? Figure 3: Change in DirectoryI­ndex
Figure 3: Change in DirectoryI­ndex
 ??  ?? Figure 2: Visual C++ redistribu­tion installati­on step 2
Figure 2: Visual C++ redistribu­tion installati­on step 2
 ??  ??

Newspapers in English

Newspapers from India