Apache 2 Web server on Ubuntu 24.04 22.10 20.04.5 18.04.6 16.04.7 install
Install Apache2 web server ...
sudo apt update
sudo apt install apache2
Edit file:
sudo nano /etc/apache2/apache2.conf
Add:
ServerName 127.0.0.1
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Commands:
sudo systemctl restart apache2
sudo systemctl status apache2
sudo apache2ctl configtest
sudo a2enmod rewrite
Edit:
sudo nano /etc/hosts
Add:
127.0.0.1 localhost
127.0.0.1 youdomain.com
127.0.0.1 mail.youdomain.com
127.0.1.1 ubuntu
Add ruls to ufw:
sudo ufw allow in "Apache Full"
Creating directories and granting privileges ...
sudo mkdir -p /var/www/youdomain.com/public_html
sudo chmod -R 755 /var/www/youdomain.com/public_html
sudo chown -R www-data:www-data /var/www/youdomain.com/public_html
Enable ssl with command ...
sudo a2enmod ssl
Create Apache Virtual Host for you web site youdomain.com
sudo nano /etc/apache2/sites-available/youdomain.com.80.conf
sudo nano /etc/apache2/sites-available/youdomain.com.443.conf
Enable http 80 port addn to file youdomain.com.80.conf
<VirtualHost *:80>
ServerName youdomain.com
ServerAlias www.youdomain.com
ServerAdmin This email address is being protected from spambots. You need JavaScript enabled to view it.
DocumentRoot /var/www/youdomain.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory />
Options +Indexes +FollowSymLinks +ExecCGI
AllowOverride All
Order deny,allow
Allow from all
Require all granted
</Directory>
Enable https 443 port addn to file youdomain.com.443.conf
<VirtualHost *:443>
ServerName youdomain.com
ServerAlias www.youdomain.com
DocumentRoot /var/www/youdomain.com/public_html
SSLEngine On
SSLCertificateFile /etc/ssl/certs/youdomain.com.crt
SSLCertificateKeyFile /etc/ssl/private/youdomain.com.key
</VirtualHost>
To disable Virtual Host:
sudo a2dissite 000-default.conf
To enable Virtual Host:
sudo a2ensite youdomain.com.80.conf
sudo a2ensite youdomain.com.443.conf