LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-09-2008, 03:46 PM   #1
utw-mephisto
Member
 
Registered: Apr 2005
Posts: 93

Rep: Reputation: 16
Lightbulb My HOW-TO: LAMP on CentOS from Source (including Movies)


I am not a professional when it comes to Linux, but I am working in that environment so I had to learn it the hard way and made some notes in the process

My "way" isn't necessarily the best, fastest or more secure way. It just works. I thought this might help someone who needs to setup a LAMP Server.

LAMP btw. means

Linux - Apache - MySQL - PHP

So this is a Video-Howto for the installation of a LAMP server based on CentOs ... During the installation you will see I install only the BASE - nothing fancy - no GNOME, nothing, just a base .. You can obviously install things like MySQL etc. as a package during the installation of CentOS - but there is no learning benefit of it and even more important : as a beginner you simply have no idea where it puts all the files which makes it a bit hard when it comes to troubleshooting.

The installation of RedHat ES is exactly the same as CentOS is based on it, just 7 days older when it comes to patches etc.

In order to use "yum" though - RH ES needs to be activated which obviously cost money - so Simply use CentOS. Get CentOS here.

I will also provide the packages I have used to make it easier for you.

All packages and video can be found here :

http://linux.mike666.co.uk/

I provide the videos in both, uncompressed and rar'ed ... The avis are Microsoft uncompressed as well so you don't need any codecs (or shouldn't really).

The way I install Linux is mostly using the TEXT mode. Graphic mode is pretty much the same - but since my server is not next door I need to minimize the bandwidth required since I normally don't fancy a slloooooow mouse etc. So the text mode simply speed things up.

Some parts may not needed by you etc., I simply used my notes in order to install it so I will specify whether this is needed or not. Although there is no harm in installing those packages. Over the time we simply needed certain packages so this way its just "complete".

So this guide gives youFrom that point on I will give short and simple instructions and commands used in the video. Btw., for some reason VLC seems to show only a grey picture - but MediaPlayer and even QuickTime show the movies just fine - so no idea why - I blame M$$ :P

Here is a screenshot of the quality of the movies

http://linux.mike666.co.uk/Sample.JPG

This installation assumes there is no other Linux or Windows installation existing - the HDD WILL BE DELETED (and all its partitions)


To download the avi files - Right click and "Save as" as it might not play in the browser.

Last edited by utw-mephisto; 04-09-2008 at 03:51 PM.
 
Old 04-09-2008, 03:46 PM   #2
utw-mephisto
Member
 
Registered: Apr 2005
Posts: 93

Original Poster
Rep: Reputation: 16
01. Installation
When you boot up CentOS the first time you will see this splash screen

http://linux.mike666.co.uk/splash.JPG

In order to use the graphical installation - just hit enter.
If you wish to follow my video - type "linux text" and hit enter in order to start the text based installation.
  1. Skip Media Test
  2. Choose preferred language
  3. Confirm to delete all data
  4. Create a custom layout or simply use a default layout - up to you. I always use a custom layout
  5. Custom layout:
    Code:
    Mount Point : /
    File System Type : ext3
    Size : 1GB (1024)
    Code:
    Mount Point : <nothing>
    File System Type : SWAP
    Size : Twice system ram up to a maximum of 2 GB (2048)
    Code:
    Mount Point : /tmp
    File System : ext3
    Size : 2GB (2048)
    Code:
    Mount Point : /var
    File System : ext3
    Size : 4GB (4096)
    Code:
    Mount Point : /usr
    File System : ext3
    Size : 8 GB (8192)
    Code:
    Mount Point : /home
    File System : ext3
    Size : Remainder
  6. Accept all defaults in regards to boot sector / grub configuration
  7. Edit the network card and either set it to DHCP or give it an IP manually
  8. Set the timezone
  9. Set a root password
  10. Choose to customize the installation and remove everything apart of Development Tools
  11. Once done remove the disk and reboot
Movie Download
01 - Installation (08:34) - avi
01 - Installation (08:34) - rar

Last edited by utw-mephisto; 04-10-2008 at 02:54 AM.
 
Old 04-09-2008, 03:47 PM   #3
utw-mephisto
Member
 
Registered: Apr 2005
Posts: 93

Original Poster
Rep: Reputation: 16
02. Post Install

After the installation a small configuration tool pops up - which disappears again after a few momemts.

Since my server is behind a firewall I disable those security features. As I said before - that doesn't necessarily applies to your environment. But I do it that way so I show how
  1. Firewall Configuration :
    Code:
    Security Level : Disabled
    SELinux : Disabled
  2. System Services:
    Code:
    Disable Bluetooth
    Disable firstboot
    Disable iptables
    Disable ip6tables
  3. Add another user to work with
    Code:
    #adduser gomjaba
    #passwd gomjaba
    <enter secure password>
  4. Edit password file to give new user root access
    Code:
    # vi /etc/passwd
    Change group / permission to 0:0
  5. Change boot time out from 5 seconds to 0 seconds
    Code:
    # vi /boot/grub/grub.conf
    And change timeout = 5 to timeout = 0
  6. Tidy up the networking
    Code:
    # vi /etc/sysctl.conf
    and add at the bottom of the file
    net.ipv4.icmp_ignore_bogus_error_responses = 1
  7. Adding library paths to ld.so.conf
    Code:
    # vi /etc/ld.so.conf
    and add at the bottom of the file
    /usr/local/lib
  8. Configure SSH to allow endless SSH sessions
    Code:
    # vi /etc/ssh/sshd_config
    Uncomment "TCPKeepAlive yes"
    Uncomment "ClientAliveInterval 0" change the value of 0 to 60
    Uncomment "ClientAliveCountrMax 3" change the value of 3 to 6
Movie Download
02 - Post Install (03:11) - avi
02 - Post Install (03:11) - rar

Last edited by utw-mephisto; 04-09-2008 at 03:52 PM.
 
Old 04-09-2008, 03:47 PM   #4
utw-mephisto
Member
 
Registered: Apr 2005
Posts: 93

Original Poster
Rep: Reputation: 16
03. Updates

Bringing everything up to date
  1. Running yum update
    Code:
    # yum update
  2. Install some develpment libraries / tools
    Code:
    # yum install freetype-devel -y
    # yum install libpng-devel -y
    # yum install libjpeg-devel -y
    # yum install gd-devel -y
    # yum install libxml2-devel -y
    # yum install openssl-devel -y
    # yum install libxslt -y
    # yum install libxslt-devel y
Movie Download
03 - Updates (06:45) - avi
03 - Updates (06:45) - rar
 
Old 04-09-2008, 03:47 PM   #5
utw-mephisto
Member
 
Registered: Apr 2005
Posts: 93

Original Poster
Rep: Reputation: 16
04. MySQL Part 1 / Apache Cronolog

MySQL has two parts as I am going to install Perl as well. The installation of DBD / DBI requires a default installation of MySQL - this means a database called "test" has to be there and the root password for the MySQL server should not have a password. I also install the Apache log rotation (Cronolog) in this part. This is actually, as the name says, Apache related. It just happend to be one of my steps I usually do and the movie was done before I actually realised it and I didn't see a point in creating a movie of 10 seconds just for Cronolog.
  1. Uncompress fhe file, rename the folder to mysql and move to its final location
    Code:
    # tar zxvf mysql-5.0.51a-linux-i686-icc-glibc23.tar.gz
    # mv mysql-5.0.51a-linux-i686-icc-glibc23 mysql
    # mv mysql /usr/local
  2. Change into the mysql folder in its final location
    Code:
    # cd /usr/local/mysql
  3. Add the user and group that mysql will run under
    Code:
    # groupadd mysql
    # useradd g mysql mysql
  4. Run the mysql install script specifying the /home/mysql directory as the data directory
    Code:
    # scripts/mysql_install_db --datadir=/home/mysql
  5. Edit the mysql.server file to configure the application base folder and the data directory
    Code:
    # vi support-files/mysql.server
    specifying
    basedir=/usr/local/mysql
    datadir=/home/mysql
    There is an additional if statement where the datadir is specified that needs to read datadir=/home/mysql
    Code:
    if test -z "$datadir"
      then
        datadir=/home/mysql
      fi
  6. Edit the my-medium.cnf file remove replication support and alter the maximum connections value
    Code:
    # vi support-files/my-medium.cnf
    At the tail of the [mysqld] section add the line:
    max_connections=2000
    Find the line: log-bin=mysql-bin and comment it out.
  7. Copy and rename the two files to their final places
    Code:
    # cp support-files/mysql.server /etc/init.d
    # cp support-files/my-medium.cnf /etc/my.cnf
  8. Set mysql to autostart on machine boot and create symbolic links to key mysql applications
    Code:
    # chkconfig mysql.server on 345
    # ln s /usr/local/mysql/bin/mysql /usr/bin/mysql
    # ln s /usr/local/mysql/bin/mysqladmin /usr/bin/mysqladmin
    # ln s /usr/local/mysql/bin/mysqldump /usr/bin/mysqldump
    # ln s /usr/local/mysql/bin/mysqlimport /usr/bin/mysqlimport
    # ln s /usr/local/mysql/bin/mysqlhotcopy /usr/bin/mysqlhotcopy
    # mkdir -p /var/lib/mysql/
    # ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
  9. Change the owner and group ownership of the /home/mysql folder to mysql and mysql, change the group only of the /usr/local/mysql folder to mysql. Give the mysql.server file execute permissions.
    Code:
    # chown R mysql:mysql /home/mysql
    # chgrp R mysql /usr/local/mysql
    # chmod 755 /etc/init.d/mysql.server
  10. Start MySQL
    Code:
    # service mysql.server start
  11. Installation of MySQL Development Libraries / Tools
    Code:
    # yum install mysql-devel -y
Movie Download
04 - MySQL Part 1 (06:00) - avi
04 - MySQL Part 1 (06:00) - rar
 
Old 04-09-2008, 03:47 PM   #6
utw-mephisto
Member
 
Registered: Apr 2005
Posts: 93

Original Poster
Rep: Reputation: 16
05. Perl
  1. Installing Perl parts using CPAN
    Code:
    # perl MCPAN e shell
    (CHOOSE NO IN ORDER TO AVOID MANUAL CONFIGURATION)
    # install Bundle::CPAN
    # install Bundle::LWP	
    # install Bundle::libnet
    # install DBI	
    # install DBD::mysql
    # quit
Movie Download
05 - Perl (08:31) - avi
05 - Perl (08:31) - rar
 
Old 04-09-2008, 03:48 PM   #7
utw-mephisto
Member
 
Registered: Apr 2005
Posts: 93

Original Poster
Rep: Reputation: 16
06. MySQL Part 2

By default MySQL does not allow remote connections. Since I do have a firewall and want to use a 3rd party software to administrate it, this enables remote connections. But this is a security risk and should not be done if you don't have a firewall or if you are not sure.
  1. Set the current password for mysql to somepassword overwriting the current, blank, password
    Code:
    # mysqladmin -u root -p password somepassword
    <press enter since an empty password was the previous password>
  2. Log in to mysql and run the following commands to secure mysql:
    Code:
    # mysql –u root -p
    <enter the new password, ie somepassword
    # drop database test;
    # use mysql
    # delete from user where user=’’; <THESE ARE TWO SINGLE QUOTES>
    # delete from user where host != ‘localhost’ ;
    # update user set host=’%’ ;
    # update user set password=password('somepassword') ;
    # exit
    Restart the mysql service to commit the changes
    # service mysql.server restart
Movie Download
06 - MySQL Part 2 (01:53) - avi
06 - MySQL Part 2 (01:53) - rar

Last edited by utw-mephisto; 04-09-2008 at 03:53 PM.
 
Old 04-09-2008, 03:48 PM   #8
utw-mephisto
Member
 
Registered: Apr 2005
Posts: 93

Original Poster
Rep: Reputation: 16
07. MySQL Part 3

This is as preparation for the later test. At the end of this tutorial we are creating a PHP Webpage which queries the database and displays the result. This way we test the whole setup - webserver, php and mysql.
Basically to do so you have to
  1. Create a database
  2. Create a user and give it permission for the newly created database
  3. Create a varchar table inside of that database
  4. Create a value inside of that table.
The attached movie shows the steps using Navicat which is imho, one of the best 3rd party tools out there. It is not free - but well worth the money if you use more than just one server and / or database.
You can obviously do the same through the commandline interface (which I am not perfect in) or other software. The other alternative is PHPMyadmin - which is also a good alternative if you don't allow remote connections as this installs directly on the webserver and connects to the database through localhost. As I said - I am not 100% familiar with the commandline interface and I don't like phpmyadmin

Movie Download
07 - MySQL Part 3 (02:04) - avi
07 - MySQL Part 3 (02:04) - rar
 
Old 04-09-2008, 03:48 PM   #9
utw-mephisto
Member
 
Registered: Apr 2005
Posts: 93

Original Poster
Rep: Reputation: 16
08. FTP Software Install (VSFTPD)

There are quite a few different FTP software packages out there but I simply prefer vsftpd - it just works.
  1. Installation
    Code:
    # yum install vsftpd -y
  2. Create a folder for the ftp log files
    Code:
    # mkdir /home/ftp_logs
  3. Replace the generic configuration
    Code:
    # rm /etc/vsftpd/vsftpd.conf 
    # vi /etc/vsftpd/vsftpd.conf 
    anonymous_enable=NO
    local_enable=YES
    write_enable=YES
    local_umask=022
    dirmessage_enable=YES
    connect_from_port_20=YES
    xferlog_enable=YES
    xferlog_file=/home/ftp_logs/vsftpd.log
    xferlog_std_format=YES
    idle_session_timeout=600
    data_connection_timeout=120
    async_abor_enable=YES
    ascii_upload_enable=YES
    ascii_download_enable=YES
    ftpd_banner=FTP service.
    pam_service_name=vsftpd
    userlist_enable=YES
    listen=YES
    tcp_wrappers=YES
    chroot_local_user=YES
    max_clients=200
    max_per_ip=4
    hide_ids=YES
    use_localtime=YES
    force_dot_files=YES
  4. Set the ftp service to autostart
    Code:
    # chkconfig vsftpd on 345
  5. Disable XInetd which is an intrusion protection service <DO THIS ONLY IF YOU KNOW WHAT IT DOES OTHERWISE JUST LEAVE IT>
    Code:
    # cd /etc
    # find . –name '*inetd*' -exec rm {} \;
  6. Disable vsftpd log rotation
    Code:
    # rm /etc/logrotate.d/vsftpd.log -f

Movie Download
08 - FTP Server install (01:25) - avi
08 - FTP Server install (01:25) - rar
 
Old 04-09-2008, 03:48 PM   #10
utw-mephisto
Member
 
Registered: Apr 2005
Posts: 93

Original Poster
Rep: Reputation: 16
09. Libraries and modules
  1. Adding library paths to ld.so.conf
    Code:
    # vi /etc/ld.so.conf
    add the following at the bottom of the file
    /usr/local/lib
  2. Reload libraries
    Code:
    # ldconfig
  3. Installation of Libmcrypt
    Code:
    # tar zxvf libmcrypt-2.5.8.tar.gz
    # cd libmcrypt-2.5.8
    # ./configure
    # make
    # make install
    # ldconfig
    # cd libmcrypt-2.5.8/libltdl
    # ./configure --enable-ltdl-install
    # make
    # make install
    # ldconfig
  4. Install Mcrypt
    Code:
    # tar zxvf mcrypt-2.6.7.tar.gz
    # cd mcrypt-2.6.7
    # ./configure
    # make
    # make install
    # ldconfig
  5. Install Mhash <Forgot to put that in the movie but is also straight forward>
    Code:
    # tar zxvf mcrypt-2.6.7.tar.gz
    # cd mcrypt-2.6.7
    # ./configure
    # make 
    # make install
  6. Install GD (Graphics library)
    Code:
    # tar zxvf gd-2.0.33.tar.gz
    # cd gd-2.0.33
    # ./configure
    # make
    # make install
Movie Download
09 - Libraries and modules (03:25) - avi
09 - Libraries and modules (03:25) - rar
 
Old 04-09-2008, 03:48 PM   #11
utw-mephisto
Member
 
Registered: Apr 2005
Posts: 93

Original Poster
Rep: Reputation: 16
10. Apache Part 1
  1. Uncompress the file into a folder and then change into that folder
    Code:
    # tar zxvf httpd-2.2.8.tar.gz
    # cd httpd-2.2.8
    # ./configure --enable-ssl --enable-module=so --enable-rewrite 
    # make
    # make install
Thats apache for now, it interleaves with php so we you need to install that next before finishing Apache.

Movie Download
10 - Apache Part 1 (07:12) - avi
10 - Apache Part 1 (07:12) - rar
 
Old 04-09-2008, 03:49 PM   #12
utw-mephisto
Member
 
Registered: Apr 2005
Posts: 93

Original Poster
Rep: Reputation: 16
11. PHP Installation
  1. Uncompress the file into a folder and then change into that folder
    Code:
    # tar zxvf php-5.2.5.tar.gz
    # cd php-5.2.5
  2. To build php with support for mysql, mysqli, xml, zlib, gd, mcrypt, freetype and openssl, run the following configure line
    Code:
    # ./configure --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir=/usr/lib --with-zlib --with-gd=/usr/local --with-mcrypt --with-freetype-dir=/usr/ --with-openssl --enable-soap --with-xsl
    # make
    # make install
    There are two way to run PHP : As modul or as CGI. Long story short : If you want performance - run it as modul - if you want security - run it as CGI.

    I don't care about performance for this example (can be changed at any time anyway) so I run it as CGI
  3. Run PHP as CGI
    Code:
    # rm -f /usr/local/bin/php
    # mkdir /usr/local/php/
    # cp sapi/cgi/php-cgi /usr/local/php/php
  4. Now we need to customise the php initialisation file for the system and move it to the right place
    Code:
    # cp php.ini-dist /usr/local/lib/php.ini
    # vi /usr/local/lib/php.ini
    We need to configure php to correctly find the smtp system (sendmail) so find the line for the sendmail path and set the path to
    /usr/sbin/sendmail –t –i
    Then we need to add a little compatibility for dodgy php code so find the line which says register_globals = Off and change it:
    register_globals = On

Thats php configuration done now back to apache.

Movie Download
11 - PHP (03:09) - avi
11 - PHP (03:09) - rar
 
Old 04-09-2008, 03:49 PM   #13
utw-mephisto
Member
 
Registered: Apr 2005
Posts: 93

Original Poster
Rep: Reputation: 16
12. Apache Part 2
  1. Creating of the usergroup we use to run Apache
    Code:
    # groupadd www
  2. All of Apache’s configuration is done in a file called httpd.conf which is in /usr/local/apache2/conf/, so we need to edit that file
    Code:
    # vi /usr/local/apache2/conf/httpd.conf
    Change the user and group that apache runs as
    user nobody
    group www
    
    Next we need to add the log format to show apache that it should output its weblogs the way our stats servers can read them, so with the other LogFormat lines we add in
    
    LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" common
    
    The next step us to add an alias for php so that php calls are routed to the correct destination. Find the line
    
    ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"
    
    Comment the line out with a # as it is unneeded and beneath that add
    
    ScriptAlias /php-bin/ "/usr/local/php/"
    
    Next we have to make apache recognise when php is being called
    Find the line
    AddType application/x-gzip .gz .tgz
    
    And underneath that, add
    
    AddType application/x-httpd-php .php
    Action  application/x-httpd-php "/php-bin/php"
    
    Which tells apache that if it sees a file with the extension .php then the file is of type x-httpd-php and routes it to /php-bin/php which with the previous Script Alias directs it to php which is in /usr/local/php
    
    As a change to the workings of apache they changed the directory map for / from
    
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    
    to:
    
    <Directory />
        Options FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
    </Directory>
    
    In order to allow access to the site root, comment out the last two lines
    
    Until ssl support is needed, we comment out the lines (using a #) 
    
    #<IfModule ssl_module>
    #SSLRandomSeed startup builtin
    #SSLRandomSeed connect builtin
    #</IfModule>
    
    Finally we need to configure virtual host configuration, a virtual host is for all intents and purposes a site. We split these out to individual files in a folder but we need to tell apache what ip address we are doing this with and where to find the configuration files. So at the end of the file we add
    
    NameVirtualHost <Server IP address>:80
    Include /usr/local/apache2/conf/v-hosts
  3. Now create the folder mentioned above, one for ssl-hosts (ssl based sites need a virtual host folder for their ssl based site and there non ssl based site) One for their ssl key files and one for their ssl certificates
    Code:
    # cd /usr/local/apache2/conf
    # mkdir ssl-hosts
    # mkdir v-hosts
    # mkdir ssl.crt
    # mkdir ssl.key
  4. With this done we have to create the file to start apache at runtime
    Code:
    # cd /etc/init.d
    # vi httpd
    Which should contain the following code (startup script)

    Code:
    #!/bin/bash
    #
    # httpd        Startup script for the Apache HTTP Server
    #
    # chkconfig: 345 55 25
    # description: Apache is a World Wide Web server.  It is used to serve \
    #              HTML files and CGI.
    # processname: httpd
    # config: /usr/local/apache2/conf/httpd.conf
    # pidfile: /usr/local/apache2/logs/httpd.pid
    
    # Source function library.
    . /etc/rc.d/init.d/functions
    
    if [ -f /etc/sysconfig/httpd ]; then
            . /etc/sysconfig/httpd
    fi
    
    # Start httpd in the C locale by default.
    HTTPD_LANG=${HTTPD_LANG-"C"}
    
    # This will prevent initlog from swallowing up a pass-phrase prompt if
    # mod_ssl needs a pass-phrase from the user.
    INITLOG_ARGS=""
    
    # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
    # with the thread-based "worker" MPM; BE WARNED that some modules may not
    # work correctly with a thread-based MPM; notably PHP will refuse to start.
    
    # Path to the apachectl script, server binary, and short-form for messages.
    apachectl=/usr/local/apache2/bin/apachectl
    httpd=${HTTPD-/usr/local/apache2/bin/httpd}
    OPTIONS=-DSSL
    prog=httpd
    pidfile=${PIDFILE-/var/run/httpd.pid}
    lockfile=${LOCKFILE-/var/lock/subsys/httpd}
    RETVAL=0
    
    # The semantics of these two functions differ from the way apachectl does
    # things -- attempting to start while running is a failure, and shutdown
    # when not running is also a failure.  So we just do it the way init scripts
    # are expected to behave here.
    start() {
            echo -n $"Starting $prog: "
            LANG=$HTTPD_LANG daemon $httpd $OPTIONS
            RETVAL=$?
            echo
            [ $RETVAL = 0 ] && touch ${lockfile}
            return $RETVAL
    }
    stop() {
            echo -n $"Stopping $prog: "
            killproc $httpd
            RETVAL=$?
            echo
            [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
    }
    reload() {
        echo -n $"Reloading $prog: "
        if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
            RETVAL=$?
            echo $"not reloading due to configuration syntax error"
            failure $"not reloading $httpd due to configuration syntax error"
        else
            killproc $httpd -HUP
            RETVAL=$?
        fi
        echo
    }
    
    # See how we were called.
    case "$1" in
      start)
            start
            ;;
      stop)
            stop
            ;;
      status)
            status $httpd
            RETVAL=$?
            ;;
      restart)
            stop
            start
            ;;
      condrestart)
            if [ -f ${pidfile} ] ; then
                    stop
                    start
            fi
            ;;
      reload)
            reload
            ;;
      graceful|help|configtest|fullstatus)
            $apachectl $@
            RETVAL=$?
            ;;
      *)
            echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
            exit 1
    esac
    
    exit $RETVAL
  5. Then we need to make that file executable and set apache to start at runtime
    Code:
    # chmod 755 httpd
    # chkconfig httpd on 345
