Saturday, August 31, 2013

// // Leave a Comment

How to Set Up Apache Virtual Hosts on CentOS 6

About Virtual Hosts


Virtual Hosts are used to run more than one domain off of a single IP address. This is especially useful to people who need to run several sites off of one virtual private server. The sites display different information to the visitors, depending on with which the users accessed the site.There is no limit to the number of virtual hosts that can be added to a VPS.

Set Up

The steps in this tutorial require the user to have root privileges.Furthermore, if I reference the user in a step, I’ll use the name www. You can implement whatever username suits you. 

Additionally, you need to have apache already installed and running on your virtual server 
If this is not the case, you can download it with this command:
sudo yum install httpd

Step One— Create a New Directory


The first step in creating a virtual host is to a create a directory where we will keep the new website’s information. 

This location will be your Document Root in the Apache virtual configuration file later on. By adding a -p to the line of code, the command automatically generates all the parents for the new directory.
sudo mkdir -p /var/www/example.com/public_html

You will need to designate an actual DNS approved domain, or an IP address, to test that a virtual host is working. In this tutorial we will use example.com as a placeholder for a correct domain name. 

However, should you want to use an unapproved domain name to test the process you will find information on how to make it work on your local computer in Step Six. 

Step Two—Grant Permissions


We need to grant ownership of the directory to the user, instead of just keeping it on the root system.
 sudo chown -R www:www /var/www/example.com/public_html 

Additionally, it is important to make sure that everyone will be able to read our new files.
 sudo chmod 755 /var/www

Now you are all done with permissions.

Step Three— Create the Page


We need to create a new file called index.html within our configurations directory.
sudo vi /var/www/example.com/public_html/index.html

We can add some text to the file so we will have something to look at when the IP redirects to the virtual host.


  
    www.example.com
  
  
    

Success: You Have Set Up a Virtual Host


Save and Exit

Step Four—Turn on Virtual Hosts


The next step is to enter into the apache configuration file itself.
sudo vi /etc/httpd/conf/httpd.conf

There are a few lines to look for.
Make sure that your text matches what you see below.
#Listen 12.34.56.78:80
Listen 80

Scroll down to the very bottom of the document to the section called Virtual Hosts.
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.
#    

#    
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for requests without a known
# server name.
# 

     ServerAdmin webmaster@example.com
     DocumentRoot /var/www/example.com/public_html
     ServerName www.example.com
     ServerAlias example.com
     ErrorLog /var/www/example.com/error.log
     CustomLog /var/www/example.com/requests.log


The most important lines to focus on are the lines that say NameVirtualHost, Virtual Host, Document Root, and Server Name. Let’s take these one at a time. 

-Uncomment (remove the number sign) NameVirtualHost without making any changes. The star means that any IP address going through port 80 will be a virtual host. As your system probably only has one IP address this is not an issue—however, if you prefer, you can replace the star with your IP address.

-You can leave the rest of the number marks in place until you reach the line . Uncomment everything from there through .

-Leave as is—its details must match with those in the NameVirtual Host section. If you replaced the star with your IP address in that section, be sure to do the same here. 

-Document Root is key! For this section, write in the extension of the new directory created in Step One. If the document root is incorrect or absent you will not be able to set up the virtual host.

-Server Name is another important piece of information, containing the virtual host’s domain name (eg. www.example.com). Make sure that you spell the domain out in full; we will put in any alternate possibilities in the next line.

-ServerAlias is a new line in the config file that is not there by default. Adding it will allow you to list a few variants of the domain name, for example without the www in the front. 



The rest of the lines in this section are not required to set up a virtual host. However, it is still helpful to know what they do. 

-Server admin asks for the webmaster’s email. 

-The Error Logs and Custom Logs keep track of any issues with the server. The error log covers issues that arise while maintaining the server, and the custom log tracks server requests. You can set up a custom location for these processes.

-Make sure that is uncommented; then save and exit.

Step Five—Restart Apache


We’ve made a lot of the changes to the configuration. However, they will not take effect until Apache is restarted. 
First stop all apache processes:
sudo apachectl -k stop

Then start up apache once again.
sudo /etc/init.d/httpd start

You may see the following error:
Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName

The message is just a warning, and you will be able to access your virtual host without any further issues.

Optional Step Six—Setting Up the Local Hosts


If you have pointed your domain name to your virtual private server’s IP address you can skip this step—you do not need to set up local hosts. Your virtual hosts should work. However, if want to try out your new virtual hosts without having to connect to an actual domain name, you can set up local hosts on your computer alone. 

For this step, make sure you are on the computer itself, not your droplet. 

To proceed with this step you need to know your computer’s administrative password, otherwise you will be required to use an actual domain name to test the virtual hosts.

If you are on a Mac or Linux, access the root user (su) on the computer and open up your hosts file:
nano /etc/hosts 

