Introduction to Apache

D

DevynCJohnson

Guest
Apache (https://httpd.apache.org/) is a popular server web-server for many systems including Linux. Apache is estimated to serve over 50% of the Internet's websites. Apache is cross-platform and open source. Those two characteristics help to make Apache a popular choice for web-servers. Obviously, many Linux users and admins may want to gain a basic understanding of this software.

Apache runs as a daemon on Linux systems. The process's name is "httpd" which stands for "Hyper Text Transfer Protocol Daemon".

A "solution stack" refers to a software bundle. Apache and the system it is running on are often referred to using special acronyms. For instance, when running Apache on a Linux system and when the website is using PHP and a MySQL database, the whole setup is referred to as a "LAMP". This indicates that the web-server is using Linux + Apache + MySQL + PHP. As another example, a "WAMP" is Windows + Apache + MySQL + PHP. The "P" could also refer to Perl or Python. Many more examples are listed below. However, many Apache server software bundles exist, so this list is not complete.

AMPPS - Apache + MySQL + MongoDB + PHP + Perl/Python
DAMP - Darwin + Apache + MySQL/MariaDB + Perl/PHP/Python
FAMP - FreeBSD + Apache + MySQL/MariaDB + Perl/PHP/Python
LAMP - Linux + Apache + MySQL/MariaDB + Perl/PHP/Python
LAPP - Linux + Apache + PostgreSQL + PHP
MAMP - Mac OS X + Apache + MySQL/MariaDB + Perl/PHP/Python
SAMP - Solaris + Apache + MySQL/MariaDB + Perl/PHP/Python
WAMP - Windows + Apache + MySQL/MariaDB + Perl/PHP/Python
XAMPP - Cross-platform + Apache + MySQL + PHP + Perl

Notice that the names of these software bundles follow a pattern of "Operating System + Web-server (Apache) + Database + Script-layer(s)".

"Apache Tomcat" refers to a special implementation of Apache that runs in a Java environment.
http://tomcat.apache.org/

NOTE: Jetty is an alternative to Apache that uses Java (similar to Apache Tomcat). http://www.eclipse.org/jetty/

The main configuration file used by Apache is /etc/httpd/httpd.conf. However, on some systems, it may be /etc/httpd.conf, /etc/httpd/conf/httpd.conf, or /etc/apache2/apache2.conf. This file is a plain-text document. The octothorpe (#) is used to comment-out lines. This means a line beginning with "#" is ignored. This allows admins to leave notes/messages in the configuration file or void/disable a setting.

The first several lines of this file may look something like the example below.
Code:
  ### Section 1: Global Environment
  #
  ServerType standalone
  ServerRoot "/etc/httpd"
  PidFile /var/run/httpd.pid
  ResourceConfig /dev/null
  AccessConfig /dev/null
  Timeout 300
  KeepAlive On
  MaxKeepAliveRequests 0
  KeepAliveTimeout 15
  MinSpareServers 16
  MaxSpareServers 64
  StartServers 16
  MaxClients 512
  MaxRequestsPerChild 100000

  ### Section 2: 'Main' server configuration
  #
  Port 80

  <IfDefine SSL>
  Listen 80
  Listen 443
  </IfDefine>

The indentation is optional. Notice that each option/setting is on its own line. On each line is the setting's name and then the desired value. For instance, "MaxClients" is the option pertaining to the maximum number of clients that the Apache system will serve. The "512" is the desired maximum. A set of related sub-options are enclosed in HTML-like tags. For instance, notice the "<IfDefine>" near the end of the example file. The enclosed options relate to SSL. The sub-options specify that SSL works on port 80 ("Listen 80") and port 443 ("Listen 443").

The default configuration file that comes with the Apache installation contains many comments that help to explain each option. So, if a user is unsure about a particular option/setting, the comments should help. If not, the official Apache website has documentation (http://httpd.apache.org/docs/current/).

The Apache executable file is often found as /usr/sbin/apache2. The "2" refers to the major version number. Since the Root user is the only user permitted to edit/configure Apache (by default), the file is stored under /usr/sbin/.

Apache's features and abilities can be extended with modules. Such modules are usually called Multi-Processing Modules (MPM). The names of the modules begin with "mod_". Therefore, the module named "mod_gzip" provides GZip capabilities. Some Apache modules can be downloaded and installed like the typical Linux software packages (*.deb via apt-get, *.rpm via yum, etc.). After installing a module, be sure to restart the Apache process (httpd). On a Debian-based system, the command is "service apache2 reload" and the command must be run with Root privileges. To enable a disabled module, execute "a2enmod MODULE" with Root privileges. Obviously, replace "MODULE" with the name of the module. To disable a module, type "a2dismod MODULE" with Root privileges.
https://modules.apache.org/

To manually install a module, place the compiled file (*.so file) under /usr/lib/httpd/modules/. Next, in the httpd.conf file, add two lines. For one line, type "LoadModule MODULE". On the next line, type the file-path to the named module (like "/usr/lib/httpd/modules/MODULE-FILE.so").

/etc/apache2/mods-available/ is a directory containing files that each provide information on an installed Apache module. /etc/apache2/mods-enabled/ is a directory that contains symbolic-links to files located in /etc/apache2/mods-available/. Each symbolic-link in /etc/apache2/mods-enabled/ represents an enabled module.

"Apache Rivet" is an add-on/extension for Apache that allows developers to use Tcl as the scripting language in-place of PHP, Python, or Perl.
http://tcl.apache.org/rivet/

Webpages and other web-content associated with the website hosted by Apache is stored under /var/www/ or /var/www/html/ (depending on the system and version). In that directory, users will see a file titled "index.html". This is the main/default page for the website. Use that file as the starting point for your website. Place other HTML files in the same directory (or subdirectories). For example, if a file named "info.html" was in the same directory as "index.html", then a hyperlink in "index.html" to "info.html" may look like "www.YOURWEBSITE.com/info.html".

Further Reading
http://httpd.apache.org/docs/current/
http://ampps.com/
https://help.ubuntu.com/community/ApacheMySQLPHP
https://wiki.debian.org/LaMp
https://en.opensuse.org/SDB:Linux_Apache_MySQL_PHP
 

Attachments

  • slide.jpg
    slide.jpg
    65.5 KB · Views: 36,026

Staff online

Members online


Top