Create(set) virtual host as local domain- ubuntu(linux)
Sometimes we need to create a local domain for the sites in our local server. To accomplish this purpose, we need to create a virtual host entry in apache hosts and respectively create its dependencies as well. Example : localhost/myproject => myproject.localhost
To meet the above described requirements, we need to follow below steps over your terminal(command-line) considering you are at /(root) directory:
1- Create your site's conf file under the directory : etc/apache2/sites-enabled.
Enter command :
- sudo cp /etc/apache2/sites-enabled/default.conf /etc/apache2/sites-available/myproject.localhost.conf
- sudo nano /etc/apache2/sites-enabled/myproject.localhost.conf
Make the changes as defined below:
Options Indexes FollowSymLinks
Require all granted
CustomLog /var/log/apache2/cphd-access.log common
2- Make your host entry for "myproject.localhost" against host IP : 127.0.1.1 .
-sudo nano /etc/hosts ( for new host entry )
3- sudo service apache2 restart( start/stop apache service )
Now you will be able to access your project/site via direct host link( myproject.localhost ) rather than accessing via directory path( localhost/myproject ).
[ Note: default.conf file name can be different. You may see under the specified directory. ]
Thanks for your valuable comments and suggestions