on Windows
1- open httpd-vhosts.conf
xampp: C:\xampp\apache\conf\extra\httpd-vhosts.conf
wamp: C:\wamp\bin\apache\apache2.4.41\conf\extra\httpd-vhosts.conf
2- paste below text into httpd-vhosts.conf
and save it
xampp: <VirtualHost *:80> ServerAdmin admin@test.local DocumentRoot "C:/xampp/htdocs/test.local" ServerName test.local ErrorLog "logs/test.local-error.log" CustomLog "logs/test.local-access.log" common </VirtualHost>
wamp: <VirtualHost *:80> ServerAdmin admin@test.local DocumentRoot "c:/wamp/www/test.local" ServerName test.local ServerAlias test.local ErrorLog "logs/test.local-error.log" CustomLog "logs/test.local-access.log" combined </VirtualHost>
3- open as admin hosts
file and edit it (for add test.local domain with local ip)
windows : C:\Windows\System32\drivers\etc\hosts
and add below text in the end line:
127.0.0.1 test.local
4- create a test page in site root folder (index.php
or index.html
)
index.php: <?php echo "Hello World!"; phpinfo(); ?>
index.html: <html> <head> <title>Welcome to Test.local</title> </head> <body> <h1>Success! The test.local virtual host is working!</h1> </body> </html>
5- open browser and type the domain:
http://test.local
or
test.local/
on Ubuntu
1- copy default configuration apache file 000-default.conf
configuration file to new test.local.conf
configuration file
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/test.local.conf
2- edit test.local.conf
sudo gedit /etc/apache2/sites-available/test.local.conf
3- paste below text into test.local.conf
and save it
<VirtualHost *:80> ServerAdmin admin@test.local ServerName test.local ServerAlias www.test.local DocumentRoot /var/www/test.local ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>
or
<VirtualHost *:80> ServerAdmin admin@test.local ServerName test.local ServerAlias www.test.local DocumentRoot /var/www/html/test.local/web ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /var/www/html/test.local/web/> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> </VirtualHost>
or
<VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.test.local ServerAdmin webmaster@test.local ServerName test.local ServerAlias www.test.local DocumentRoot /var/www/html/test.local # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost>
or
<VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin webmaster@localhost DocumentRoot /var/www/html # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
4- enable the new virtual host test.local.conf
sudo a2ensite test.local.conf
5- disable the default apache site defined 000-default.conf
sudo a2dissite 000-default.conf
6- restart apache server
sudo systemctl restart apache2
7- open hosts
file and edit it and
open: sudo gedit /etc/hosts
add below text in the end line:
127.0.0.1 test.local
8- create a test page in site root folder (index.php
or index.html
)
index.php: <?php echo "Hello World!"; phpinfo(); ?>
index.html: <html> <head> <title>Welcome to Test.local</title> </head> <body> <h1>Success! The test.local virtual host is working!</h1> </body> </html>
9- open browser and type the domain:
http://test.local
or
test.local/