Adding a new site to a server is a great deal when it comes to adding them or even editing them on an Apache based server. Plus the need of the hour shouts out loud that if you are willing to add the server with several other websites with different domain names or sub domain names. Let me make the solution for your trouble of adding them all to the server. Here is a bit easier solution for you. With the following steps which you can tag on actually ‘step by step’ to solve things easily.
Before tagging on the steps I will help you clear the air with some prerequisites for sure:
- CentOS server used should be of the latest version.
- The OS combo that one should have is Windows – Putty and Mac, Linux – Terminal
- Software for the server to work should be a well updated one with a good hosting for website.
- Now enough of requisites let’s talk the real stuff. Follow them religiously and you will know the difference.
How To Add New Site Into Your Apache-based CentOS Server :
Step 1- First thing is first- LOGIN!
Without a tutorial logining in to the server moving ahead is simply out of question. After getting in login as your name with sudo prefix. This can be done if the login name is already in use along with the root privilege. Even tying an ‘su’ and ‘Enter’ will serve the deal. Next while entering the root directory type cd~
Step 2- The RIGHT commands
When the new website has to surface one has to be clear with the root directory which you add as a new document to the same. Let me help you with some commands wherein instead of xyz.com you can place the domain in which you want to work for.
The command is as under:
mkdir -p /var/www/xyz.com/public_html
mkdir -p /var/www/xyz.com/htdocs
Here both the commands with public_html as well as htdocs can be used valiantly.
Step 3- Permission Prior Admission
If you have switched the login details from being in the form of a user or a root then the command needs to be taken well care of like:
chown -R username:username /var/www/xyz.com/public_html
But if the command you used is used along with the root privilege then it should look something like this:
sudo chown -R www:www /var/www/xyz.com/public_html
A sudo can definitely change your output Step 4- www directory Changes
The directory means something to be used or which is expected to be used by everyone, right? The why would not you want your website to be used globally? Yes you would like it to, right? Then have the following command stated:
chmod 755 /var/www
Step 5- New Domain needs Apache hosts files, right? Configuring the Apache virtual hosts file to have a website added is the biggest step forward. Editing httpd.anf file will be just the beginning.
Command to be next issued will be:
Later search for these lines below:
#Listen 126.96.36.199:80 Listen 80
The listen to port 80 is what is compulsory now. Make sure you have that for sure.
Next thing you need to do is unless and until you see these commands beneath after continuously hitting the Ctrl and V, don’t stop!!
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. #
Of course removing the hashtag (#) will be what you do next to clear things from your commands.
Sign in the above command simply means the symbol of your IP. If you have more than one of those then you are free to put in those symbols without keeping the count.
After certain required alterations like:
Removing the # symbols
Changing the email ids
Also setting up the servers with more elaborate ErrorLog and CustomLog lines will be a great option to bide with even if they are not compulsory.
After a short time when things get into place and the commands are aptly done with the window will have these lines:
<VirtualHost *:80> ServerAdmin firstname.lastname@example.org DocumentRoot /var/www/xyz.com/public_html ServerName www.xyz.com ServerAlias xyz.com ErrorLog /var/www/xyz.com/error.log CustomLog /var/www/xyz.com/requests.log
A ctrl O button will save the file with a ctrl X exiting the editor once and for all.
Step 6- The Inception
Finally after so much of edits and inputs its time for the process to run.
TO kill the processes type:
apachectl -k stop
To begin with what you just created type:
service httpd start
Hence your server is now ready to go online on your webiste.
Step 7- Testing Testing ONE TWO THREE
Testing is necessary a part because without doing that it is a huge risk to allow your website fall into unwanted scrutiny so before allowing it to actually go live, do some dummy tests to see if things are all set as it should be.
The test page will be available at:
/var/www/domain.com/public_html/index.html <html> <head> <title>Apache is really working</title> </head> <body> <h1>Success: You Have Set Up a Virtual Host</h1> <p>This is test page for domain.com</p> </body> </html>
Bang! There you go! Open the last used browser window and type the domain for which you did all these ups and downs. This will open a virtual view hosting of the domain and later with further edits and add-ons you can surely make use of the website which goes live for everyone!
With this ready to go server you have things in your hands now! Have a great time using these.
Hope these tips and steps for the new server helps you beyond need and hope you get through the troubles using the browser by these simple steps.