Mar 24, 2023

Apache 2 Server : Installation in Ubuntu Server v.22.04.2

 Apache 2 Server Installation in Ubuntu Server v.22.04.2

1. Ensure Ubuntu repository is up-to-date.

sudo apt update && sudo apt upgrade -y

 

2. Install Apache 2 server.

sudo apt install apache2 -y

 

3. Double check UFW settings and configure to allow. Below is to list all "Allow" apps:-

sudo ufw app list

 This is to show UFW status.

sudo ufw status

 This command is to add "Apache2" into allow list

sudo ufw allow ‘Apache’

 

4. Create a virtual directory for Apache 2 server. Replace [Domain Name] with your actual domain name (eg. intranet.company.com)

sudo mkdir /var/www/[Domain Name]

 

5. Change the ownership of that folder.

sudo chown -R $USER:$USER /var/www/[Domain Name]

 

6. Change the mode of that folder.

sudo chmod -R 755 /var/www/[Domain Name]

 

7. Now create a temporary "index.html" file for testing of the new virtual directory.

sudo nano /var/www/[Domain Name]/index.html

 Copy the below code as an example then Save and Exit.

<html>

    <head>

        <title>WELCOME TO [DOMAIN NAME] !</title>

    </head>

    <body>

        <h1>SUCCESS ! THE [DOMAIN NAME] VIRTUAL HOST IS WORKING !</h1>

    </body>

</html>

 

8. Create a configuration for your virtual host.

sudo nano /etc/apache2/sites-available/[Domain Name].conf

 Copy the following code and then Save and Exit.

<VirtualHost *:80>

    ServerAdmin webmaster@localhost

    ServerName [Domain Name]

    ServerAlias www. [Domain Name]

    DocumentRoot /var/www/[Domain Name]

    ErrorLog ${APACHE_LOG_DIR}/error.log

    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

 

9. Enable the newly created site.

sudo a2ensite [Domain Name].conf

 

10. Disable the "Default" site.

sudo a2dissite 000-default.conf

 

11. Now test the configuration of the new site.

sudo apache2ctl configtest

 It should return --> "Syntax OK" message.


12. Restart the Apache service to take effect.

sudo systemctl restart apache2

 

13. Now open any browser and browse to the new site (eg. http://[Domain Name])


Edit: Added video for easy references.




!!! HAPPY COMPUTING !!!


No comments:

Post a Comment