HTTP Server: Apache 2.4


by ross at 07:28:49 on August 1, 2014

The main configuration file - apache24/httpd.conf - has a section with LoadModule lines. This is where you enable/disable Apache modules. Out of the box many modules are commented out, you might want to uncomment some of them. For example, mod_rewrite module, which you will probably need.

Near the end of that file you will find some extra config files also commented out. Uncomment these two:

  • Include etc/apache24/extra/httpd-mpm.conf - configure the MPM you selected
  • Include etc/apache24/extra/httpd-default.conf - some default values you might want to change, for example, increase Timeout to match PHP's max_execution_time.

Virtual hosts

Place your virtual host definition files in apache24/Includes directory. Each file should end with '.conf' otherwise it will be ignored.

Apache will load these *.conf files in alphabetical order. First virtual host loaded becomes the default host, i.e. it will be shown on direct access to the server via IP address not name. You can start name of the file of such host with a digit to make sure it is loaded first.

Create apache24/Includes/000.default.conf:

# Default vhost for *:80
<VirtualHost _default_:80>
    ServerName localhost
    DocumentRoot "/usr/local/www/apache24/data"

## Default vhost for *:443 (https)
#<VirtualHost _default_:443>
#    ServerName localhost
#    DocumentRoot "/usr/local/www/apache24/data"
#    SSLEngine on
#    # You need to specify the certificate and the key:
#    SSLCertificateFile "/etc/certs/localhost.crt"
#    SSLCertificateKeyFile "/etc/certs/localhost.unencrypted.key"

Add to /etc/rc.conf:


Start apache:

# service apache24 start

Log rotation

To rotate Apache logs daily and keep 7 rotations of them add to /etc/newsyslog.conf:

/var/log/httpd-*.log    root:wheel      640  7     *    @T00  BJG /var/run/ 30
# service newsyslog restart