Movie Download
12 - Apache Part 2 (04:00) - avi
12 - Apache Part 2 (04:00) - rar
 
Old 04-09-2008, 03:49 PM   #14
utw-mephisto
Member
 
Registered: Apr 2005
Posts: 93

Original Poster
Rep: Reputation: 16
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.
  1. 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>
  2. Create a user the website should run under
    Code:
    # adduser centos-test
  3. Create necessary directories
    Code:
    # mkdir /home/centos-test/htdocs
    # mkdir /home/centos-test/cgi-bin
    # mkdir /home/centos-test/logs
  4. Set the approriate permissions
    Code:
    # chmod -R 2750 /home/centos-test
    # chown -R centos-test:www /home/centos-test
  5. Give user a password
    Code:
    # passwd centos-test
    <enter new password here>
  6. 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.
  1. 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.

  2. 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/
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Remote setup of LAMP server on CentOS 5 satimis Linux - Server 19 01-31-2008 11:42 PM
LXer: CentOS 5.1 Server Setup: LAMP, Email, DNS, FTP, ISPConfig LXer Syndicated Linux News 0 12-06-2007 03:21 PM
LAMP server - which flavour Linux: Fed or CentOS? uncle-c Linux - General 2 06-20-2007 04:10 PM
LXer: Cacti On CentOS 4.4 Including The Plug-In Architecture LXer Syndicated Linux News 0 04-25-2007 07:47 PM
LXer: Building A Low-Cost LAMP Server For Your Webhosting Business With CentOS 4.3 LXer Syndicated Linux News 0 05-03-2006 02:54 PM


All times are GMT -5. The time now is 04:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration