Apache

From Server rent store
Jump to navigation Jump to search
  1. Apache Web Server Configuration for MediaWiki 1.40

This article details the necessary configuration of the Apache web server to optimally run MediaWiki 1.40. Proper Apache configuration is crucial for performance, security, and stability. This guide is intended for system administrators and those new to configuring Apache for MediaWiki. We will cover virtual host setup, module requirements, and important optimization settings.

Prerequisites

Before beginning, ensure you have:

  • A functioning Apache 2.4+ installation. Verify with `apache2 -v`.
  • Root or sudo access to the server.
  • Basic familiarity with command-line interfaces and text editors.
  • PHP installed and configured to work with Apache (see PHP Configuration).
  • MediaWiki 1.40 files uploaded to your web server’s document root.

Virtual Host Configuration

A virtual host allows you to host multiple websites (or, in this case, a MediaWiki installation) on a single server. This is best practice for organization and security.

1. Create a new virtual host configuration file. The location varies by distribution (e.g., `/etc/apache2/sites-available/mediawiki.conf` on Debian/Ubuntu, `/etc/httpd/conf.d/mediawiki.conf` on CentOS/RHEL).

2. Add the following configuration, adjusting paths as needed:

```apache <VirtualHost *:80>

   ServerName your.mediawiki.domain
   ServerAlias www.your.mediawiki.domain
   DocumentRoot /var/www/mediawiki
   <Directory /var/www/mediawiki>
       Options FollowSymLinks
       AllowOverride All
       Require all granted
   </Directory>
   ErrorLog ${APACHE_LOG_DIR}/mediawiki_error.log
   CustomLog ${APACHE_LOG_DIR}/mediawiki_access.log combined

</VirtualHost> ```

Replace `your.mediawiki.domain` and `/var/www/mediawiki` with your actual domain and MediaWiki installation directory.

3. Enable the virtual host. On Debian/Ubuntu: `sudo a2ensite mediawiki.conf`. On CentOS/RHEL: `sudo ln -s /etc/httpd/conf.d/mediawiki.conf /etc/httpd/conf.d/`.

4. Restart Apache: `sudo systemctl restart apache2` or `sudo systemctl restart httpd`.

Required Apache Modules

MediaWiki relies on several Apache modules for proper functionality. Ensure these are enabled:

Module Description
`mod_rewrite` Enables URL rewriting, essential for clean URLs and MediaWiki’s routing. `mod_expires` Allows setting expiration headers for static assets (images, CSS, JavaScript) to improve caching. `mod_deflate` Compresses content before sending it to the browser, reducing bandwidth usage and improving page load times. `mod_headers` Allows manipulation of HTTP response headers. `mod_ssl` Required if you are using HTTPS (highly recommended).

To enable modules (Debian/Ubuntu): `sudo a2enmod module_name`. To enable modules (CentOS/RHEL): Ensure the module is loaded in `/etc/httpd/conf.modules.d/`. Restart Apache after enabling modules.

Optimization Settings

Optimizing Apache can significantly improve MediaWiki performance.

  • **KeepAlive:** Enable `KeepAlive` to allow persistent HTTP connections, reducing overhead. Add or modify the following in your Apache configuration:

```apache KeepAlive On KeepAliveTimeout 10 MaxKeepAliveRequests 100 ```

  • **Caching:** Utilize `mod_expires` to cache static assets. Add the following to your virtual host configuration:

```apache <FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">

   Expires active on
   Header append Cache-Control "public"

</FilesMatch> ```

  • **Gzip Compression:** Enable `mod_deflate` to compress content.

```apache <IfModule mod_deflate.c>

 AddOutputFilterByType DEFLATE text/plain
 AddOutputFilterByType DEFLATE text/html
 AddOutputFilterByType DEFLATE text/xml
 AddOutputFilterByType DEFLATE text/css
 AddOutputFilterByType DEFLATE application/xml
 AddOutputFilterByType DEFLATE application/xhtml+xml
 AddOutputFilterByType DEFLATE application/rss+xml
 AddOutputFilterByType DEFLATE application/javascript
 AddOutputFilterByType DEFLATE application/x-javascript

</IfModule> ```

  • **PHP-FPM:** Consider using PHP-FPM instead of `mod_php` for improved performance and resource management. This requires additional configuration beyond the scope of this article, but resources are available on the PHP Configuration page.

