Changes between Version 15 and Version 16 of howto/Apache2
- Timestamp:
- Oct 21, 2017, 9:45:24 PM (7 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
howto/Apache2
v15 v16 13 13 MacPorts includes the following versions of Apache: 14 14 15 * '''apache2''': Apache HTTP Server v2.2.x. This is the recommended port to use. 16 * '''apache24-devel''': Apache HTTP Server v2.4.x. This is intended for testing, and cannot be used to replace apache2 at this time. It has a different directory layout from apache2, so none of the other ports that use apache2 can use apache24-devel. it is expected that the contents of the apache24-devel port will eventually replace the contents of the apache2 port at which time the apache24-devel port will be retired. 17 * '''apache''': Apache HTTP Server v1.3.x. This version reached [http://mail-archives.apache.org/mod_mbox/httpd-announce/201002.mbox/%3c20100203000334.GA19021@infiltrator.stdlib.net%3e end of life] in 2010 and is therefore not recommended. 15 * '''apache2''': Apache HTTP Server v2.4.x. This is the recommended port to use. 16 * '''apache20''': Apache HTTP Server v2.0.x. This is port is soon to be retired. 17 * '''apache22''': Apache HTTP Server v2.2.x. This is the former '''apache2''' port. It will be maintained as long as as it is supported by Apache.org. 18 * '''apache24-devel''': Apache HTTP Server v2.4.x. The apache24-devel port has been retired. 19 * '''apache''': Apache HTTP Server v1.3.x. The apache port has been retired. 18 20 19 21 This page shows how to install and use the apache2 port. The instructions cannot be easily adapted to the other ports. 20 22 21 23 == October 2017 - Apache 2.4.x == 22 In October of 2017 Apache 2.2.x was upgrade to Apache 2.4.x. This involved a significant set of changes as listed in the Notes of the portfile:24 In October of 2017 Apache 2.2.x was upgraded to Apache 2.4.x. This involved a significant set of changes as listed in the Notes of the portfile: 23 25 24 26 Apache2 has been migrated from the 2.2.x to the 2.4.x branch. … … 75 77 }}} 76 78 77 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.79 A sample configuration file is provided in `/opt/local/etc/apache2/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/etc/apache2/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. 78 80 79 81 = Step 3: Verify your config file = 80 Verify any changes you have made to the config file: /opt/local/ apache2/conf/httpd.conf81 {{{ 82 $ /opt/local/ apache2/bin/apachectl -t82 Verify any changes you have made to the config file: /opt/local/etc/apache2/httpd.conf 83 {{{ 84 $ /opt/local/sbin/apachectl -t 83 85 }}} 84 86 This will return either "Syntax OK" or a specific line by line error listing. … … 107 109 to start it again. 108 110 109 The default log file location is: '''/opt/local/ apache2/logs/'''. The startup will be logged in "'''error_log'''"111 The default log file location is: '''/opt/local/var/log/apache2/'''. The startup will be logged in "'''error_log'''" 110 112 111 113 = Step 5: Initial changes to the config file = … … 115 117 116 118 {{{ 117 $ /opt/local/ apache2/bin/apachectl -t119 $ /opt/local/sbin/apachectl -t 118 120 $ sudo port unload apache2 119 121 $ sudo port load apache2 … … 123 125 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. 124 126 125 If the sever name is not set properly in the configuration file, `/opt/local/ apache2/conf/httpd.conf`, you will encounter the warning below.127 If the sever name is not set properly in the configuration file, `/opt/local/etc/apache2/httpd.conf`, you will encounter the warning below. 126 128 127 129 {{{ … … 145 147 === User directories === #userdir 146 148 147 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:148 149 {{{ 150 #Include conf/extra/httpd-userdir.conf149 If you would like to be able to access web pages in the Sites directory of your home directory, edit `/opt/local/etc/apache2/httpd.conf` and locate the following line: 150 151 {{{ 152 #Include etc/apache2/extra/httpd-userdir.conf 151 153 }}} 152 154 … … 154 156 155 157 {{{ 156 Include conf/extra/httpd-userdir.conf157 }}} 158 This 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.159 160 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. 161 162 {{{ 163 $ /opt/local/ apache2/bin/apachectl -t158 Include etc/apache2/extra/httpd-userdir.conf 159 }}} 160 This file: ''"/opt/local/etc/apache2/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. 161 162 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. 163 164 {{{ 165 $ /opt/local/sbin/apachectl -t 164 166 $ sudo port unload apache2 165 167 $ sudo port load apache2 … … 170 172 === Local Apache manual === #manual 171 173 172 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:173 174 {{{ 175 #Include conf/extra/httpd-manual.conf174 The [http://httpd.apache.org/docs/2.4/ 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/etc/apache2/httpd.conf` and uncomment the following line: 175 176 {{{ 177 #Include etc/apache2/extra/httpd-manual.conf 176 178 }}} 177 179 … … 179 181 180 182 {{{ 181 Include conf/extra/httpd-manual.conf182 }}} 183 184 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. 185 186 {{{ 187 $ /opt/local/ apache2/bin/apachectl -t183 Include etc/apache2/extra/httpd-manual.conf 184 }}} 185 186 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. 187 188 {{{ 189 $ /opt/local/sbin/apachectl -t 188 190 $ sudo port unload apache2 189 191 $ sudo port load apache2 … … 192 194 You can then view the manual by accessing http://localhost/manual/. 193 195 194 NOTE: This option expects ''"/opt/local/ apache2/manual"'' to be accessible under "<Document Root>." This can be accomplished by196 NOTE: This option expects ''"/opt/local/www/apache2/manual"'' to be accessible under "<Document Root>." This can be accomplished by 195 197 {{{ 196 198 $ cd <Document Root> 197 $ ln -s /opt/local/ apache2/manual199 $ ln -s /opt/local/www/apache2/manual 198 200 }}} 199 201 and then accessing: ''http://<servername>/manual/'' … … 202 204 '''Note:''' Establishing Secure Sockets is a fairly extensive process. One should first read the current Apache2 documentation found in the Apache2 manual: 203 205 {{{ 204 http://httpd.apache.org/docs/2. 2/ssl/206 http://httpd.apache.org/docs/2.4/ssl/ 205 207 }}} 206 208 ==== Generate a self-signed certificate ==== … … 262 264 writing RSA key 263 265 264 $ sudo cp server.crt /opt/local/ apache2/conf/265 $ sudo cp server.key /opt/local/ apache2/conf/266 }}} 267 '''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:268 {{{ 269 cp: /opt/local/ apache2/conf/server.crt and server.crt are identical (not copied).270 cp: /opt/local/ apache2/conf/server.key and server.key are identical (not copied).271 }}} 272 273 Then enable the following in {{{/opt/local/ apache2/conf/httpd.conf}}}266 $ sudo cp server.crt /opt/local/etc/apache2/ 267 $ sudo cp server.key /opt/local/etc/apache2/ 268 }}} 269 '''Note:''' Certificate generation can be accomplished in any directory. If you did so in ''"/opt/local/etc/apache2"'' the last two copy commands are redundant, and will generate the following errors respectively: 270 {{{ 271 cp: /opt/local/etc/apache2/server.crt and server.crt are identical (not copied). 272 cp: /opt/local/etc/apache2/server.key and server.key are identical (not copied). 273 }}} 274 275 Then enable the following in {{{/opt/local/etc/apache2/httpd.conf}}} 274 276 275 277 {{{ … … 277 279 278 280 # Secure (SSL/TLS) connections 279 Include conf/extra/httpd-ssl.conf280 }}} 281 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. 282 {{{ 283 $ /opt/local/ apache2/bin/apachectl -t281 Include etc/apache2/extra/httpd-ssl.conf 282 }}} 283 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. 284 {{{ 285 $ /opt/local/sbin/apachectl -t 284 286 $ sudo port unload apache2 285 287 $ sudo port load apache2 … … 288 290 The most likely error you will receive is: 289 291 {{{ 290 Syntax error on line 120 of /opt/local/ apache2/conf/extra/httpd-ssl.conf:291 SSLCertificateFile: file '/opt/local/ apache2/conf/server.crt' does not exist or is empty292 Syntax error on line 120 of /opt/local/etc/apache2/extra/httpd-ssl.conf: 293 SSLCertificateFile: file '/opt/local/etc/apache2/server.crt' does not exist or is empty 292 294 }}} 293 295 If so, simply revisit the instructions above to create a self-signed certificate. … … 301 303 ==== Configure your "Virtual Host" ==== 302 304 While 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."''\\ 303 This is because the SSL Virtual Host has not been configured in ''"/opt/local/ apache2/conf/extra/httpd-ssl.conf"''304 305 Edit ''"/opt/local/ apache2/conf/conf/extra/httpd-ssl.conf"'' and moved down to the section:305 This is because the SSL Virtual Host has not been configured in ''"/opt/local/etc/apache2/extra/httpd-ssl.conf"'' 306 307 Edit ''"/opt/local/etc/apache2/extra/httpd-ssl.conf"'' and moved down to the section: 306 308 {{{ 307 309 # General setup for the virtual host 308 DocumentRoot "/opt/local/ apache2/htdocs"310 DocumentRoot "/opt/local/www/apache2/html" 309 311 ServerName www.example.com:443 310 312 ServerAdmin you@example.com 311 ErrorLog "/opt/local/ apache2/logs/error_log"312 TransferLog "/opt/local/ apache2/logs/access_log"313 ErrorLog "/opt/local/var/log/apache2/error_log" 314 TransferLog "/opt/local/var/log/apache2/access_log" 313 315 }}} 314 316 Configure this section appropriately. \\ … … 316 318 As there are many optional ways of configuring security on your web server, consult the Apache2 manual for details. 317 319 {{{ 318 http://httpd.apache.org/docs/2. 2/ssl/319 }}} 320 321 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. 322 {{{ 323 $ /opt/local/ apache2/bin/apachectl -t320 http://httpd.apache.org/docs/2.4/ssl/ 321 }}} 322 323 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. 324 {{{ 325 $ /opt/local/sbin/apachectl -t 324 326 $ sudo port unload apache2 325 327 $ sudo port load apache2