Apache

From LinuxReviews
Jump to navigationJump to search
Apache HTTP Server
Apache-icon.png
Original author(s)Robert McCool
Developer(s)Apache Software Foundation
Initial release1995; 25 years ago (1995)
RepositoryApache HTTP Server Repository
Written inC, XML
Operating systemUnix-like, Microsoft Windows
TypeWeb server
LicenseApache License 2.0

Apache ("Apache HTTP Server", or httpd) is a tried and true modular free open source web server with powerful features. It is mostly used to serve PHP scripts, static pages and images. Many widely used content management systems like WordPress and MediaWiki can be served using the Apache web server. Apache powered about half the websites on the Internet Q3 2020.

Apache does not have the ability to run server-side JavaScript the way node.js does.

Apache is a modular web server and there are a lot of modules available. It can have a very small memory footprint if a minimal amount of modules are loaded and it can have a lot of features and a higher memory footprint if a huge variety of modules are loaded.

Tips

You can get free HTTPS certificates for Apache from Let's Encrypt. Using https with a valid certificate is almost a requirement for hosting any even remotely popular website.

Apache is best restarted by running:

apachectl configtest
apachectl graceful

You can restart Apache by running apachectl restart or systemd by running service httpd restart - but that will immediately close all the webservers connections and potentially cause failed page loads for those visiting sites running on the webservers. apachectl graceful will keep current connections open. Restarting this way takes longer but it is also safer.

Configuration

Modern Apache version support three different worker modules:

  • prefork MPM (doc)
  • worker MPM (doc)
  • event MPM (doc)

The event MPM works really well with both php-fpm and php-zts.

PHP

Apache 2.4 supports opcache. It should be enabled in /etc/httpd/conf.d/php.conf with:

    php_value opcache.file_cache   "/var/lib/php/opcache"

Make sure the user apache is running as can read and write to the directory you choose. The performance difference between a opcahce (compiled PHP cache) and no cache really is quite huge.

Modern PHP modules for Apache support APCu memory cache. You should absolutely enable this if the web application you use supports because it really is very efficient.

Mod Rewrite Tricks

You can turn *.php? into */ with:

RewriteRule ^([^/\.]+)/?$ $1.php [L]

Common Problems

"(28)No space left on device: mod_rewrite: could not create rewrite_log_lock": This error can occur if Apache shuts down in a dirty (not normal) fashion. The cause of this error is semaphore-arrays left over after an unclean shutdown. You can check what, if anything, is left behind with ipcs -s | grep apache and remove the semaphore-arrays by running:

ipcs -s | grep apache | perl -e 'while (<STDIN>) { @a=split(/\s+/); print `ipcrm sem $a[1]`}'

Links

Apache has a homepage at httpd.apache.org.

Add your comment
LinuxReviews welcomes all comments. If you do not want to be anonymous, register or log in. It is free.