Security Considerations

  • **HTTPS:** Always use HTTPS to encrypt communication between the server and users. Obtain an SSL certificate from a trusted Certificate Authority.
  • **Directory Listing:** Disable directory listing to prevent unauthorized access to files. Ensure `Options Indexes` is *not* present in your `<Directory>` blocks.
  • **Permissions:** Set appropriate file and directory permissions to prevent unauthorized modification.
  • **Regular Updates:** Keep Apache and all modules updated to the latest versions to patch security vulnerabilities.

Performance Monitoring

Regularly monitor Apache performance to identify bottlenecks and optimize configurations. Tools like `apachetop`, `htop`, and server logs can provide valuable insights. Consider using a monitoring system for long-term performance tracking.

Apache Configuration Table Summary

Setting Value Description
ServerName your.mediawiki.domain The primary domain name for your MediaWiki site. ServerAlias www.your.mediawiki.domain Alternative domain names. DocumentRoot /var/www/mediawiki The directory where MediaWiki files are located. KeepAlive On Enables persistent HTTP connections. KeepAliveTimeout 10 Seconds to keep a connection alive. MaxKeepAliveRequests 100 Maximum requests allowed on a single connection.

Troubleshooting

  • **500 Internal Server Error:** Check your Apache error logs for detailed information. Common causes include PHP errors, incorrect file permissions, or invalid `.htaccess` configurations.
  • **403 Forbidden:** Verify that the Apache user has read access to the MediaWiki files and directories. Check the `<Directory>` block configuration.
  • **404 Not Found:** Ensure that the `DocumentRoot` is correctly configured and that the requested files exist. Verify that `mod_rewrite` is enabled and configured correctly. See URL Rewriting.

Further Resources


Intel-Based Server Configurations

Configuration Specifications Benchmark
Core i7-6700K/7700 Server 64 GB DDR4, NVMe SSD 2 x 512 GB CPU Benchmark: 8046
Core i7-8700 Server 64 GB DDR4, NVMe SSD 2x1 TB CPU Benchmark: 13124
Core i9-9900K Server 128 GB DDR4, NVMe SSD 2 x 1 TB CPU Benchmark: 49969
Core i9-13900 Server (64GB) 64 GB RAM, 2x2 TB NVMe SSD
Core i9-13900 Server (128GB) 128 GB RAM, 2x2 TB NVMe SSD
Core i5-13500 Server (64GB) 64 GB RAM, 2x500 GB NVMe SSD
Core i5-13500 Server (128GB) 128 GB RAM, 2x500 GB NVMe SSD
Core i5-13500 Workstation 64 GB DDR5 RAM, 2 NVMe SSD, NVIDIA RTX 4000

AMD-Based Server Configurations

Configuration Specifications Benchmark
Ryzen 5 3600 Server 64 GB RAM, 2x480 GB NVMe CPU Benchmark: 17849
Ryzen 7 7700 Server 64 GB DDR5 RAM, 2x1 TB NVMe CPU Benchmark: 35224
Ryzen 9 5950X Server 128 GB RAM, 2x4 TB NVMe CPU Benchmark: 46045
Ryzen 9 7950X Server 128 GB DDR5 ECC, 2x2 TB NVMe CPU Benchmark: 63561
EPYC 7502P Server (128GB/1TB) 128 GB RAM, 1 TB NVMe CPU Benchmark: 48021
EPYC 7502P Server (128GB/2TB) 128 GB RAM, 2 TB NVMe CPU Benchmark: 48021
EPYC 7502P Server (128GB/4TB) 128 GB RAM, 2x2 TB NVMe CPU Benchmark: 48021
EPYC 7502P Server (256GB/1TB) 256 GB RAM, 1 TB NVMe CPU Benchmark: 48021
EPYC 7502P Server (256GB/4TB) 256 GB RAM, 2x2 TB NVMe CPU Benchmark: 48021
EPYC 9454P Server 256 GB RAM, 2x2 TB NVMe

Order Your Dedicated Server

Configure and order your ideal server configuration

Need Assistance?

⚠️ *Note: All benchmark scores are approximate and may vary based on configuration. Server availability subject to stock.* ⚠️