If you have a LAMP-installation installed on a computer / server(hardware) that has one or more network-interface cards, one of which has a public/Live IP-address, a huge security risk would be to leave your LAMP-installation on the default "localhost or 127.0.0.1" setting.

Leaving it as default allows your LAMP installation to be accessed from all IP-addresses configured for your server, for example: http://127.0.0.1, http://ip-address#1 and http://ip-address#2 will all resolve to the "It works" Apache page:

lamp-localhost-1

If one of your network-interface card's IP address is public/Live, your LAMP installation would also be accessible from the internet by anyone around the world; and just in case your 'PHPMyadmin' directory or some other '/www/DIR' isn't secured, someone can begin to hacker-practice on your machine, for example with http://live-ip-address/phpmyadmin.

In this tutorial, I will explain how to change the localhost-IP address(127.0.0.1) to an IP-address(assumed static) of one of your network interface cards.

It is thus assumed that LAMP is installed. If not, then read: How to setup a LAMP Server on Debian 6.0.6 Squeeze.

Suppose we have a static-IP: 192.168.100.1 on an interface card and we want to set this as LAMP's default IP-address, just 2-file needs to be edited.

a) hosts file, found at: /etc/hosts. Add a new line with the static-IP of an interface-card and a new hostname.

sample-before:
127.0.0.1 localhost
127.0.1.1 debian

sample-after:
127.0.0.1 localhost
127.0.1.1 debian
192.168.100.1 debian2

save and close the hosts file.

b) 000-default file, found at /etc/apache2/sites-enabled/000-default. Find and edit the first line with "VirtualHost" - at the top.

sample-before:
VirtualHost *:80

sample-after:
VirtualHost 192.168.100.1:80

save and close the file.

Lastly:

Reload apache2 with command: service apache2 reload

Restart apache2 with command: service apache2 restart

lamp-localhost-2

Note:

For better security, the default port of LAMP on debian can also be changed: How to change LAMP Default Webserver Port in Debian Squeeze.

You have no rights to post comments