Installing and Configuring Apache

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 {} \;
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Managing Users and Groups

Managing Users and Groups on Linux Proper user management is essential for server security. Avoid...

Managing Services with systemctl

Managing Services with systemctl systemctl is the standard tool for managing services on modern...

Monitoring Server Resources

Monitoring Server Resources Keeping an eye on your server's resource usage helps you identify...

Scheduling Tasks with Cron

Scheduling Tasks with Cron Cron allows you to schedule commands to run automatically at set...

Installing and Configuring Nginx

Installing and Configuring Nginx Nginx is a high-performance web server and reverse proxy widely...