Sunday, September 28, 2014

VPS for WordPress basics [Part 7] - Install Apache Webserver

Apache Webserver is a very common today, you just imagine the Shared Hosting packages with cPanel X users are mostly used Apache before. Due to its popularity and easier to configure, so I will tell you practice, but for the most optimal use nginx webserver but will not talk to her in the first post.

Contents content

I. What is Webserver?
II. How to install Apache Webserver
III. How to create a VirtualHost for Apache
TIPS: adding VirtualHost Quick Trick
Epilogue

I. What is Webserver?

Webserver as a service (service) you support displaying data to a user on the VPS via default port 80 A webserver can create multiple VirtualHost, and each virtualhost can carry 1 IP and 1 different domains .
Speaking more understandable, VirtualHost is how you add another 1 domain on VPS to run on that site.

II. How to install Apache Webserver

Please log in to SSH and conducting command yum action is install and the package name is httpd .
1
sudo  yum install  httpd
If it's like this, the press asked y  then enter offline.
1
2
3
Total download size: 1.1 M
Installed size: 3.4 M
Is this ok [y / N]:
After it appeared Complete text! ie installed successfully.
Next is to conduct service httpd restart they have installed.
1
sudo  service httpd start
if it is currently " httpd: Could not reliably quyết the server's fully qualified domain name, using 127.0.0.1 for ServerName "then let it, but just because you do not point the hostname only IP. In the end all I have to show you how to change it from the press anymore ServerName.
Now you try to access the website with the IP address of the VPS to see if it appears the Welcome page of Apache's success.
rule-apache-webserver-finish-2
But there is a problem is the service you installed will not start automatically if you reboot the VPS, so you will need to type this command to add to the list given service httpd restart automatically when rebooting.
1
sudo  chkconfig httpd on
By default, the data show the website will reside in the / var / www . You can access it to upload any file on it's path accessible by your VPS IP.

III. How to create a VirtualHost for Apache

The above is just the installed Apache and I do not encourage you to use the directory / var / www to upload to the website, but to create a new folder at your disposal and then add the domain to use for the folder, the This we will call VirtualHost  (Virtual Host).
To create a VirtualHost, the first thing that you need to create a public_html folder (or you can also customize your recording is www) in a given folder, its here to encourage you to put in / home / webdata / name-domain.com . We proceed to create a directory with the following command:
1
sudo  mkdir  -p / home / webdata / thachpham .dev / public_html
Do you remember instead thachpham.dev the domain that you want to add to the VPS, the parameter p here it means that you are forced to manually create folders on stage if it is not there. For instance in the directory / home its no webdata / So we will use the parameter p to pressure it creates folders webdata / .
You can check that it has not successfully created with the command  ls / home .
Next we will give the user apache and group apache owns this directory because this directory is owned by conducting create your user instead CHMOD safer.
1
sudo  chown  -R apache: apache / home / webdata / thachpham .dev
Also added is the apache user and group apache it was automatically created when you install Apache Webserver on VPS.
You can check the ownership of this directory with the command:
1
ls  -al / home / webdata / thachpham .dev
Next, create a file index.html in the directory for a little /home/webdata/thachpham.dev/public_html we will examine, with the following contents:
1
sudo  vi  / home / webdata / thachpham .dev / public_html / index html
1
2
3
4
5
6
7
8
html >
  head >
    title > Welcome </ title >
  </ head >
  body >
    h1 > You have set the bar bent VirtualHost </ h1 >
  </ body >
