Changes between Version 83 and Version 84 of howto/MAMP


Ignore:
Timestamp:
Dec 28, 2014, 10:55:22 PM (7 years ago)
Author:
magill@…
Comment:

Apache instructions extracted to howto/Apache2

Legend:

Unmodified
Added
Removed
Modified
  • howto/MAMP

    v83 v84  
    55These installation instructions are written for the following versions:
    66
    7  * Apache 2.2.*
     7 * Apache 2.2.* - See: [[howto/Apache2]] for instructions on installation of Apache2
    88 * MySQL 5.6.*
    99 * PHP 5.4.*
    10 
    11 = Step 1: '''Turn off Apple's "Personal Web Sharing"''' = #pws
    12 If you haven’t already done so, make sure you turn off Apple’s "Personal Web Sharing" so that the default Apache server is not running. While you can set things up so that both servers run on different ports (e.g., port 80 and port 8080), it’s not worth the hassle of maintaining two web server daemons. Just use the latest Apache from MacPorts and be done with it.
    13 
    14 === OS X 10.8 and older ===
    15 Turn off Personal Web Sharing in the Sharing pane of System Preferences.
    16 === Mavericks ===
    17 Stop the web server from the command line:
    18 {{{
    19 sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
    20 }}}
    21 === Yosemite ===
    22 Yosemite no longer has Personal Web Sharing as an option. Although the Apache 2 web server is still supplied by Apple as part of the Yosemite distribution, there is no "easy" way to turn it on (or off). So, if you managed to turn it on, you already know how to turn it off!
    23 === OS X Server ===
    24 Launch Server Manager and turn off the web server.
    25 
    26 = Step 2: Install Apache = #apache
    27 
    28 {{{
    29 sudo port install apache2
    30 }}}
    31 
    32 A sample configuration file is provided in `/opt/local/apache2/conf/original/httpd.conf`. Don't edit this file; leave it as is so you can refer to the defaults later. The first time you install apache2, the sample configuration file will be copied to `/opt/local/apache2/conf/httpd.conf` for you. You can edit this file as desired. When 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.
    33 
    34 == 2A:  Verify your config file ==
    35 Verify any changes you have made to the config file: /opt/local/apache2/conf/httpd.conf
    36 {{{
    37  /opt/local/apache2/bin/apachectl -t
    38 }}}
    39 This will return either "Syntax OK" or a specific line by line error listing.
    40 
    41 ==  2B: Activate Apache2 ==
    42 Activate your Apache installation so that it starts now and every time you boot your machine:
    43 
    44 {{{
    45 sudo port load apache2
    46 }}}
    47 If when you issue this command, you immediately receive the message:
    48  /opt/local/etc/LaunchDaemons/org.macports.apache2/org.macports.apache2.plist: Operation already in progress
    49 This 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.
    50 
    51 After correcting any config errors and saving the updated config file, simply run:
    52 {{{
    53 sudo port unload apache2
    54 }}}
    55 
    56 to stop apache (even though it is not running) and then start it using
    57 
    58 {{{
    59 sudo port load apache2
    60 }}}
    61 
    62 to start it again.
    63 
    64 The default log file location is: '''/opt/local/apache2/logs/'''. The startup will be logged in "'''error_log'''"
    65 
    66 == 2C: Initial changes to the config file ==
    67 Once you have determined that your basic installation is working, you need to consider making some initial changes to your config file.
    68 
    69 After 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.
    70 
    71 {{{
    72 /opt/local/apache2/bin/apachectl -t
    73 sudo port unload apache2
    74 sudo port load apache2
    75 }}}
    76 In 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.
    77 
    78 However 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.
    79 
    80 If the sever name is not set properly in the configuration file, `/opt/local/apache2/conf/httpd.conf`, you will encounter the warning below.
    81 
    82 {{{
    83 httpd: Could not reliably determine the server's fully qualified domain name, using <Computer-Name>.local for ServerName
    84 }}}
    85 
    86 Where `<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.
    87 
    88 {{{
    89 ServerName localhost:80
    90 }}}
    91 
    92 To 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!"
    93 
    94 If desired, reboot your machine and point your browser again to http://localhost/ to confirm that Apache is again running.
    95 
    96 '''NOTE:''' If you have set "ServerName" to be anything other than "localhost" 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".''
    97 === User directories === #userdir
    98 
    99 If 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:
    100 
    101 {{{
    102 #Include conf/extra/httpd-userdir.conf
    103 }}}
    104 
    105 Uncomment it by removing the "`#`" at the start of the line so that it reads:
    106 
    107 {{{
    108 Include conf/extra/httpd-userdir.conf
    109 }}}
    110 
    111 Then edit `/opt/local/apache2/conf/extra/httpd-userdir.conf` add the following lines to the end of the file:
    112 
    113 {{{
    114 #
    115 # Include user configurations
    116 #
    117 Include /private/etc/apache2/users/*.conf
    118 }}}
    119 
    120 For Mac OS X 10.4 and lower:
    121 {{{
    122 #
    123 # Include user configurations
    124 #
    125 Include /private/etc/httpd/users/*.conf
    126 }}}
    127 
    128 Restart Apache using `sudo /opt/local/apache2/bin/apachectl -k restart` to make this change take effect. You can then view your personal pages by accessing http://localhost/~username/, where "username" is your Mac OS X account's short name.
    129 
    130 === Local Apache manual === #manual
    131 
    132 The [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:
    133 
    134 {{{
    135 #Include conf/extra/httpd-manual.conf
    136 }}}
    137 
    138 So that it reads like this:
    139 
    140 {{{
    141 Include conf/extra/httpd-manual.conf
    142 }}}
    143 
    144 Restart Apache using `sudo /opt/local/apache2/bin/apachectl -k restart` to make this change take effect. You can then view the manual by accessing http://localhost/manual/.
    145 
    146 === Secure Sockets (https) === #ssl
    147 
    148 This works for a development system (not recommended for production!).
    149 
    150 {{{
    151 openssl genrsa -des3 -out server.key 1024
    152 # [enter your passphrase, a simple password we will remove soon]
    153 openssl req -new -key server.key -out server.csr
    154 # [you can accept all the defaults, it does not matter, or customize it to your liking]
    155 openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt
    156 # [will ask for passphrase]
    157 cp server.key server.key.bak
    158 openssl rsa -in server.key.bak -out server.key
    159 # [passphrase needs to be typed]
    160 sudo cp server.crt /opt/local/apache2/conf/
    161 sudo cp server.key /opt/local/apache2/conf/
    162 }}}
    163 
    164 Then enable the following in {{{/opt/local/apache2/conf/httpd.conf}}}
    165 
    166 {{{
    167 LoadModule ssl_module modules/mod_ssl.so
    168 
    169 # Secure (SSL/TLS) connections
    170 Include conf/extra/httpd-ssl.conf
    171 }}}
    17210
    17311