Skip to main content

How To Configure Apache Virtual Hosts on CentOS 7

Introduction

Virtual Hosts are used to run more than one domain off of a single IP address. This is especially useful to people who need to run several sites off of one virtual private server.

Requirements

  • A desktop machine running Linux
  • A static IP address.

Set Up

sudo yum update
sudo yum install httpd (for Centos )
sudo apt-get install httpd (for Ubuntu )
start Httpd service
/etc/init.d/httpd start ( Centos )
/etc/init.d/apache2 start  ( Ubuntu )

Create a New Directory

First,make a directory structure where we will keep the new website’s information.
mkdir -p /var/www/html/www.sam.com

Grant Permissions

chown -R apache:apache /var/www/html/www.sam.com\
chmod -R 755 /var/www/html

Create the Page

We need to create a new file called index.html within our configurations directory.
Vim /var/www/html/www.sam.com/index.html
Add the following content.
<html>
<head>
<title>www.sam.com</title>
</head>
<body>
<h1>The sam.com virtual host is working!</h1>
</body>
</html>
Save and close the file when you are finished.

Turn on Virtual Hosts

The next step is to enter into the apache configuration file itself.
sudo vi /etc/httpd/conf/httpd.conf
#Listen 12.34.56.78:80
Listen 80
<VirtualHost *:80>
ServerName www.sam.com
ServerAlias sam.com
DocumentRoot /var/www/html/www.sam.com
ErrorLog /var/www/html/www.sam.com/error.log
CustomLog /var/www/html/www.sam.com/access.log combined
</VirtualHost>
Save & Exit
When you are finished, You can check the syntax of files with the following command:
sudo apachectl configtest
After the syntax check is done, restart Apache to make these changes take effect.
sudo systemctl restart httpd

Setting Up the Local Hosts

Now, you need to create DNS record for www.vhost1.com to test the virtual hosts. One easy way is to add a “domain name to IP mapping” entry to the /etc/hosts file.
Add the following lines, using the static IP address of your server:
127.0.0.1  www.sam.com
Save and exit the file.
Now on the desktop Linux computer, open your web browser and go to the URLs
http://www.sam.com

Comments

Popular posts from this blog

Why Prestashop is the best eCommerce platform?

Why Prestashop is the best eCommerce  platform? E-commerce is the current buzzword in the online world. Every business owner desires to have online eCommerce website to reach many people and get more sales. Prestashop is the one of the best eCommerce solution for the best eCommerce site because of its feature. Free, Open-source Prestashop is totally free to download, You don't need to pay for using it. Supports whenever you need them. Best part of this is you don't need to search for the required documentation as these are available on the website of Prestashop. Easy to Install  And Smart Back-End Prestashop scores very high in the segment of usability. The installation is very easy and the installation requires very little technical skills. PrestaShop helps you to run your store in a manner that proves beneficial for you. It is highly impressive and it is even integrated with all the major carriers such as UPS, FedEx and USPS. Also, the backend dashboard o...

Latest PHP web development trends

1) Faster and leaner PHP 7 - PHP 7 looks familiar for developers, but it is especially focused on high performance. - Experts predict the growth of PHP 7 adoption rate, and they have several reasons for verifying such forecast.  - Using PHP 7 the performance of applications has gained up twice comparing with older versions.  - RAM consumption was decreased by 50% during the request processing in PHP 7. - Previously there are many errors which are reason of application stop working now those can be processed as exceptions - The most popular CMS and frameworks such as WordPress, Magento and Symfony ready for PHP 7. - All these changes of PHP 7 increase application speed and reduce resources needs. 2) Market forecast - Experts predict that by 2025 half of American enterprises are expected to run more than 10 applications. - Though PHP cannot be the best choice for any web solutions, it is still holding the lead positions in the development of tech startups...

Sass

Sass: Here we are now introducing some other facts about the Sass Css Framework. Sass is the latest framework of css that is trending now very fast and it's professional, mature and powerful grade css version comparing to old versions. The Sass css is adapted by bootstrap also and other framework also so it is going fastly worldwide and many more industries are not moving to Sass. Basically Sass is the precompiled css version. It is help to load the page fastly then older css versions. Sass can be compiling through Gulp Js, Grunt and other compiler software also. It is latest version but still it is compatible with the all old versions of the css frameworks. It is working with the dynamic variables like for colors, spacing and different sections containers etc. Like, in this css framework the value of color is described once in variable but the variable can be used multiple time and in many files so if we want to change the color so we just have to change at one place...