Apache is one of the most widely used web servers in the world and forms the foundation for running websites on many Linux systems. This article shows you how to install Apache, set up virtual hosts, enable modules, and secure the server. With the right configuration, Apache runs stable, fast, and securely, even when hosting multiple websites on a single server.
Installing Apache on Linux
On most Linux distributions, you install Apache via the package manager. On Debian- or Ubuntu-based systems, use apt install apache2; on CentOS or AlmaLinux, use dnf install httpd. After installation, start the service and enable it to start automatically at boot, so Apache is immediately available again after a reboot.
The main configuration files are located in /etc/apache2/ on Debian systems and in /etc/httpd/ on RHEL systems. The main file is called apache2.conf or httpd.conf, with separate folders for sites and modules. Keeping this structure organized helps prevent mistakes when making future changes.
apachectl configtest before restarting the service. This prevents a typo from taking the entire website offline.Setting up virtual hosts
With virtual hosts, you can run multiple websites on a single server, each with its own domain name and document root. For each site, you create a separate configuration file in the available sites folder and enable it using a2ensite on Debian systems.
A virtual host should at minimum include the ServerName, the DocumentRoot, and log files for errors and access. Make sure the domain name correctly points to the right IP address via the DNS settings; if you haven’t registered a domain yet, you can easily arrange this through a provider for domain names.
Configuring SSL and security
A secure connection is essential nowadays. With the mod_ssl module and a valid certificate, for example from Let’s Encrypt, you can set up HTTPS for your virtual host. Make sure to also set up a redirect from HTTP to HTTPS, so visitors always connect via the secure connection.
Further secure the server by disabling unnecessary modules, prohibiting directory listing, and hiding the server version in the response headers. Also limit file and folder permissions so the web server only has access to what it needs. In addition, keep an eye on your email configuration; a correctly configured business email environment prevents misconfigured servers from being abused for spam.
Install Apache
Use your distribution’s package manager and start the service.
Create a virtual host
Set the ServerName and DocumentRoot and enable the site.
Install an SSL certificate
Enable mod_ssl and configure HTTPS with a redirect.
Test and restart
Check the configuration and restart Apache without downtime.
Optimizing and managing Apache
For better performance, you can enable caching modules and tune the number of worker processes to match the server’s available memory. Keep an eye on log files to quickly identify slow pages or error messages, and rotate logs regularly to save disk space.
If you’d rather not spend time on server management yourself, a managed environment with Plesk is a convenient alternative: you can manage virtual hosts, SSL, and backups neatly through a single interface. If you still run into configuration issues, check out the knowledge base for more background information, or ask about the options for switching to Tandata if you prefer a managed solution.
Frequently Asked Questions
What is the difference between Apache and Nginx?
Apache uses a modular architecture with a lot of flexibility via .htaccess files, while Nginx is often faster at serving static content. Both can also be used together, with Nginx running as a reverse proxy in front of Apache.
How do I restart Apache without downtime?
Use apachectl graceful instead of a full restart. This reloads the configuration without immediately dropping active connections.
Where can I find the Apache error logs?
By default, these are located in /var/log/apache2/error.log on Debian systems or /var/log/httpd/error_log on RHEL systems, unless you’ve configured this differently per virtual host.
Can I use multiple PHP versions on a single Apache server?
Yes, this is possible via PHP-FPM with separate pools per virtual host, allowing each website to use its own PHP version and settings.
Conclusion
Configuring Apache on Linux comes down to a logical structure: installation, virtual hosts, SSL and security, followed by optimization and management. With the right settings and regular checks of logs and configuration, your web server runs stable and secure. If you’d rather leave this management to someone else, check out reliable web hosting with Plesk, NVMe storage, and full support.