joppot

コピペで絶対動く。説明を妥協しない

mac

Set up subdomain for each directory using virtual host of apache 2.4 and Mac hosts

投稿日:2017年3月12日 更新日:


topthumbsubdoman

Abstract

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.

http://localhost:8080/workspace/alice_blog/index.html
http://localhost:8080/workspace/tom_service/index.html

It is the long URL.
If you choose this article way,

http://alice.localhost:8080/index.html
http://tom.localhost:8080/index.html

you can make the above URL.

Premise

mac
apache2.4
Sample project



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.

127.0.0.1 alice.localhost

hostsubdomain

Save it.
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.

/usr/local/etc/apache2/2.4/httpd.conf

Add this.

<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>

alicelocal

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 .

Save it.

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.

http://alice.locahost:8080

youcanacessaliceblog

Access succeeded.


Conclusion

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.

スポンサードリンク

If you think this article is good, share it please

-mac
-,

執筆者:


comment

Your email address will not be published. Required fields are marked *

関連記事

Build PlantUML environment on Mac using brew

Abstract Hello everybody it’s me candle. In this article, I would like to build a plantUML environment which can make UML easily on Mac. I have been used starUML for making UML. plantUML seems to be much more useful than that. Precondition You already use brew. Check java version I think that java is already installed in your mac pc. PlantUML can be run with mac default java. So you launch terminal app and check the java version with the below command. java -version Probably it can be work in java version around 1.8.x . Install graphviz graphviz is a …

How to install and manage fonts of mac using brew-cask-fonts

Abstract Hello everyone it’s me candle. In this article, I will show you how to install and manage fonts of mac using brew-cask-fonts. In general, font of mac is managed using an application called Font Book. It is certainly convenient, but it takes a lot of time to install. Anyway, the way of font distribution is not only Github, font is located in various places such as individual sites and DropBox. So, the procedure of introduction is often different for each fonts. On the other hand, programmers are generally lazy people by a good meaning, so fonts installation will be …

With nodenv, upgrade installation list and node version.

Abstract Hello everyone I’m candle. In this time I will show you how to update nodenv installation list and node version. The development of node is very active and the version of node will advance quickly. Let’s update node version using nodenv. Condition You have installed nodenv by brew. Upgrade nodenv installation list The installation list of the old nodenv becomes old with the passage of time. Even if you run this command, the latest node may not be displayed. nodenv install –list This is because the list information that node-build has is out of date. So we will upgrade …

How to use f.lux, blue light cut software

Abstract Hello everyone. In this time I will explain how to use f.lux. f.flux can reduce the amount of blue light as much as possible. f.lux can adjust the blue light cut rate with the seek bar. Please try using it. Condition You use Mac or Windows I will explain it in Mac PC. Download f.lux Go to the blew site. http://justgetflux.com/ Click the center “Download f.lux” button. Once you have downloaded the zip file, let’s double-click it and extract it. Since The executable file is expanded in the download folder, move it to the Application folder. It’s over. Use …


I work in the venture company as a CTO. I start to write program in University, first I learned java, C++ and PHP. In the company, I'm developing web services by Rails. I do like to automation.