Skip to content

Instantly share code, notes, and snippets.

@hoandang
Last active April 1, 2024 06:46
Show Gist options
  • Save hoandang/8066175 to your computer and use it in GitHub Desktop.
Save hoandang/8066175 to your computer and use it in GitHub Desktop.
Sample vhost configuration

Sample apache vhost configuration

Udate /etc/hosts or c:\windows\system32\drivers\etc\hosts file so that the new servername is mapped to 127.0.0.1

Apache config file changes document root

    DocumentRoot "/Users/hoan/www"
<Directory "/Users/hoan/www">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # https://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options Indexes MultiViews FollowSymLinks
    MultiviewsMatch Any

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   AllowOverride FileInfo AuthConfig Limit
    #
    AllowOverride All
    Order allow,deny
    Allow from all

    #
    # Controls who can get stuff from this server.
    #
    Require all granted

</Directory>

Enable vhost:

Uncomment the line: Include /private/etc/apache2/extra/httpd-vhosts.conf

Vhost files locate at: /private/etc/apache2/extra/httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot "/Users/hoandang/Sites/insieme/insieme-server/public"
    ServerName api.insieme.dev

    <Directory "/Users/hoandang/Sites/insieme/insieme-server/public">
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all

        Header set Access-Control-Allow-Headers "ORIGIN, X-REQUESTED-WITH, CONTENT-TYPE"
        Header set Access-Control-Allow-Methods "POST, GET, OPTIONS, PUT, DELETE"
        Header set Access-Control-Allow-Origin "*"
        Header set Access-Control-Allow-Credentials true
        Header set Access-Control-Max-Age 60000
    </Directory>
</VirtualHost>

Bonus: load homebrew php instead of system php in /private/etc/apache2/extra/httpd-vhosts.conf

LoadModule php5_module /usr/local/Cellar/php53/5.3.28/libexec/apache2/libphp5.so
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment