Posted By Shahid Malla

How To Host a website on Ubuntu with Apache2 - Shahid Malla - WHMCS Expert Freelancer

To host a website on Ubuntu with Apache2, you can follow these steps:

  1. Install Apache2:
sudo apt-get update
sudo apt-get install apache2
  1. Configure Firewall to Allow Web Traffic:
sudo ufw app list
sudo ufw allow 'Apache'
  1. Create a new virtual host configuration file:
sudo nano /etc/apache2/sites-available/example.com.conf

Replace “example.com” with your domain name or IP address.

  1. Add the following configuration to the virtual host file:
<VirtualHost *:80>
    ServerAdmin webmaster@example.com
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/html/example.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Replace “example.com” with your domain name or IP address.

  1. Create the document root directory:
sudo mkdir -p /var/www/html/example.com/public_html
  1. Set ownership of the document root directory:
sudo chown -R $USER:$USER /var/www/html/example.com/public_html
sudo chmod -R 755 /var/www/html
  1. Create an index.html file in the public_html directory:
enano /var/www/html/example.com/public_html/index.html
  1. Add some content to the index.html file, save and exit.
  2. Enable the virtual host:
sudo a2ensite example.com.conf
  1. Restart Apache2:
sudo systemctl restart apache2

That’s it! You should now be able to access your website by going to your domain name or IP address in a web browser.

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x