Monday, September 4, 2023

Apache Configuration on Linux

 Here we will talk about how we can install and configure in Linux. we will deploy a site and will access it with DNS





Install Apache on Linux

To install Apache on Linux run following command step by step

sudo apt update

sudo apt update
sudo apt install apache2

now check apache is running or not to check you can run.(if the status is running then fine and apache installed and running successfully)

sudo systemctl status apache2


But if your apache status not running then for this you must need to enable and start it, by using following commands you can eamable and start appache2

Enable

sudo systemctl enable apache2
sudo systemctl start apache2

now hit 127.0.0.1 in browser and if it load the following page then its working fine



Deploy Website on DNS

To deploy our website on DNS (Domain Name Server) we need create virtual host first

Create VirtualHost

go to site-available folder for this you can do

cd /etc/apache2/sites-available

create here one more file to create virtual host for your site to create file your can run following command . this command will create file and will open your file in editor. after pasting following code in your file click esc button and then :wq your file will be saved

sudo vim leran-test.conf

now add following code in this file

<VirtualHost *:80>

 


ServerAdmin test@test

DocumentRoot /var/www/test

ServerName learn.test

ServerAlias www.learn.test

ErrorLog ${APACHE_LOG_DIR}/error.log

CustomLog ${APACHE_LOG_DIR}/access.log combined

 

</VirtualHost>

  • serverAdmin could be your server Eamil
  • DocumentRoot : add the path of your website's index page. (the site that i  want to deploy is stored  on /var/www/test.  ) in you case verify your site directory path
  • ServerName: add domain name with out www
  • ServerAlias: add domain name with www


Register your site in Hosts file

before registration of this domain name you must know about your local ip address to get this type following command .

sudo ifconfig
under enp0s1: with inet 192.168.64.2 will be  your local ip





Now we need to register our hosting in hosts file goto your etc folder and then open hosts file
cd /
cd etc
sudo vim hosts
now first type your ip and then your domain name like ( Example 192.168.64.2   learn.net) and then click esc button :wq to save and exit



Now  enable your site and reload the apache service by using following command

sudo a2ensite learn-test.conf // its your virtual host file name
sudo systemctl reload apache2 // it will reload appache service
and now hit your DNS in browser it will be work fie 



So  We have deployed website successfully 

Thanks
Previous Post
Next Post

post written by:

0 comments: