Installing and Configuring Apache
Apache is the world's most widely deployed web server, known for its flexibility and .htaccess support.
Install Apache
Ubuntu/Debian:
apt update
apt install apache2 -y
systemctl enable apache2
systemctl start apache2
CentOS/AlmaLinux/Rocky:
dnf install httpd -y
systemctl enable httpd
systemctl start httpd
Enable Important Modules (Ubuntu)
a2enmod rewrite # Required for WordPress, Laravel, etc.
a2enmod ssl
a2enmod headers
systemctl restart apache2
Create a Virtual Host
nano /etc/apache2/sites-available/yourdomain.com.conf
<VirtualHost *:80>
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/yourdomain.com
<Directory /var/www/yourdomain.com>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/yourdomain_error.log
CustomLog ${APACHE_LOG_DIR}/yourdomain_access.log combined
</VirtualHost>
Enable the site:
a2ensite yourdomain.com.conf
apache2ctl configtest
systemctl reload apache2
Set Correct File Permissions
chown -R www-data:www-data /var/www/yourdomain.com
find /var/www/yourdomain.com -type d -exec chmod 755 {} \;
find /var/www/yourdomain.com -type f -exec chmod 644 {} \;