HOW TO: Set up a Virtual Host on Apache 2.4.4 [ MAC / *NIX ]

前提是你 提交于 2020-01-21 02:34:08

问题


I am posting this because I recently had a lot of trouble setting up a Virtual Host with a MAMP stack, due to Apple's throttling of the useable PHP version on Mac OS 10.8's default Apache2 installation.

This is a very quick guide on what to do and I owe the solution to this question on Stack Overflow:

  • Information Source

You can think of this as a compilation of what worked for me, as the accepted answers had no effect, but rather those with a significantly lower score.

Similarly, every guide I have seen fails to mention some points which users answered with on the sourced question.


回答1:


Step 1: Install and configure Apache.

Make sure you specify what port you want to listen on, for me I specified 8080. This will be the case for this series of instructions.

Listen 8080 - Default is 80

Step 2: Edit your /etc/hosts file to spoof your loopback address, 127.0.0.1

127.0.0.1   localhost
127.0.0.1   some.example         # domain-name.domain-TLD
127.0.0.1   www.some.example     # The same as the above line, but with www. prefixed

You should really add a handle for subdomains on your web server, Apache or Nginx (or whatever else you use. Something that routes www to non-www.

Step 3: Enable the Virtual Hosts import on Apache.

  1. Open your httpd.conf file located within Apache2's subdirectories. Usually within /conf
  2. Uncomment the line that resembles this: Include conf/extra/httpd-vhosts.conf
  3. Also uncomment this module import: LoadModule log_config_module modules/mod_log_config.so

Step 4: Configure your Virtual Hosts file

  1. Find your Virtual Hosts config, httpd-vhosts.conf, you can comment out the two example Virtual Hosts in the file. Usually within /conf/extra
  2. Copy your own Virtual Host into the file from this template:
<VirtualHost *:80>                           # Change the 80 to the number Apache2 "Listen"s on. In my case, 8080
    ServerName SERVER-ADDRESS                # E.g. mywebsite.local
    ServerAlias WWW.SERVER-ADDRESS           # E.g. www.mywebsite.local
    DocumentRoot " SERVER-FILE-ROOT "        # E.g. "Users/user-name/Sites"
        <Directory />                        # This should be a full path, though
            Require all granted              # Required for permission errors
            Options Indexes FollowSymLinks Includes ExecCGI
            AllowOverride none
        </Directory>
</VirtualHost>

You're Done!

Once your Virtual Host has been edited to your liking you are done, just restart Apache and enjoy.

This guide already includes the fixes implemented, but in-case you still get permission errors:

  • You MUST make sure that your DocumentRoot is not inside any documents your user explicitly owns. If it needs to be, give "Read Only" access to "Everyone" on Mac for that particular folder, E.g. "Documents" or "Movies" etc....



回答2:


Although the above answer is much explanatory, the following 2 things are most important when you are migrating virtual hosts to apache 2.4

  1. Go to wamp/bin/apache/apache2.4.x/conf/httpd.conf find #Include conf/extra/httpd-vhosts.conf and uncomment to Include conf/extra/httpd-vhosts.conf

  2. Add the virtual hosts in wamp/bin/apache/apache2.4.x/conf/extra/httpd-vhosts.conf as

<VirtualHost *:80>
        ServerAdmin admin@localhost.com
        DocumentRoot "H:/Wamp/www/mysite"
        ServerName mysite
        ServerAlias mysite
        <Directory />
            Require all granted
        </Directory>
    </VirtualHost>

Note: <Directory **/**> the / is important



来源:https://stackoverflow.com/questions/18739764/how-to-set-up-a-virtual-host-on-apache-2-4-4-mac-nix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!