If you are on a Windows Computer, you can find the directions to alter the host file on the Microsoft site

You can add the local hosts details to this file, as seen in the example below. As long as that line is there, directing your browser toward, say, example.com will give you all the virtual host details for the corresponding IP address.
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1       localhost

#Virtual Hosts 
12.34.56.789    www.example.com 

However, it may be a good idea to delete these made up addresses out of the local hosts folder when you are done to avoid any future confusion. 

Step Seven—RESULTS: See Your Virtual Host in Action


Once you have finished setting up your virtual host, you can see how it looks online. Type your ip address into the browser (ie. http://12.34.56.789) 

It should look somewhat similar to my handy screenshot

Good Job!

Adding More Virtual Hosts


To create additional virtual hosts, you can just repeat the process above, being careful to set up a new document root with the appropriate new domain name each time. Then just copy and paste the new Virtual Host information into the Apache Config file, as shown below

     ServerAdmin webmaster@example.com
     DocumentRoot /var/www/example.com/public_html
     ServerName www.example.com
     ServerAlias example.com
     ErrorLog /etc/var/www/example.com/error.log
     CustomLog /var/www/example.com/requests.log


     ServerAdmin webmaster@example.org
     DocumentRoot /var/www/example.org/public_html
     ServerName www.example.org
     ServerAlias example.org
     ErrorLog /var/www/example.org/error.log
     CustomLog /var/www/example.orgrequests.log

Read More
// // Leave a Comment

How to Install Linux, Apache, MySQL, PHP (LAMP) stack on CentOS 6

About LAMP


LAMP stack is a group of open source software used to get web servers up and running. The acronym stands for Linux, Apache, MySQL, and PHP. Since the server is already running CentOS, the linux part is taken care of. Here is how to install the rest. 

Set Up

The steps in this tutorial require the user on the virtual private server to have root privileges. 

Step One—Install Apache


Apache is a free open source software which runs over 50% of the world’s web servers. 

To install apache, open terminal and type in this command:
sudo yum install httpd

Once it installs, you can start apache running on your VPS:
sudo service httpd start

That’s it. To check if Apache is installed, direct your browser to your server’s IP address (eg. http://12.34.56.789). The page should display the words “It works!" like this.

How to find your Server’s IP address


You can run the following command to reveal your server’s IP address.
ifconfig eth0 | grep inet | awk '{ print $2 }'

Step Two—Install MySQL


MySQL is a powerful database management system used for organizing and retrieving data on a virtual server 

To install MySQL, open terminal and type in these commands:
sudo yum install mysql-server
sudo service mysqld start

During the installation, MySQL will ask you for your permission twice. After you say Yes to both, MySQL will install. 

Once it is done installing, you can set a root MySQL password:
sudo /usr/bin/mysql_secure_installation

The prompt will ask you for your current root password. 

Since you just installed MySQL, you most likely won’t have one, so leave it blank by pressing enter.
Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Then the prompt will ask you if you want to set a root password. Go ahead and choose Y and follow the instructions. 

CentOS automates the process of setting up MySQL, asking you a series of yes or no questions. 

It’s easiest just to say Yes to all the options. At the end, MySQL will reload and implement the new changes.
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y                                            
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Step Three—Install PHP


PHP is an open source web scripting language that is widely used to build dynamic webpages.

To install PHP on your virtual private server, open terminal and type in this command:
sudo yum install php php-mysql

Once you answer yes to the PHP prompt, PHP will be installed. 

PHP Modules


PHP also has a variety of useful libraries and modules that you can add onto your server. You can see the libraries that are available by typing:
yum search php-

Terminal then will display the list of possible modules. The beginning looks like this:
php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
php-cli.x86_64 : Command-line interface for PHP
php-common.x86_64 : Common files for PHP
php-dba.x86_64 : A database abstraction layer module for PHP applications
php-devel.x86_64 : Files needed for building PHP extensions
php-embedded.x86_64 : PHP library for embedding in applications
php-enchant.x86_64 : Human Language and Character Encoding Support
php-gd.x86_64 : A module for PHP applications for using the gd graphics library
php-imap.x86_64 : A module for PHP applications that use IMAP
To see more details about what each module does, type the following command into terminal, replacing the name of the module with whatever library you want to learn about.
yum info name of the module

Once you decide to install the module, type:
sudo yum install name of the module

You can install multiple libraries at once by separating the name of each module with a space.

Congratulations! You now have LAMP stack on your droplet!

We should also set the processes to run automatically when the server boots (php will run automatically once Apache starts):
sudo chkconfig httpd on
sudo chkconfig mysqld on

Step Four—RESULTS: See PHP on your Server


Although LAMP is installed on your virtual server, we can still take a look and see the components online by creating a quick php info page

To set this up, first create a new file:
sudo nano /var/www/html/info.php

Add in the following line:


Then Save and Exit. 

Restart apache so that all of the changes take effect on your virtual server:
sudo service httpd restart

Finish up by visiting your php info page (make sure you replace the example ip address with your correct one): http://12.34.56.789/info.php
Read More
// // Leave a Comment

[CPanel] How to install ffmpeg mplayer and mencoder on CentOS6 (FFMpeg 0.7.11)

Hello Guys,

Installation of FFMPEG is treated as the toughest installations as it has many dependencies. Check with the below steps for easy installation.

1. Enable 9xhost and EPEL yum repositories

    The CentOS 6 RPM packages of ffmpeg, mplayer and MP4Box packages are available on 9xhost.net. These RPM packages are copied from ATrpms and RPM Fusion YUM repositories for a simplified installation.

    Some packages on 9xhost YUM repo depend on EPEL repo. To enable EPEL repo, install the epel-release RPM package

    rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm

1.1 To enable 9xhost YUM repository, create the file /etc/yum.repos.d/9xhost.repo

    nano /etc/yum.repos.d/9xhost.repo

    and add following repository configuration:

    [9xhost]
    name=9xhost Packages CentOS 6 - $basearch
    baseurl=http://dl.9xhost.info/yumrepo/centos/6/$basearch/
    enabled=1
    gpgcheck=0

2. Install ffmpeg mplayer and mencoder

    for x86 (32bit system)

    yum install ffmpeg mplayer

    for x86_64 (64bit system)

    yum install ffmpeg mplayer --exclude "*.i386"

    Note: there is no separate package for mencoder. It is also provided by mplayer package.

    This will also install various dependency packages like libtheora, libvorbis, libogg, lame, opencore-amr, x264, xvidcore etc.

3. Install flvtool2

    cPanel has its own ruby installer script. So install ruby using following cPanel script:

    /scripts/installruby

    Flvtool2 is available as a Ruby Gems package. Use following gem command to install flvtool2:

    gem install flvtool2

4. Install MP4Box2

    MP4Box is provided by gpac package. Install gpac and its library packages:

    for x86 (32bit system)

    yum install gpac gpac-libs

    for x86_64 (64bit system)

    yum install gpac gpac-libs --exclude "*.i386"

5. Install ffmpeg-php

    Ffmpeg-php requires ffmpeg development package. Install it using yum:
    for x86 (32bit system)

    yum install ffmpeg-devel

    for x86_64 (64bit system)

    yum install ffmpeg-devel --exclude "*.i386"

    Now download the latest ffmpeg-php package:

    wget http://downloads.sourceforge.net/ffmpeg-php/ffmpeg-php-0.6.0.tbz2

    Untar this package, build and install it with following commands:

    tar xjf ffmpeg-php-0.6.0.tbz2
    cd ffmpeg-php-0.6.0
    sed -i 's/PIX_FMT_RGBA32/PIX_FMT_RGB32/g' ffmpeg_frame.c
    phpize
    ./configure
    make
    make install

    The make install command will show PHP extensions path where ffmpeg PHP extension is installed:

    root@server [~/ffmpeg-php-0.6.0]# make install
    Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20060613/

    Now edit php.ini file

    nano /usr/local/lib/php.ini

    and make sure that value of extension_dir is set to PHP extension directory as given by above make install command:


    extension_dir = "/usr/local/lib/php/extensions/no-debug-non-zts-20060613"

    Add following line just below extension_dir and this will enable ffmpeg PHP extension:

    extension="ffmpeg.so"

    Restart Apache to make this change effective:

    /scripts/restartsrv_httpd

    You can verify the status of ffmpeg extension on a PHP info web page or from command line as given below:


    root@server [~]# php -i | grep ffmpeg
    ffmpeg
    ffmpeg-php version => 0.6.0-svn
    ffmpeg-php built on => Jun 2 2012 20:48:04
    ffmpeg-php gd support => enabled
    ffmpeg libavcodec version => Lavc52.123.0
    ffmpeg libavformat version => Lavf52.111.0
    ffmpeg swscaler version => SwS0.14.1
    ffmpeg.allow_persistent => 0 => 0
    ffmpeg.show_warnings => 0 => 0
    OLDPWD => /root/ffmpeg-php-0.6.0
    _SERVER["OLDPWD"] => /root/ffmpeg-php-0.6.0
    _ENV["OLDPWD"] => /root/ffmpeg-php-0.6.0

6. Installation paths

    Following are the file system paths of tools that we installed:

    ffmpeg: /usr/bin/ffmpeg
    mplayer: /usr/bin/mplayer
    mencoder: /usr/bin/mencoder
    flvtool2: /usr/bin/flvtool2
    MP4Box: /usr/bin/MP4Box
Read More