Making it Static
The final thing I guess I should mention is the fact that it’s not such a great idea to have a server -any server, whether database or web- get its IP address via DHCP. It’s not so bad if you set up lease reservations by MAC address so that you are certain the same IP address will always get served to the same machine, but otherwise you’re at risk of the IP address changing every time you reboot the thing, which means pointing a remote browser at it becomes problematic!
It makes more sense, then, to make sure your VM is using a static IP address, rather than a dynamic one. You do that logged in to your VM as root and issuing the following command:
nano /etc/network/interfaces
At the moment, that file probably has a couple of lines in it which read:
auto eth0 iface eth0 inet dhcp
You need to edit this so that it ends up looking something like this instead:
iface eth0 inet static address 192.168.0.37 netmask 255.255.255.0 network 192.168.0.0 broadcast 192.168.0.255 gateway 192.168.0.1
- Line 1 states simply that you want to set the eth0 network interface statically.
- Line 2 specifies the static IP address you’re assigning to this VM -I suggest you use whatever IP address has already been assigned via DHCP, because by definition that must be an address that no other machine on your network is currently using. That’s why in this example, you see me specifying the same IP address as was displayed with the ifconfig command back on page 4. If you want to pick your own, feel free -but it needs to be (a) unique and (b) compatible with other addresses on your network if you want them to be able to communicate with each other. If all other PCs are using 10.0.1.x addresses, for example, then setting a new one to 192.168.0.5 would be a daft thing to do.
- Line 3 is the netmask you want to use for this network segment: it was again visible in the output from ifconfig back on page 4. Entire long-winded essays have been written explaining what netmasks are and how they work -and if you like bitmasks, you’ll love netmasks! I would simply say: “find what netmask you’ve already been assigned via DHCP and use that”. Or “find what netmask every other PC on your network uses and stick with that”.
- Line 4 is the generic network address, a way of saying ‘these addresses would be common to all PCs on my subnet’ -for subnets 255.255.255.0, the network address always ends in zero.
- Line 5 is the broadcast address -where you send packets when you want the entire subnet to pick them up (as NETBIOS does, for example). For networks using the 255.255.255.0 netmask, this always ends in .255.
- Finally, Line 6 specifies the gateway address -the IP address of the machine or router (or old laptop in my case!) which happens to have a connection to the Internet which other machines can use or share. This could be anything: you need to know if you’re using Internet Connection Sharing (ICS), or a dedicated router or something else to share one Internet connection around the house. In my case, I use Windows’ ICS and that means my laptop is forced to be 192.168.0.1, so that’s what I have to put in here.
Now, with all that lot typed in correctly, save the file. Then issue this command:
/etc/init.d/networking restart
You’ll get warnings about it being deprecated, but it will nevertheless work and if it completes successfully, it means you’re good to go. Old Windows hands like me will, however, probably want to reboot the server a couple of times, checking with ifconfig that the server really is applying the one, constant IP address each time it comes back up and checking the contents of /etc/network/interfaces to see that the interface really does remain statically configured!
However you do it, once you’re happy the server is acquiring a valid, usable and static IP address, you might want to consider taking this opportunity to take a snapshot of your virtual machine, since all’s in working order: Machine > Take Snapshot if so.
Conclusion
I’ll stop the article at this point, because it’s done what it said on the tin: you’ve now got yourself an Apache web server that’s capable of serving up useful stuff to any browser that asks it to. In subsequent articles, I’ll explain how to use this capability to help you build an Oracle database server and then how to link that to your web server so that you can browse your way through things like the EMP table
For now, I’ll just sum up what we’ve done so far as follows:
- build a new, small Ubuntu server 32-bit Virtual Machine
- apt-get install apache2 php5 unzip make binutils openssh-server
- passwd root
- upload various files and utilities to /var/www using standard sftp client software
Have fun.
Pingback: Installing Apache on centos 6 | DIASPAR WAS NOT ALWAYS THUS