Black Friday Hosting Deals: 69% Off + Free Migration: Grab the Deal Grab It Now!
The Apache HTTP Server is a widely used web server globally. It caters to various uses with its:
- Open-source nature
- Extensive customization options
- Strong features
Setting up Apache may appear overwhelming initially, but it becomes manageable with clear instructions.
This manual will guide you in configuring an Apache server hosting efficiently.
Make sure you have the necessary prerequisites before starting the configuration process:
1. A server that operates on a Linux distribution like:
- Ubuntu
- CentOS
- Debian
2. Root or sudo access to the server.
3. Apache is installed on the server. If Apache is not installed, you can do so using the following command for your respective Linux distribution:
Ubuntu/Debian:
sudo apt update
sudo apt install apache2
CentOS/RHEL
sudo yum install httpd
The usual location for Apache's main configuration file is typically found
/etc/apache2/apache2.conf (Ubuntu/Debian systems)
or
/etc/httpd/conf/httpd.conf (CentOS/RHEL systems)
This document includes worldwide configurations for the Apache server.
sudo nano /etc/apache2/apache2.conf # Ubuntu/Debian
sudo nano /etc/httpd/conf/httpd.conf # CentOS/RHEL
Specify the ServerName directive with your domain name or IP address to prevent warning messages regarding the server's complete domain name.
ServerName yourdomain.com
The Timeout directive defines how long Apache will wait for certain events before failing a request. The default value is generally 300 seconds.
Timeout 60
Apache’s functionality can be extended with modules. Common modules include:
- mod_rewrite for URL rewriting
- mod_ssl for enabling SSL
Ensure necessary modules are enabled.
Enable modules on Ubuntu/Debian
sudo a2enmod rewrite
sudo a2enmod ssl
Enable modules on CentOS/RHEL
Add or remove the specified lines in the configuration file.
LoadModule rewrite_module modules/mod_rewrite.so
LoadModule ssl_module modules/mod_ssl.so
Virtual Hosts enable the cloud hosting of numerous websites on one server. Every site will possess its configuration file.
- Ubuntu/Debian
sudo nano /etc/apache2/sites-available/yourdomain.com.conf
- CentOS/RHEL
sudo nano /etc/httpd/conf.d/yourdomain.com.conf
ServerAdmin [email protected]
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/yourdomain.com/public_html
ErrorLog ${APACHE_LOG_DIR}/yourdomain.com_error.log
CustomLog ${APACHE_LOG_DIR}/yourdomain.com_access.log combined
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
- Ubuntu/Debian
sudo a2ensite yourdomain.com.conf
sudo systemctl reload apache2
- CentOS/RHEL
There is no need to enable sites separately. Just restart Apache.
sudo systemctl restart httpd
sudo mkdir -p /var/www/yourdomain.com/public_html
sudo chown -R $USER:$USER /var/www/yourdomain.com/public_html
sudo chmod -R 755 /var/www/yourdomain.com
To activate SSL, you must have a certificate. You can acquire it from a:
- Certificate Authority
- Use a self-signed certificate
- Ubuntu/Debian
sudo a2enmod ssl
sudo systemctl restart apache2
- CentOS/RHEL
sudo yum install mod_ssl
sudo systemctl restart httpd
- Ubuntu/Debian
sudo nano /etc/apache2/sites-available/yourdomain.com-ssl.conf
- CentOS/RHEL
sudo nano /etc/httpd/conf.d/yourdomain.com-ssl.conf
ServerAdmin [email protected]
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/yourdomain.com/public_html
ErrorLog ${APACHE_LOG_DIR}/yourdomain.com_error.log
CustomLog ${APACHE_LOG_DIR}/yourdomain.com_access.log combined
SSLEngine on
SSLCertificateFile /etc/ssl/certs/apache-selfsigned.crt
SSLCertificateKeyFile /etc/ssl/private/apache-selfsigned.key
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
- Ubuntu/Debian
sudo a2ensite yourdomain.com-ssl.conf
sudo systemctl reload apache2
- CentOS/RHEL
No need to enable sites separately. Just restart Apache.
sudo systemctl restart httpd
Ensure your Apache configuration files are free of syntax errors.
sudo apachectl configtest # Ubuntu/Debian
sudo httpd -t # CentOS/RHEL
sudo systemctl restart apache2 # Ubuntu/Debian
sudo systemctl restart httpd # CentOS/RHEL
Access https://yourdomain.com on your web browser to confirm accessibility and proper SSL certificate setup.
Configuring the Apache web server involves:
- Setting up the main configuration file.
- Creating and enabling Virtual Hosts.
- Securing the server with SSL certificates.
Following these steps ensures your Apache server is configured properly to efficiently and securely serve your websites. Updating your server, monitoring its performance, and staying current with top security practices can ensure a strong and secure web hosting environment.
Let’s talk about the future, and make it happen!
By continuing to use and navigate this website, you are agreeing to the use of cookies.
Find out more