The way Apache is now setup it will always look into
Code:
/usr/local/apache2/conf/v-hosts
For a v-host file. A v-host file is basically a configuration file for each website you want to run. If you run just one website then you only need one file there as well.
Remember the MySQL database we have created at the beginning ? Now we build the website for it.
- Create a v-host file called ie centos-test.domain.com
Code:
# vi /usr/local/apache2/conf/v-hosts/centos-test.domain.com
And put the following code in
Code:
<VirtualHost <IP here>:80>
ServerName centos-test.domain.com
ServerAlias centos-test.domain.com
ServerAdmin mail@centos-domain.com
DocumentRoot /home/centos-test/htdocs/
ScriptAlias /cgi-bin /home/centos-test/cgi-bin
ErrorLog /home/centos-test/logs/error_log
CustomLog "|/usr/local/sbin/cronolog /home/centos-test/logs/log.%Y%m%d" zeus
DirectoryIndex index.php index.htm index.html
</VirtualHost>
<Directory "/home/centos-test/htdocs">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
- Create a user the website should run under
Code:
# adduser centos-test
- Create necessary directories
Code:
# mkdir /home/centos-test/htdocs
# mkdir /home/centos-test/cgi-bin
# mkdir /home/centos-test/logs
- Set the approriate permissions
Code:
# chmod -R 2750 /home/centos-test
# chown -R centos-test:www /home/centos-test
- Give user a password
Code:
# passwd centos-test
<enter new password here>
- Reload the Apache config
Code:
# service httpd reload
Basically if someone is now browsing to
centos-test.domain.com, the server checks all v-host files if it finds the approriate value. It will now find in the v-host file we have just created, that the homefolder for this website is
/home/centos-test/htdocs.
Now its time to create the website (this point is now covered in the movie also, but not the creation of the v-host file itself).
If you now browse to the domain mentioned, you should just see something like "Index of /" as directory browsing is allowed and there are no files in yet.
- Create a simple index.html page
Code:
# vi index.html
Put anything in
Browsing to the domain should display the content of the index.html.
Now we want to check whether PHP and MySQL is working as well.
- Create a php file called "connectio.php"
PHP Code:
<?php
$hostname_connection = "localhost";
$database_connection = "connection";
$username_connection = "connection";
$password_connection = "connection";
$connection = mysql_pconnect($hostname_connection, $username_connection, $password_connection) or die(mysql_error());
mysql_select_db($database_connection, $connection);
$query_mysql_test = "SELECT connection FROM connection";
$mysql_test = mysql_query($query_mysql_test, $connection) or die(mysql_error());
$row_mysql_test = mysql_fetch_assoc($mysql_test);
$totalRows_mysql_test = mysql_num_rows($mysql_test);
?>
<html>
<head>
<title>connection</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php echo $row_mysql_test['connection']; ?>
</body>
</html>
<?php
mysql_free_result($mysql_test);
?>
Browsing now to
http://centos-test.domain.com/connection.php should display the content of the table we have created earlier.
Obviously I cannot cover EVERYTHING, but this should give you a good overview in how to do it. I also assume at this point that you know for example how to use an editor, such as "vi" or "nano".
I also assume that you you know how to setup DNS / IPs and domains etc. as this would really too much to cover here too.
But as a quick tip:
If you want to test this for example on vmware at home with an IP in your private network, simple give that server a private IP, such as 192.168.1.100 and use this IP in all those v-host files you have created.
Now you can even use centos-test.domain.com as URL - HOWEVER, your ADSL provider or / and router obviously doesn't that that this URL should go to your test vm
In order now to make it work (in Windows), add this URL to your HOST file.
In
C:\WINDOWS\system32\drivers\etc
You will find a file called HOSTS, which looks like
Code:
# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
So here simply add the URL and IP of your test PC
So the full file should look simething like this
Code:
# Copyright (c) 1993-1999 Microsoft Corp.
#
# This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
#
# This file contains the mappings of IP addresses to host names. Each
# entry should be kept on an individual line. The IP address should
# be placed in the first column followed by the corresponding host name.
# The IP address and the host name should be separated by at least one
# space.
#
# Additionally, comments (such as these) may be inserted on individual
# lines or following the machine name denoted by a '#' symbol.
#
# For example:
#
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
192.168.1.100 centos-test.domain.com
If you now put the URL into your browser, you should see the testpage just fine.
So I hope I can help someone with this
Back to my beer now.....
Movie Download
13 - Final Test (01:06) - avi
13 - Final Test (01:06) - rar
All packages used to install this testserver and movies can be found here :
http://linux.mike666.co.uk/