1) Open up your terminal
2) sudo pico /etc/hosts
3) Move to the next free line and add:
127.0.0.1 subdomain.localhost
4) Ctrl+o to save, then ctrl+x to exit
5) sudo pico /etc/httpd/httpd.conf
6) Ctrl+w to find: <VirtualHost *:80>
7) Add:
NameVirtualHost localhost
<VirtualHost localhost:80>
ServerName localhost
DocumentRoot "/path/to/default/dir/without/subdomain"
DirectoryIndex index.php index.html index.html index.htm index.shtml
</VirtualHost>
NameVirtualHost subdomain.localhost
<VirtualHost subdomain.localhost:80>
ServerName subdomain.localhost
DocumentRoot "/path/to/the/dir/that/you/want/to/use/as/your/subdir/"
DirectoryIndex index.php index.html index.html index.htm index.shtml
</VirtualHost>
8) Ctrl+o to save, then ctrl+x to exit
9) Now, restart Apache using:
sudo apachectl stop
sudo apachectl start
For Apache to notice the changes.
Done!
Click to view attachment