</ html >
Next, open the file /etc/httpd/conf/httpd.conf (Apache configuration file):
1
sudo  vi  / etc / httpd / conf / httpd .conf
Find this section:
1
2
#Listen 12.34.56.78:80
Listen 80
Make sure the part Listen you are pointing to port 80 because this is the default port of the webserver.
Find more  #ServerName www.example.com:80 and revised toServerName localhost .
Find more sections below:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
#NameVirtualHost *: 80
#
# NOTE: NameVirtualHost can not be used without a port specifier
# (Eg: 80) if mod_ssl is being used, Due to the nature of the
# SSL protocol.
#
#
# VirtualHost example:
# Almost any Apache directive unfortunately go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# Server name.
#
# <VirtualHost *: 80>
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs / dummy-host.example.com-error_log
# CustomLog logs / dummy-host.example.com-access_log common
# </ VirtualHost>
Then you remove comment marks (# sign) in some sections of the same below.
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
NameVirtualHost *: 80
#
# NOTE: NameVirtualHost can not be used without a port specifier
# (Eg: 80) if mod_ssl is being used, Due to the nature of the
# SSL protocol.
#
#
# VirtualHost example:
# Almost any Apache directive unfortunately go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# Server name.
#
<VirtualHost *: 80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /www/docs/dummy-host.example.com
ServerName dummy-host.example.com
ErrorLog logs / dummy-host.example.com-error_log
CustomLog logs / dummy-host.example.com-access_log common
</ VirtualHost>
Ok, now I want to add a domain thachpham.dev folder in/home/webdata/thachpham.dev/public_html in VirtualHost, I will read as follows:
1
2
3
4
5
6
7
8
<VirtualHost *: 80>
ServerAdmin contact@thachpham.com
DocumentRoot /home/webdata/thachpham.dev/public_html
ServerName www.thachpham.dev
ServerAlias ​​thachpham.dev
# ErrorLog /home/webdata/thachpham.dev/logs/thachpham.dev-error_log
# CustomLog logs / dummy-host.example.com-access_log common
</ VirtualHost>
I would like to explain the parameters in the above paragraph as follows:
  • VirtualHost *: 80 - This means that the domain will use port 80, you set the same as the port of Apache okay.
  • ServerAdmin - Email an administrator.
  • DocumentRoot - Root directory of this domain, we have created it in the first post.
  • ServerName - the domain of the VirtualHost.
  • ServerAlias ​​- Added option to access the domain without the www.
  • ErrorLog - Links webserver error log file of this domain.
  • Custom Log - This one I do not use, because it hits every note the log, consuming hard drive, add a # to disable.
In case you have multiple IP VPS and you want this VirtualHost use private IP, then add the 1 123 456 789 Listen in on the ServerAdmin .
After this you want to add more VirtualHost then just copy the above paragraph is only then corrected. Now we save the file and exit.
Ok, restart Apache so that it updates offline changes.
1
sudo  service httpd restart
1
2
Stopping httpd: [FAILED]
Starting httpd: [OK]
Part stopping it FAILED, then let it be, but just because we suddenly stop restart, restart again is knocked out.
Finally, point your domain to VPS or IP address you have set for VirtualHost okay, if that domain to access the file that we have created Welcome on the success.
apache-virtualhost-success
PRO TIPS : You do not necessarily have to use a real domain if you are practicing, for example, in his article thachpham.dev domain use. Then, just go to your hosts file on your computer and add the 123 456 789 thachpham.dev is finished. Of these, 123 456 789 is the IP of the VPS server that I need to point to, or their IP is added to the VirtualHost.

TIPS: adding VirtualHost Quick Trick

Rather than edit the httpd.conf file and add VirtualHost in it, you can change the following:
1
2
3
4
5
6
7
8
<VirtualHost *: 80>
ServerAdmin contact@thachpham.com
DocumentRoot /home/webdata/thachpham.dev/public_html
ServerName www.thachpham.dev
ServerAlias ​​thachpham.dev
# ErrorLog /home/webdata/thachpham.dev/logs/error_log
# CustomLog logs / dummy-host.example.com-access_log common
</ VirtualHost>
List
1
include /etc/apache/conf/domains/*.conf
This passage means that it will take all the data of files ending with .conf in the directory / etc / httpd / conf / domains / put in the httpd.conf file. Then you place the folder conf / domains create a folder / file name is then created 1 thachpham.dev.conf and paste this content into:
1
2
3
4
5
6
7
8
<VirtualHost *: 80>
ServerAdmin contact@thachpham.com
DocumentRoot / home / webdata / thachpham .dev / public_html
ServerName www.thachpham.dev
ServerAlias ​​thachpham.dev
# ErrorLog /home/webdata/thachpham.dev/logs/thachpham.dev-error_log
# CustomLog logs / dummy-host.example.com-access_log common
/ VirtualHost >
VirtualHost later if needed, you just need to copy the file to the other thachpham.dev.conf, renamed domain need to replace and repair thachpham.dev file into your new domain.

Epilogue

In this lesson we learn how to install Apache Webserver past and VirtualHost setup for it.This is an important step that you can do the work many times for fluency to be able to be more active in the future.
But now you no where to run WordPress because we lack PHP and MySQL applications, we will install in the next post.

0 nhận xét:

Post a Comment