Today, I will guide the people how to configuring a virtual host is really important if anybody works as
web developer. It will give your separate hosting environment by keeping
specific features from another one. Beside this, I have a plan to write
a complete tutorial on setting up LAMP environment with proper
extension for being a professional developer. Though it’s not so
difficult, but sometimes it turns you in some troubles. However, let me
explain it by following some easy steps . . .
Assuming that apache2 is already installed in your PC. if it is not, please setup it before you create virtual host.
Whatever, first thing is to create configuration file in
/etc/apache2/sites-available by gedit, nano or any other text editor.
Suppose, the configuration file name is
tranthanhepu.com and local IP
address is 127.0.0.1. Type following command in terminal….
|
gksudo gedit /etc/apache2/sites-available/tranthanhepu.com
|
Add following lines in configuration file
|
<VirtualHost 127.0.0.1:80>
DocumentRoot /var/www/tranthanhepu.com
ServerName tranthanhepu.com
ServerAlias www.tranthanhepu.com
ServerAdmin admin@tranthanhepu.com
</VirtualHost>
|
Save and close it. Now create a symbolic link of this configuration
file to /etc/apache2/sites-enabled directory in order to enable it
|
cd /etc/apache2/sites-enabled/
sudo ln -s ../sites-available/tranthanhepu.com .
|
Now, add a virtual domain with a specific local IP to hosts file that
is located in /etc/hosts. You can also add the port using a colon with
the IP.
add this line
|
127.0.0.1.:80 tranthanhepu.com
|
Save and close it. Almost done. Finally, restart the apache service.
|
sudo /etc/init.d/apache2 restart
|
Done. Keep it in your mind that you can make multiple name based
virtual hosts based on your IP address. Best practice is make separate
configuration for each virtual host.
No comments: