Base de Conhecimento

How to Install Apache Web Server on Ubuntu

Apache (httpd) is one of the most widely used web servers. This guide covers installing it on Ubuntu and creating a virtual host.

1. Install Apache

sudo apt update
sudo apt install -y apache2

2. Start, enable and allow through the firewall

sudo systemctl enable --now apache2
sudo ufw allow 'Apache Full'

3. Create a virtual host

sudo mkdir -p /var/www/example.com/public_html
sudo nano /etc/apache2/sites-available/example.com.conf

Paste the following, replacing example.com with your domain:

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

4. Enable the site and reload

sudo a2ensite example.com.conf
sudo apache2ctl configtest
sudo systemctl reload apache2

For HTTPS, install Certbot with sudo apt install certbot python3-certbot-apache and run sudo certbot --apache.

Esta resposta foi útil?

1 Utilizadores acharam útil

Powered by WHMCompleteSolution