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

  1. Make directory.
  2. 
    mkdir /var/www/html/random.com
        
  3. Create index.html in /var/www/html/random.com.
  4. 
    <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>
        
  5. Change ownership of directory to www-data.
  6. 
    sudo chown -R www-data:www-data /var/www/html/random.com
        
  7. Create an Apache virtual host config file /etc/apache2/sites-available/random.com.conf.
  8. 
    <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>
        
  9. Enable and restart apache2.
  10. 
    a2ensite random.com
    sudo systemctl restart apache2
        
  11. Add your DNS record to DNS resolver, like Route 53, by mapping Domain name to Public IPv4 address.

Conflicts

  1. Failed to start The Apache HTTP Server. This may be caused by another load balancer nginx.
  2. 
    sudo systemctl status nginx
    sudo systemctl stop nginx
        

References


  1. Host Multiple Websites on a Single Server with Apache on Ubuntu 18.04
  2. Can I run nginx and apache at the same time?