Apache2
Installation
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install apache2
sudo systemctl start apache2
sudo systemctl enable apache2
sudo systemctl status apache2 # should be active
sudo ufw allow in "Apache Full"
Testing to host
- Make directory.
mkdir /var/www/html/random.com
- Create
index.html
in /var/www/html/random.com
.
<html>
<title>site1.example.com</title>
<h1>Welcome to site1.example.com Website</h1>
<p>This is my first website hosted with name-based virtual hosting</p>
</html>
- Change ownership of directory to www-data.
sudo chown -R www-data:www-data /var/www/html/random.com
- Create an Apache virtual host config file
/etc/apache2/sites-available/random.com.conf
.
<VirtualHost *:80>
ServerAdmin admin@random.com
ServerName random.com
DocumentRoot /var/www/html/random.com
DirectoryIndex index.html
ErrorLog ${APACHE_LOG_DIR}/random.com_error.log
CustomLog ${APACHE_LOG_DIR}/random.com_access.log combined
</VirtualHost>
- Enable and restart apache2.
a2ensite random.com
sudo systemctl restart apache2
- Add your DNS record to DNS resolver, like Route 53, by mapping Domain name to Public IPv4 address.
Conflicts
- Failed to start The Apache HTTP Server. This may be caused by another load balancer nginx.
sudo systemctl status nginx
sudo systemctl stop nginx
References
- Host Multiple Websites on a Single Server with Apache on Ubuntu 18.04
- Can I run nginx and apache at the same time?