DEV Community

technonotes-hacker
technonotes-hacker

Posted on

Apache2 in Local Machine

08-08-2023

What is Apache2 server ?

  1. Apache is a open-source software .
  2. Developed by " Apache Software Foundation ".
  3. Its a WEB HOSTING SERVER.

Install Apache2 over the system :

sudo apt install apache2
systemctl status apache2
Enter fullscreen mode Exit fullscreen mode

Image description

sudo systemctl start apache2
Enter fullscreen mode Exit fullscreen mode

Image description
This error is due to another server with same functionality is running,

sudo systemctl stop nginx
sudo systemctl status nginx
Enter fullscreen mode Exit fullscreen mode

Image description

sudo systemctl disable nginx
Enter fullscreen mode Exit fullscreen mode

Now start the apach2 server,

sudo systemctl start apache2
sudo systemctl status apache2
sudo systemctl enable apache2
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

cd /var/www/html/  --> Edit the index.html file
vi /etc/hosts      --> Add the entry of the host
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Image description

All these are local machine changes, so this won't be available in INTERNET.

One Machine - 1 Site
One Machine - Multiple Site ( Virtual )

Types of hosting a web server:

  1. Name based eg., site1.name.com & site2.name.com
  2. Port based Virtual Hosting
  3. IP based

Now creating Name based Virtual Hosting ,

cd /var/www/html
sudo mkdir site1.test.com
sudo mkdir site2.test.com
Enter fullscreen mode Exit fullscreen mode

Image description

now go inside these folders ,

Image description
Image description

Permission Change:

Current owner of the files & folders,

Image description

This permission change is required , as these are in ROOT permission it may create some issue in future , so always better to change to any user. Here we are using "www-data".

www-data ---> Who is this default user ? Apache2 user.

sudo chown -R www-data:www-data site1.test.com site2.test.com
Enter fullscreen mode Exit fullscreen mode

Image description

Configuration Files :

cd /etc/apache2/
cd /etc/apache2/sites-available
Enter fullscreen mode Exit fullscreen mode

Image description

Create a configuration file inside this folder for the two sites,

/etc/apache2/sites-available
sudo vi site1.test.com.conf
Enter fullscreen mode Exit fullscreen mode

Image description

Sample Entry Below,

<VirtualHost *:80>
ServerAdmin admin@apple.hashlabs.in
ServerName apple.hashlabs.in
DocumentRoot /var/www/html/apple.hashlabs.in
DirectoryIndex index.html
ErrorLog ${APACHE_LOG_DIR}/apple.hashlabs.in_error.log
CustomLog ${APACHE_LOG_DIR}/apple.hashlabs.in_access.log combined
</VirtualHost>
Enter fullscreen mode Exit fullscreen mode

Image description


sudo a2ensite site1.test.com
sudo systemctl reload apache2
sudo systemctl restart apache2

sudo a2ensite site2.test.com
sudo systemctl reload apache2
sudo systemctl restart apache2
Enter fullscreen mode Exit fullscreen mode
sudo vi  /etc/hosts
Enter fullscreen mode Exit fullscreen mode

Image description

Image description

Image description

Image description

Image description

Important & Reference:

  1. https://github.com/alebcay/awesome-shell
  2. https://www.nginx.com/ --> WEB HOSTING SERVER
  3. SHIFT + CONTROL + P --.> Private Tab
  4. a2ensite ? a2ensite is a script that configures apache2 to enable the provided site (which contains a block). It accomplishes this by generating symlinks in /etc/apache2/sites-enabled . (or) a2ensite is a script that enables the specified site (which contains a '<'VirtualHost'>' block) within the apache2 configuration. It does this by creating symlinks within /etc/apache2/sites-enabled. Likewise, a2dissite disables a site by removing those symlinks.
  5. digitalocean - Try this site too to buy cloud.
  6. https://httpd.apache.org/ - Apache2 website
  7. https://www.javatpoint.com/what-is-apache

Top comments (0)