Set up subdomain for each directory using virtual host of apache 2.4 and Mac hosts
Hello everybody, It’s candle.
This time I will show you how to divide directories by subdomain with mac easily.
For example, it is useful when such situation.
If you are developing some wordpress project with apache, there are URL like the following.
It is the long URL.
If you choose this article way,
you can make the above URL.
setting for hosts
First, you write the subdomain which you want to use to hosts file.
Open the /etc/hosts, in general, it is described as follows.
127.0.0.1 [sub domain name]
127.0.0.1 is your own pc address, that is the local host.
In this time, we describe like this.
The sub domain setting is over.
Setting apache’s virtual host
We set up apache side.
There is a configuration file in the following path when you install apache 2.4 by brew.
<VirtualHost *:8080> ServerName alice.localhost DocumentRoot /Users/candle/apache/alice_blog <Directory "/Users/candle/apache/alice_blog"> AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>
Please change the port number 8080 to your own setting.
Write the subdomain you set before in ServerName.
Specify the location you want to be root when accessing url with DocumentRoot and
Check with the browser
Let’s start apache server and check it.
Apache installed with brew, start it with the fllowing command.
httpd -k start
You try to access the URL which is setting in hosts and apache.
This apache configuration is a setting for development only locally, we do not consider security etc.
Please be careful about migration to the production environment.