Building an Apache Web Server

Installing Apache and PHP

Assuming you’ve logged onto the new VM as yourself, issue the following commands:

sudo apt-get install apache2 php5 unzip make binutils
sudo /etc/init.d/apache2 restart 
sudo nano /var/www/phpdata.php

The first command will cause you to be prompted for your password again, after which about 30MB of software will be downloaded (so make sure your Internet connection is working!)

The second command is how we restart the Apache web server. I do it so that I’m certain the Apache server has picked up the fact that PHP has been installed.

The final command simply uses the nano text editor to create an empty text file in the /var/www directory (which is your new web server’s root directory). In that file, you type the following:

<?php
phpinfo();
?>

Be careful of spacing and so on here: you need to type exactly what’s here. Throw an extra space between the ‘?’ and ‘php’ in the first line, for example, and the thing won’t work. All we’re doing at this point is creating a file called phpdata.php which, if called by a remote web browser, will invoke the ‘phpinfo’ function to display the details of how PHP is configured. If we see configuration when we visit this new ‘web page’, therefore, we’ll know everything is working as advertised.

Just before we do that, however, we first need to know precisely what address to type in our remote web browser: the Ubuntu installer defaults to using DHCP so we don’t yet know what IP address our server has been assigned. At the command prompt, therefore, type the command:

ifconfig

…and you should see something like this:

The bit which reads inet addr is your IP address. In my case, it’s 192.168.0.37 -but it all depends on the vagaries of your DHCP server. Once you know what IP address you’re using, switch back to your physical PC, open a browser and type in the address:

http://<your IP address>/phpdata.php

If all has gone according to plan, you’ll see something like this:

Once you see something like that, you know (a) Apache is working and (b) PHP has been installed correctly. You’ve got yourself a working web server. All that remains, for this article at least, is to make it useful!

One thought on “Building an Apache Web Server

  1. Pingback: Installing Apache on centos 6 | DIASPAR WAS NOT ALWAYS THUS

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>