Saturday, August 31, 2013

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

Friday, August 9, 2013

// // Leave a Comment

Install Memcache on CentOS 6 cPanel

Here is how to install Memcache for PHP on a CentOS 6 cPanel / WHM box. Some of the guides suggest that you need libevent (well, you do need libevent), though when I tried it, I already had it installed. But if you need it, yum will sort you out.
yum install libevent
Next, install memcache itself. Note that the package is called memcached.
yum install memcached
Of course, just installing it doesn’t mean that the daemon is running. So don’t forget to start it too!
/etc/init.d/memcached start
Finally, we need to add the PHP extension. Beware that the PECL installer on WHM won’t work! So you need to compile it manually from source. That isn’t too difficult though.
wget http://pecl.php.net/get/memcache
tar zxvf memcache
cd memcache-3.0.6
phpize
./configure
make
make install
And add the extension to your php.ini.
extension=memcache.so
Now restart Apache and a memcache section should appear in your PHP info.
Read More

Thursday, August 8, 2013

// // Leave a Comment

Linux: HowTo Copy a Folder [ Command Line Option ]

I'm a new Linux user. How do I copy a directory or folder under Linux operating system using command line options and bash shell?

You can use various command to copy a folder under Linux operating systems.

cp Command

cp is a Linux command for copying files and directories. The syntax is as follows:
 
cp source destination
cp dir1 dir2
cp -option  source destination
cp -option1 -option2  source destination
 
In this example copy /home/vivek/letters folder and all its files to /usb/backup directory:
 
cp -avr /home/vivek/letters /usb/backup
 
Where,
  • -a : Preserve the specified attributes such as directory an file mode, ownership, timestamps, if possible additional attributes: context, links, xattr, all.
  • -v : Explain what is being done.
  • -r : Copy directories recursively.

Example

Copy a folder called /tmp/conf to /tmp/backup:
$ cp -avr /tmp/conf/ /tmp/backup
Sample outputs:
HowTO: Copy Folder Linux Terminal Command
Fig.01: cp command in action

rsync Command

You can also use rsync command which is a fast and extraordinarily versatile file copying tool. It can make copies across the network. The syntax is as follows:
 
rsync -av /path/to/source /path/to/destination
rsync -av /path/to/source/ /path/to/destination/source
 
To backup my home directory, which consists of large files and mail folders to /media/backup, enter:
$ rsync -avz /home/vivek /media/backup
I can copy a folder to remote machine called server1.cyberciti.biz:
$ rsync -avz /home/vivek/ server1.cyberciti.biz:/home/backups/vivek
Where,
  • -a : Archive mode i.e. copy a folder with all its permission and other information including recursive copy.
  • -v : Verbose mode.
  • -z : With this option, rsync compresses the file data as it is sent to the destination machine, which reduces the amount of data being transmitted — something that is useful over a slow connection.
You can show progress during transfer using --progress or -P option:
$ rsync -av --progress /path/to/source/ /path/to/dest
Sample outputs:
Copy Folder Linux Commands [ rsync ]
Fig.02: rsync command in action
Read More
// // Leave a Comment

[CPanel] Auto fix for file permissions and ownership

suPHP and FastCGI require files and folders to have a specific set of permissions/ownership from other handlers. Without these permissions set you will see a lot of errors such as: “403 Forbidden”, “500 Internal Server Error”, or simply generic errors that commonly have the word ‘permission’ in them.
It can be very time consuming to track down and check file permissions across a whole server. Luckily, fixing this on a cPanel box can be scripted. This gives us a quick and very easy script you can wget to any cPanel server. Simply run the ‘fixperms’ script, specifying the user (or all users), sit back and watch the errors just disappear. I use this script daily in my administrative work and it never fails! It is simply a good generic fix if you cannot find your permission problem, or if you have just switched your handler and need a quick way to change every user account on the server.
Credit does not go to me though. A good buddy of mine, Colin R., wrote this for ServInt. Thanks Colin for making lives easier!
***WARNING!!! The following scripts are intended for suPHP or FastCGI. If you are not running either of these two handlers, be aware of how the script works and the changes it makes. The code is posted at the end of this article; please take a moment to review it. For example, when running DSO, some files/folders may need to be owned by ‘nobody’ in order to function properly (such as in certain WordPress functions or PHP based file uploads). Running this fixperms will set everything to USER:USER. Under DSO, this is potentially not a problem for most sites, except a few core functions may not work. You can always change specific files later if any errors pop up.
Furthermore, it is highly recommended that you run a full backup of your server before running fixperms or any other script that makes changes to multiple files.
This ‘fixperms’ script is intended for cPanel servers only. It is dependent on cPanel’s internal scripts and file structure. If you’re on anything else (such as Plesk), it will simply fail to run. It won’t be able to do anything.
I know that criteria sounds very specific, but those two conditions cover a large number of the reseller/multi-user hosting servers out there. And that’s really the crowd that would benefit most from an automated script such as this.
That all being said, if you are running suPHP or FastCGI, press on; for this script will work flawlessly for you and potentially save you a TON of time & hassle.

Fixperms – for one single user

To use the fixperms script, simply log into your server as root, wget the file from our server, then run it. Type in the cPanel username and it will run only for that particular account.
It does not matter which directory you are in when you run fixperms. You can be in the user’s home directory, the server root, etc. The script will not affect anything outside of the particular user’s folder.

Fixperms – for all of the users

If you would like fix the permissions for every user on your cPanel server, simply use the ‘-all’ option:

Verbosity of Fixperms

By default, the script runs in a ‘quiet’ mode with minimal display. However, if you’re like me, you may want to see everything that is happening. You can turn on verbosity and have the script print to the screen everything that is being changed. I find this extremely useful when fixing large accounts that have many files. You can watch the changes as a sort of ‘progress bar’ of completion. The ‘-v’ option can be used per account or with all accounts.
For one single account:
For all accounts:
Read More