Skip to content
Yurii Torbyk edited this page Jan 7, 2019 · 11 revisions

Apache installation and its leveraging use next configuration section:

    'apache' => [
        'formula' => 'httpd',
        'vhosts' => '/Users/username/.sage/apache-vhosts',
        'config' => '/Users/username/.sage/httpd.conf',
        'brew_config_path' => '/usr/local/etc/httpd/httpd.conf',
        'brew_config_dir_path' => '/usr/local/etc/httpd',
        'localhost_path' => '/Users/username/xSage/localhost',
        'php_module' => 'LoadModule php{high_version}_module /usr/local/opt/php@{version}/lib/httpd/modules/libphp{high_version}.so',
        'php_module_header' => '#Load PHP Module'
    ]

Installation

Installation can be triggered by sage apache:install command or as a step in sage env:install command.

Apache installation actions:

  • install Brew formula httpd (see config settings ['apache']['formula'])
  • adds Include /Users/username/.sage/httpd.conf line at the end of /usr/local/etc/httpd/httpd.conf file. This's the only change which is done in apache configs.
  • create localhost virtual host with /Users/username/xSage/localhost directory (see ['apache']['localhost_path'] config)

Since the config include added at the end of apache config it can overwrite its settings. The include is generated from template.

Uninstallation

In order to uninstall Apache run sage apache:uninstall command or sage env:uninstall command then apache will be deleted with all other sage's environment.

Apache uninstallation actions:

  • uninstall Brew formula httpd (see config settings ['apache']['formula'])
  • delete /Users/username/.sage/httpd.conf config file
  • delete /usr/local/etc/httpd directory
  • delete localhost directory by ['apache']['localhost_path'] path

By default Virtual Hosts (located in /Users/username/.sage/apache-vhosts directory see ['apache']['vhosts'] config) are not deleted. In order to delete them pass --force or -f flag to the uninstall commands.

Start, Stop and Restart

Sage uses Brew services in order to start|stop|restart Apache service.

Available next commands:

  • sage apache:start alias for sudo brew services start httpd
  • sage apache:stop alias for sudo brew services stop httpd
  • sage apache:restart it stops services if it's running and starts it

It's possible to use Brew commands directly however be aware that Apache services should be run as root user (starts with sudo)

Virtual Host

As you can see at the end of Sage's Apache config there are included all configs from VHOSTS_PATH directory. During Apache installation VHOSTS_PATH is replaced with /Users/username/.sage/apache-vhosts path (see ['apache']['vhosts'] config). So in order to add new virtual host there is needed to create config for it and put it into the directory. Sage creates the virtual host config by http template and https template, by default it creates https certificate and marks it as trusted in system (only for .test domains).

Commands which can create apache virtual hosts:

  • sage apache:host create apache virtual host
  • sage site:link run sage apache:host and sage apache:restart commands

Both of the commands has the same arguments and options.

Arguments

  • domain domain which the virtual host should be created for
  • aliases [optional] space separated domains, domain-aliases which will be added to the virtual host

Options:

  • --path or -p [optional] path to root of virtual host.
    • if it's not passed then current directory will be used
    • if it starts with / then it's considered as full path
    • otherwise passed path will be considered as relative to current directory
  • --not-secure flag which prevent creating secure virtual host (https)

Commands which can delete apache virtual hosts:

  • sage apache:host-revoke create apache virtual host
  • sage site:unlink run sage apache:host-revoke and sage apache:restart commands

Both of the commands require domain which virtual host should be deleted and the command could be run from anywhere (not necessary from the root of virtual host)

# create Virtual Host http/https with site.test domain
# Document root /path/to/my/site directory
# restart Apache
sage site:link site.test -p /path/to/my/site

# create Virtual Host http/https site.test with aliases site2.test and site3.test
# current directory as Document Root
# restart Apache
sage site:link site.test site2.test site3.test

# delete Virtual Host for site.test domain
# restart Apache
sage site:unlink site.test