How to Add New Site to Apache

Login into root or root user

cd into root directory

cd ~

Make your website directory

Mkdir –p /var/www/yourdomain.com/public_html

Or

Mkdir –p /var/www/yourdomain.com/htdocs

Give ownership permission to user (if you login from user to root)

Chown –R user:user /var/www/yourdomain.com/public_html or htdocs

Change directory permission

Chmod 755 /var/www

Configure Apache hosts file for the new domain

vi /etc/httpd/conf/httpd.conf

Make sure apache is listening on port 80

Look for:
#Listen IPadress:80
Listen 80

Scroll down and look for:

#NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#

Remove the # symbol from #NameVirtualHost *:80

NameVirtualHost *:80
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#

If you have only one IP you can replace the * with your ip 123.123.123.123:80

Below that section you will see:

#
# ServerAdmin youremail@domain.com
# DocumentRoot /var/www/domain.com/public_html
# ServerName www.domain.com
# ServerAlias domain.com
# ErrorLog /var/www/domain.com/error.log
# CustomLog /var/www/domain.com/requests.log
#

Remove all the # symbol
ServerAdmin youremail@domain.com
DocumentRoot /var/www/domain.com/public_html
ServerName www.domain.com
ServerAlias domain.com
ErrorLog /var/www/domain.com/error.log
CustomLog /var/www/domain.com/requests.log

Once done, save the file

:wq!

Restart apache and httpd

Apachectl –k stop – This will stop all apache process

Service httpd restart

Or

Service httpd stop/start

Finally you can access the web browser and type in the IP or yourdomain.com

Leave a Reply

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