1. create a directory using the following command.

sudo mkdir -p /var/www/example.com/public_html

2. Grant Permission to your newly directory

sudo chown -R $USER:$USER /var/www/example.com/public_html

sudo chmod -R 755 /var/www/example.com/public_html

3. Create a new config file using default config file

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/example.com.conf

4. Edit example.com.conf file

a) Run

sudo nano /etc/apache2/sites-available/example.com.conf

b) Paste the below code and save the file

ServerAdmin admin@example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example.com/public_html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

5. Enable site using following command

sudo a2ensite example.com.conf

6. Restart Apache server

sudo service apache2 restart

7. Set ip in host file
a) Run

sudo nano /etc/hosts

b) Add IP e.g xxx.xxx.xxx.xxx example.com

8) Create index.html file

sudo nano /var/www/example.com/public_html/index.html

add any html here like

Hello World!

9. Now run http://www.example.com on browser.

Categories: Linux

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *