Note: You are currently viewing documentation for Moodle 2.2. Up-to-date documentation for the latest stable version is available here: Apache.

Apache: Difference between revisions

From MoodleDocs
(Added 'Configuration' sub-heading)
(Installing Moodle template)
 
(42 intermediate revisions by 13 users not shown)
Line 1: Line 1:
When most people refer to '''Apache''' they are talking about the "Apache HTTP Server Project". In fact Apache is really the "Apache Software Foundation" which hosts a long list of projects of which the HTTP server is just one, albeit the best known.
{{Installing Moodle}}
'''This article refers to the 'Apache HTTP server''''


The Apache HTTP Server enables web pages to be published on the internet (or an intranet or even on a single test machine). It is tightly linked with the [[PHP]] scripting language in which Moodle is developed. A web server is a required component of a Moodle installation. There are two distinct developments of the Apache HTTP Server, version 1 and version 2. Although version 2 should have replaced version 1, the architectures are so different that they both continue to be supported. Either are fully supported by Moodle.
The Apache HTTP server is the software that (along with the PHP scripting language) 'runs' Moodle. Note that there are alternatives (e.g. IIS on Windows) but the Apache HTTP Server is very popular on all platforms.  


The Apache HTTP Server Project describes itself thus:
== Installing Apache ==
Installers are available for most platforms from http://httpd.apache.org/download.cgi. The official installation instructions are here: http://httpd.apache.org/docs/2.0/install.html. If you are running Linux then you are recommended to use the packaged version if you can. For example in Debian/Ubuntu it is simply:
<pre>
sudo apt-get install apache2
</pre>


"The Apache HTTP Server Project is an effort to develop and maintain an open-source HTTP server for modern operating systems including UNIX and Windows NT. The goal of this project is to provide a secure, efficient and extensible server that provides HTTP services in sync with the current HTTP standards.
See the documentation for your particular platform for the instructions. Apache is straightforward to build from source if you have to and the PHP documentation contains an article on building both Apache and PHP together - although you should rarely need to do that.


Apache has been the most popular web server on the Internet since April 1996. The November 2005 Netcraft Web Server Survey found that more than 70% of the web sites on the Internet are using Apache, thus making it more widely used than all other web servers combined."
==Performance==


==Configuration==
See [[Performance recommendations]]


If you have the luxury of being able to configure Apache directly, you can achieve a major performance boost by specifying that images, JavaScript and other often-reused elements must be cached locally. This will enormously reduce both page loading time and server load.
==SSL==


===Apache 2.x===
Moodle has an option to enable login pages to force the HTTPS protocol. This is recommended but requires that your web server is configured for SSL. It is possible to run the whole site over HTTPS (typically by configuring Apache to rewrite all http:// URLs to <nowiki>https://</nowiki>) but as this disables caching, there is a considerable performance hit. Only do this if you have a very good reason.


from the command line:
'''WARNING: Before switching on login over HTTPS, make very sure that HTTPS is working (just change the http:// to https:// in any Moodle URL). If not, you may lock yourself out'''


a2enmod expires
You have two options for obtaining an SSL certificate:
* generate a self-signed certificate. This is fine on (say) an Intranet but unsuitable for the public internet (except perhaps for testing). The user has no assurance that the certificate is legitimate.
* purchase a certificate from a vendor. There is a surprising range of prices and value-added services available. Some hosting companies even provide free certificates.


you can now add the following lines inside the <virtualhost> tags of the relevant file in apache2/sites-enabled
Below are instructions for install of a self-signed certificate. If you purchase a certificate you will normally receive instructions for installing it


<IfModule mod_expires.c>
===Debian and Apache2===
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 1 seconds"
  ExpiresByType image/gif "access plus 120 minutes"
  ExpiresByType image/jpeg "access plus 120 minutes"
  ExpiresByType image/png "access plus 120 minutes"
  ExpiresByType text/css "access plus 60 minutes"
  ExpiresByType text/javascript "access plus 60 minutes"
  ExpiresByType application/x-javascript "access plus 60 minutes"
  ExpiresByType text/xml "access plus 60 minutes"
</IfModule>


then restart apache with something like
1. generate a certification:
<pre>
apache2-ssl-certificate
</pre>


/etc/init.d/apache2 restart
for debian etch, apache2-ssl-certificate is no longer available, use make-ssl-cert instead:
 
<pre>
The downside is that if you're editing your theme, there may be confusion as you'll keep seeing the old images instead of the new ones. Clicking 'refresh' in the browser or clearing the cache should sort this out.
make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem
</pre>
2. edit /etc/apache2/ports.conf:
<pre>
      Listen 80
      Listen 443
</pre>
3. copy /etc/apache)2/sites-available/default to /etc/apache2/sites-available/default-ssl, and change /etc/apache2/sites-available/default:
<pre>
      NameVirtualHost *:80
      <VirtualHost *:80>
      ...
      </VirtualHost>
