How to create virtual host with wildcard in apache server using ubuntu
1.) Start by copying the file for the first domain:-
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/
demo.com
.conf
2.) Open the new file in your editor with root privileges
sudo gedit /etc/apache2/sites-available/demo.com.conf
3.) Remove the all constant from the file and replace the below text
<VirtualHost *:80>
ServerAdmin demo@example.com
ServerName demo.com
ServerAlias www.demo.com
DocumentRoot /var/www/html/php-work/wordpress
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
4.) We can use the a2ensite tool to enable each of our sites like this
ServerAdmin demo@example.com
ServerName demo.com
ServerAlias www.demo.com
DocumentRoot /var/www/html/php-work/wordpress
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
4.) We can use the a2ensite tool to enable each of our sites like this
sudo a2ensite demo.com.conf
5.) Set the local host and restart server
sudo nano /etc/hosts
127.0.0.1 demo.com
sudo service apache2 restart
for wildcard setup
1.) sudo apt-get install dnsmasq
2.) sudo service network-manager restart
3.) sudo gedit dnsmasq.conf
4.) include the line #address=/demo.com/127.0.0.1
5.)
sudo /etc/init.d/dnsmasq restart