Changes between Initial Version and Version 1 of Apache2.4.x


Ignore:
Timestamp:
Oct 22, 2017, 1:31:35 PM (7 years ago)
Author:
whmagill
Comment:

Initial pass on a new Apache 2.4.x wiki howto page

Legend:

Unmodified
Added
Removed
Modified
  • Apache2.4.x

    v1 v1  
     1[[PageOutline]]
     2
     3[wiki:howto <- Back to the HOWTO section]
     4
     5= About Apache = #about
     6
     7The Apache HTTP Server, commonly referred to simply as Apache, is the world's most-popular web server.
     8
     9For information on integrating Apache2-2.4.x with MySQL and PHP, see [wiki:howto/MAMP2.4.x MAMP2.4.x]. (Yet to be written - 10-20-17-whm.)
     10
     11= Versions = #versions
     12
     13MacPorts includes the following versions of Apache:
     14
     15* '''apache2''': Apache HTTP Server v2.4.x. This is the current, recommended port to use, and will install if you simply type:
     16{{{
     17$ sudo port install apache2
     18}}}
     19Apache2-2.4.x has a different directory layout from apache2, so none of the other ports that use apache2 can use apache2.4-.x without modifications.
     20
     21This page shows how to install and use the apache2-2.4.x  port on High Siarra (OSX 10.13.x).
     22These instructions cannot be easily adapted to the other ports.
     23For information of earlier versions of Apache2 visit see [wiki:howto/Apache2].
     24
     25== October 2017 - Apache2-2.4.28 ==
     26In October of 2017 <Macports upgraded Apache 2.2.x  to Apache 2.4.x as the default installation. This involved a significant set of changes as listed in the Notes of the portfile:
     27
     28Apache2 has been migrated from the 2.2.x to the 2.4.x branch.
     29   
     30    The install paths have been changed to no longer violate the MacPorts mtree:
     31   
     32    1. The binaries are now under '''''/opt/local/sbin/'''''
     33       (rather than under /opt/local/apache2/bin/)
     34   
     35    2. The configure files are now under '''''/opt/local/etc/apache2/'''''
     36       (rather than under /opt/local/apache2/conf/)
     37   
     38    3. The modules are now under '''''/opt/local/lib/apache2/modules/'''''
     39       (rather than under /opt/local/apache2/modules/)
     40   
     41    4. The web root is now located under '''''/opt/local/www/apache2/html/'''''
     42       (rather than under /opt/local/apache2/htdocs/)
     43   
     44    5. The cgi-bin is now located under '''''/opt/local/www/apache2/cgi-bin/'''''
     45       (rather than under /opt/local/apache2/cgi-bin/)
     46   
     47    6. The logs are now located under '''''opt/local/var/log/apache2/'''''
     48       (rather than under /opt/local/apache2/logs/)
     49   
     50    7. The manual is now located under '''''/opt/local/www/apache2/manual/'''''
     51       (rather than under /opt/local/apache2/manual/)
     52   
     53    8. The manual (man) pages are still at '''''/opt/local/share/apache2/man/'''''
     54   
     55    You can move your htdocs and cgi-bin to the new locations, or edit /opt/local/etc/apache2/httpd.conf to point at the old
     56    locations.
     57
     58
     59= Step 1: '''Turn off Apple's "Personal Web Sharing"''' = #pws
     60
     61=== OS X 10.13.x  High Sierra  ===
     62Beginning with Yosemite (OSX 10.10), OSX no longer has Personal Web Sharing as an option in System Preferences.
     63
     64However,  the Apache 2 web server (and PHP 7) is supplied by Apple as part of the High Sierra  distribution (Apache/2.4.27).
     65It is found at `/etc/apache2`; there is no "GUI" way to turn it on (or off), only via the command line.
     66It is not turned on, or configured, in a default High Sierra installation.
     67
     68{{{
     69$ sudo apachectl stop
     70}}}
     71=== OS X Server ===
     72Launch Server Manager and turn off the web server.
     73
     74= Step 2: Install Apache = #apache
     75
     76{{{
     77$ sudo port install apache2
     78}}}
     79
     80A sample configuration file is provided in '''''/opt/local/etc/apache2/httpd.conf.orig'''''.
     81
     82The first time you install apache2, this sample configuration file will be copied to `/opt/local/etc/apache2/httpd.conf` for you.
     83You can edit this file as desired.
     84When you later upgrade apache2 to a newer version, MacPorts will upgrade the sample configuration file but will not modify your `httpd.conf`, so be sure to manually compare your `httpd.conf` with the new sample configuration file and bring over any relevant changes. You should also keep backup copies of your `httpd.conf` in a safe place.
     85
     86A copy of the origina `httpd.conf` file and the and configuration files in the extra directory, are found in `/opt/local/etc/apache2/original` so you can refer to the defaults later.
     87
     88=  Step 3:  Verify your config file =
     89Verify any changes you have made to the config file: /opt/local/etc/apache2/httpd.conf
     90{{{
     91$ /opt/local/sbin/apachectl -t
     92}}}
     93This will return either "Syntax OK" or a specific line by line error listing.
     94
     95=  Step 4: Activate Apache2 =
     96Activate your Apache installation so that it starts now and every time you boot your machine:
     97
     98{{{
     99$ sudo port load apache2
     100}}}
     101= below not updated yet
     102If when you issue this command, you immediately receive the message:
     103 /opt/local/etc/LaunchDaemons/org.macports.apache2/org.macports.apache2.plist: Operation already in progress
     104This means that the Launch Daemon believes that it successfully started Apache. At this point, a configuration error is your most likely problem. Verify your config file as above.
     105
     106After correcting any config errors and saving the updated config file, simply run:
     107{{{
     108$ sudo port unload apache2
     109}}}
     110
     111to stop apache (even though it is not running) and then start it using
     112
     113{{{
     114$ sudo port load apache2
     115}}}
     116
     117to start it again.
     118
     119The default log file location is: `opt/local/var/log/apache2/'` The startup will be logged in "'''error_log'''"
     120
     121= Step 5: Initial changes to the config file =
     122Once you have determined that your basic installation is working, you need to consider making some initial changes to your config file.
     123
     124After each change to the config file, you should again verify the file syntax, and then you need to stop and restart Apache for the changes to take effect.
     125
     126{{{
     127$ /opt/local/apache2/bin/apachectl -t
     128$ sudo port unload apache2
     129$ sudo port load apache2
     130}}}
     131In Apache documentation (including this page), you will see the use of "''apachectl -k restart''" described as the method to cause the config file to be re-read.
     132
     133However under OSX, the purpose of ''launchd'' is to notice processes that stop without its knowledge, and to restart them. So if you use ''apachectl -k restart'', launchd may notice apache "crashing" and restart it itself, confusing apachectl. Instead, you shoulduse "port" to tell launchctl to unload apache2, then load it again. This will result in a short interruption of service.
     134
     135If the sever name is not set properly in the configuration file, `/opt/local/apache2/conf/httpd.conf`, you will encounter the warning below.
     136
     137{{{
     138httpd: Could not reliably determine the server's fully qualified domain name, using <Computer-Name>.local for ServerName
     139}}}
     140
     141Where `<Computer-Name>` refers to the name of your computer as specified in the System Preferences Sharing pane.  To resolve the warning, edit the configuration file and set the server name appropriately.  For personal use, `localhost` is sufficient.
     142
     143{{{
     144ServerName localhost:80
     145}}}
     146
     147To verify Apache is now running, point your browser to http://localhost/ (you may need to reload the page). You should see a page that says "It works!"
     148
     149If desired, reboot your machine and point your browser again to http://localhost/ to confirm that Apache is again running.
     150
     151'''NOTE:''' The setting of "ServerName" to anything other than the '''Fully Qualified Domain Name''' (FQDN) of the server under Apache 2.2.x and Yosemite, does not produce the expected results.
     152Using the links above to "localhost" will fail with Safari complaining "''Failed to open page. Safari can't open the page "localhost" because Safari can't connect to the server "localhost".''
     153The simple answer is "localhost" is an "old-tyme" shortcut which should still work, but often does not for many different reasons. The "Fix" is to simply use the FQDN of your server when testing Apache or related Web services.
     154
     155=== User directories === #userdir
     156
     157If you would like to be able to access web pages in the Sites directory of your home directory, edit `/opt/local/apache2/conf/httpd.conf` and locate the following line:
     158
     159{{{
     160#Include conf/extra/httpd-userdir.conf
     161}}}
     162
     163Uncomment it by removing the "`#`" at the start of the line so that it reads:
     164
     165{{{
     166Include conf/extra/httpd-userdir.conf
     167}}}
     168This file:   ''"/opt/local/apache2/conf/extra/httpd-userdir.conf"'' will activate the "Sites" sub-directory for all ~users on your system. (''"/Users/*/Sites"'') and contains initial, basic restrictions for access to the contents of that directory.
     169
     170After each change to the config file, you should again verify the file syntax, and then you need to stop and restart Apache for the changes to take effect.
     171
     172{{{
     173$ /opt/local/apache2/bin/apachectl -t
     174$ sudo port unload apache2
     175$ sudo port load apache2
     176}}}
     177
     178You can then view your personal pages by accessing http://localhost/~username/, where "username" is your Mac OS X account's short name.
     179
     180=== Local Apache manual === #manual
     181
     182The [http://httpd.apache.org/docs/2.2/ Apache manual] is available on the Apache web site. If you would like to be able to access a copy of this manual on your web server, edit `/opt/local/apache2/conf/httpd.conf` and uncomment the following line:
     183
     184{{{
     185#Include conf/extra/httpd-manual.conf
     186}}}
     187
     188So that it reads like this:
     189
     190{{{
     191Include conf/extra/httpd-manual.conf
     192}}}
     193
     194After each change to the config file, you should again verify the file syntax, and then you need to stop and restart Apache for the changes to take effect.
     195
     196{{{
     197$ /opt/local/apache2/bin/apachectl -t
     198$ sudo port unload apache2
     199$ sudo port load apache2
     200}}}
     201
     202You can then view the manual by accessing http://localhost/manual/.
     203
     204NOTE: This option expects ''"/opt/local/apache2/manual"'' to be accessible under "<Document Root>." This can be accomplished by
     205{{{
     206$ cd <Document Root>
     207$ ln -s /opt/local/apache2/manual
     208}}}
     209and then accessing: ''http://<servername>/manual/''
     210
     211=== Apache SSL/TLS Encryption (aks Secure Sockets  or https) === #ssl
     212'''Note:''' Establishing Secure Sockets is a fairly extensive process. One should first read the current Apache2 documentation found in the Apache2 manual:
     213{{{
     214http://httpd.apache.org/docs/2.2/ssl/
     215}}}
     216==== Generate a self-signed certificate ====
     217The following instructions are to generate a "self-signed" certificate.\\
     218This is simply a shortcut for testing purposes (a self-signed certificate is not recommended for production!).\\
     219The complete dialog is listed here for reference. The commands necessary are prefixed as "$ sudo", with comments prefixed with a #.\\
     220
     221{{{
     222$ sudo openssl genrsa -des3 -out server.key 1024
     223# Enter pass phrase for server.key [enter your passphrase, a simple password we will remove soon]
     224
     225Generating RSA private key, 1024 bit long modulus
     226.....++++++
     227................++++++
     228e is 65537 (0x10001)
     229Enter pass phrase for server.key:
     230Verifying - Enter pass phrase for server.key:
     231
     232
     233$ sudo openssl req -new -key server.key -out server.csr
     234#
     235# [you can accept all the defaults, it does not matter, or customize it to your liking]
     236
     237Enter pass phrase for server.key:
     238You are about to be asked to enter information that will be incorporated
     239into your certificate request.
     240What you are about to enter is what is called a Distinguished Name or a DN.
     241There are quite a few fields but you can leave some blank
     242For some fields there will be a default value,
     243If you enter '.', the field will be left blank.
     244-----
     245Country Name (2 letter code) [AU]:
     246State or Province Name (full name) [Some-State]:
     247Locality Name (eg, city) []:
     248Organization Name (eg, company) [Internet Widgits Pty Ltd]:
     249Organizational Unit Name (eg, section) []:
     250Common Name (e.g. server FQDN or YOUR name) []:
     251Email Address []:
     252
     253Please enter the following 'extra' attributes
     254to be sent with your certificate request
     255A challenge password []:
     256An optional company name []:
     257
     258
     259$ sudo openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt
     260# [will ask for passphrase - the same as you entered in the first step]
     261
     262Signature ok
     263subject=/C=US/ST=Pennsylvania/L=Elizabethtown/O=MVE/OU=Elizabethtown/CN=mcgillsociety.org/emailAddress=magill@icloud.com
     264Getting Private key
     265Enter pass phrase for server.key:
     266
     267$ sudo cp server.key server.key.bak
     268$ sudo openssl rsa -in server.key.bak -out server.key
     269# [will ask for passphrase - the same as you entered in the first step]
     270
     271Enter pass phrase for server.key.bak:
     272writing RSA key
     273
     274$ sudo cp server.crt /opt/local/apache2/conf/
     275$ sudo cp server.key /opt/local/apache2/conf/
     276}}}
     277'''Note:''' Certificate generation can be accomplished in any directory. If you did so in ''"/opt/local/apache2/conf"'' the last two copy commands are redundant, and will generate the following  errors respectively:
     278{{{
     279cp: /opt/local/apache2/conf/server.crt and server.crt are identical (not copied).
     280cp: /opt/local/apache2/conf/server.key and server.key are identical (not copied).
     281}}}
     282
     283Then enable the following in {{{/opt/local/apache2/conf/httpd.conf}}}
     284
     285{{{
     286LoadModule ssl_module modules/mod_ssl.so
     287
     288# Secure (SSL/TLS) connections
     289Include conf/extra/httpd-ssl.conf
     290}}}
     291After each change to the config file, you should again verify the file syntax, and then you need to stop and restart Apache for the changes to take effect.
     292{{{
     293$ /opt/local/apache2/bin/apachectl -t
     294$ sudo port unload apache2
     295$ sudo port load apache2
     296}}}
     297
     298The most likely error you will receive is:
     299{{{
     300Syntax error on line 120 of /opt/local/apache2/conf/extra/httpd-ssl.conf:
     301SSLCertificateFile: file '/opt/local/apache2/conf/server.crt' does not exist or is empty
     302}}}
     303If so, simply revisit the instructions above to create a self-signed certificate.
     304
     305==== Verify your success ====
     306
     307type ''"https://<your server address>"'' in Safari. \\
     308Safari should return the pop-up: "Safari can't verify the identity of the website "<your server address>" \\
     309At which point you can view the details of your certificate and select your appropriate actions.
     310
     311==== Configure your "Virtual Host" ====
     312While you have verified your certificate, you will discover that you have no access to your server - ''"You don't have permission to access.... on this server."''\\
     313This is because the SSL Virtual Host has not been configured in ''"/opt/local/apache2/conf/extra/httpd-ssl.conf"''
     314
     315Edit ''"/opt/local/apache2/conf/conf/extra/httpd-ssl.conf"'' and moved down to the section:
     316{{{
     317#   General setup for the virtual host
     318DocumentRoot "/opt/local/apache2/htdocs"
     319ServerName www.example.com:443
     320ServerAdmin you@example.com
     321ErrorLog "/opt/local/apache2/logs/error_log"
     322TransferLog "/opt/local/apache2/logs/access_log"
     323}}}
     324Configure this section appropriately. \\
     325Assuming you wish to implement SSL on your entire server, ''DocumentRoot'' and ''ServerName'' should match the values in ''"/opt/local/apache2/conf/httpd.conf"''\\
     326As there are many optional ways of configuring security on your web server, consult the Apache2 manual for details.
     327{{{
     328http://httpd.apache.org/docs/2.2/ssl/
     329}}}
     330
     331After each change to the config file, you should again verify the file syntax, and then you need to stop and restart Apache for the changes to take effect.
     332{{{
     333$ /opt/local/apache2/bin/apachectl -t
     334$ sudo port unload apache2
     335$ sudo port load apache2
     336}}}
     337
     338[wiki:howto <- Back to the HOWTO section]