</pre>
and also /etc/apache2/sites-available/default-ssl:
<pre>
      NameVirtualHost *:443
      <VirtualHost *:443>
      ...
              SSLEngine on
              SSLCertificateFile /etc/apache2/ssl/apache.pem
      ...
      </VirtualHost>
</pre>
4. symbolic link the ssl file:
<pre>
a2ensite default-ssl
</pre>
5. don't forget to symbolic link the ssl module:
<pre>
a2enmod ssl
</pre>
6. restart apache and '''test the connection''' (e.g. https://localhost/):
<pre>
/etc/init.d/apache2 restart
</pre>


== See also ==
== See also ==
Line 44: Line 78:
* [http://httpd.apache.org/ The Apache HTTP Server Project homepage]
* [http://httpd.apache.org/ The Apache HTTP Server Project homepage]
* [http://en.wikipedia.org/wiki/Apache_HTTP_Server Wikipedia article on the Apache HTTP Server]
* [http://en.wikipedia.org/wiki/Apache_HTTP_Server Wikipedia article on the Apache HTTP Server]
* [http://httpd.apache.org/docs/2.0/misc/perf-tuning.html Apache Performance Tuning article at the official homepage]
* [https://els.earlham.edu/cayaraa/weblog/1468.html Making Moodle work with SSL]
* [http://www.krufix.de/ Using the same Moodle twice in local network and Internet via SSL-Proxy] (in German)


 
[[pl:Apache]]
[[Category:Administrator]]
[[ja:Apache]]
[[Category:Developer]]
[[de:Apache]]
 
{{stub}}

Latest revision as of 09:15, 8 December 2011

This article refers to the 'Apache HTTP server'

The Apache HTTP server is the software that (along with the PHP scripting language) 'runs' Moodle. Note that there are alternatives (e.g. IIS on Windows) but the Apache HTTP Server is very popular on all platforms.

Installing Apache

Installers are available for most platforms from http://httpd.apache.org/download.cgi. The official installation instructions are here: http://httpd.apache.org/docs/2.0/install.html. If you are running Linux then you are recommended to use the packaged version if you can. For example in Debian/Ubuntu it is simply:

sudo apt-get install apache2

See the documentation for your particular platform for the instructions. Apache is straightforward to build from source if you have to and the PHP documentation contains an article on building both Apache and PHP together - although you should rarely need to do that.

Performance

See Performance recommendations

SSL

Moodle has an option to enable login pages to force the HTTPS protocol. This is recommended but requires that your web server is configured for SSL. It is possible to run the whole site over HTTPS (typically by configuring Apache to rewrite all http:// URLs to https://) but as this disables caching, there is a considerable performance hit. Only do this if you have a very good reason.

WARNING: Before switching on login over HTTPS, make very sure that HTTPS is working (just change the http:// to https:// in any Moodle URL). If not, you may lock yourself out

You have two options for obtaining an SSL certificate:

  • generate a self-signed certificate. This is fine on (say) an Intranet but unsuitable for the public internet (except perhaps for testing). The user has no assurance that the certificate is legitimate.
  • purchase a certificate from a vendor. There is a surprising range of prices and value-added services available. Some hosting companies even provide free certificates.

Below are instructions for install of a self-signed certificate. If you purchase a certificate you will normally receive instructions for installing it

Debian and Apache2

1. generate a certification:

apache2-ssl-certificate

for debian etch, apache2-ssl-certificate is no longer available, use make-ssl-cert instead:

make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /etc/apache2/ssl/apache.pem

2. edit /etc/apache2/ports.conf:

      Listen 80
      Listen 443

3. copy /etc/apache)2/sites-available/default to /etc/apache2/sites-available/default-ssl, and change /etc/apache2/sites-available/default:

      NameVirtualHost *:80
      <VirtualHost *:80>
      ...
      </VirtualHost>

and also /etc/apache2/sites-available/default-ssl:

      NameVirtualHost *:443
      <VirtualHost *:443>
      ...
              SSLEngine on
              SSLCertificateFile /etc/apache2/ssl/apache.pem
      ...
      </VirtualHost>

4. symbolic link the ssl file:

a2ensite default-ssl

5. don't forget to symbolic link the ssl module:

a2enmod ssl

6. restart apache and test the connection (e.g. https://localhost/):

/etc/init.d/apache2 restart

See also