Prerequisite
- A working CentOS server. In this guide I am using CentOS 6.3 x32.
- Windows users should download Putty while Mac and Linux users can simply use Terminal
- You’ll also need a basic skill to use Putty and to navigate through SSH. .
- Your server should already has necessary software to host a website. In this case are: Apache, PHP5, and MySQL.
- About 15 minutes of your time and a cup of tea if you like.
The How To Steps
Step 1 – Login to your server and follow my previous guide about Basic setup for CentOS before you build a live web server. You may and may not follow that tutorial but if you followed, it will give you some basic security tweak to your server.Before you proceed to the next steps, it is better to explain that all commands in this tutorial are written without the “sudo” prefix. However if you disabled root login and you logged in using another username with root privilege, you can add the “sudo” prefix all by your self. Alternatively you can simply type su, hit Enter and type in your password twice to switch login as root.
You may also need to type this command to go to the root directorty:
1
| cd ~ |
1
| mkdir -p /var/www/domain .com /public_html |
1
| mkdir -p /var/www/domain .com /htdocs |
- Replace “domain.com” with your actual domain name. Do this in all part of this tutorial.
- In this example (in screenshot pics) I use “fikitips.com” as my domain. Why? Because that domain is currently unused so I use it as my testing purpose.
- You can use either the “public_html” or “htdocs” as the name of your directory but in this example I’ll use “public_html”.
1
| chown -R username:username /var/www/domain .com /public_html |
If you are still logging in as user (with root privilege), use this command instead:
1
| sudo chown -R www:www /var/www/domain .com /public_html |
1
| chmod 755 /var/www |
Step 5 – Activate Apache virtual hosts file for the new domain. Now you have to setup and configure Apache virtual hosts file to add your new website. In this stage you need to edit “httpd.conf” file. Issue this command:
1
| nano /etc/httpd/conf/httpd .conf |
1
2
| #Listen 12.34.56.78:80 Listen 80 |
Found it? Make sure it listen to port 80.
Next, scroll down again or hit Control+V several times until you see this section (in screenshot pic) below:
Now remove / delete the # symbol. So it’ll look like this:
1
2
3
4
5
6
| 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. # |
Once done, right below that section you’ll see:
What you have to do:
- Remove all the # symbols before the <VirtualHost *:80> until </VirtualHost>.
- Change email address at “ServerAdmin” line.
- Change the document root path at “DocumentRoot” line.
- ErrorLog and CustomLog lines are optional but you better also set it up to log issues that arise while maintaining the server.
1
2
3
4
5
6
7
8
| <VirtualHost *:80> 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 < /VirtualHost > |
That’s it. Now hit Control+O on your keyboard to save followed by Control+X to exit Nano editor screen.
Step 6 – Finally restart Apache service and all its processes. Issue this command first:
1
| apachectl -k stop |
1
| service httpd start |
1
| /etc/init .d /httpd start |
Step 7 – Give it a test. Now your server is basically ready to host your site but you better give it a test before actually deploying / moving your site in. For that purpose you can use this test page:
1
| /var/www/domain .com /public_html/index .html |
1
2
3
4
5
6
7
8
9
| < 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 > |
Finally, open your most favorite web browser then access your server. You can do that by typing its IP address or domain name if you’ve updated your domain’s DNS records. It should look like this:
Congratulation, you server is now ready. You can now upload your site’s files to your server via your favorite FTP client app.
p.s: You can follow the whole steps above to add another website (with new domain name) to your server
Another tip:
Also do following step if you want to enable .htaccess usage for your website. Open Nano editor to edit httpd.conf file again: You’ll only need to do this once.
1
| nano /etc/httpd/conf/httpd .conf |
1
2
3
4
| <directory /> Options FollowSymLinks AllowOverride none < /directory > |
<directory /> Options FollowSymLinks AllowOverride all </directory>Once done, hit Control+O to save followed by Control+X to exit.
No comments:
Post a Comment