Install YouTube-DL – A Command Line Video Download Tool for Linux

youtube-dl is a Python based small command-line tool that allows to download videos fromYouTube.comDailymotionGoogle VideoPhotobucketFacebookYahooMetacafe,Depositfiles and few more similar sites. It written in pygtk and requires Python interpreter to run this program, it’s not platform restricted. It should run on any UnixWindows or in Mac OS Xbased systems.

Recently, youtube-dl added video download support for 17 new websites:,,,

youtube-dl also allows to choose specific avialable video quality format to download or let the program itself automatically download higher quality video from the site. It also has supports for user specific playlist downloads, options to add custom or original title to the downloadedvideo file. proxy support and many more.


First, you need to download the file using Wget and then install it using RPM on your system to enable the EPEL repository. Use below links based on your Linux OS versions. (Make sure you must be root user).

RHEL/CentOS 6 32-64 Bit

## RHEL/CentOS 6 32-Bit ##
# wget
# rpm -ivh epel-release-6-8.noarch.rpm

## RHEL/CentOS 6 64-Bit ##
# wget
# rpm -ivh epel-release-6-8.noarch.rpm

RHEL/CentOS 5 32-64 Bit

## RHEL/CentOS 5 32-Bit ##
# wget
# rpm -ivh epel-release-5-4.noarch.rpm

## RHEL/CentOS 5 64-Bit ##
# wget
# rpm -ivh epel-release-5-4.noarch.rpm

RHEL/CentOS 4 32-64 Bit

## RHEL/CentOS 4 32-Bit ##
# wget
# rpm -ivh epel-release-4-10.noarch.rpm

## RHEL/CentOS 4 64-Bit ##
# wget
# rpm -ivh epel-release-4-10.noarch.rpm


Once enabled, you can install using ‘yum‘ package manager tool as shown.

# yum install youtube-dl

Install YouTube-DL in Ubuntu/Linux Mint and Debian

Ubuntu users can download and install latest youtube-dl version from the webupd8 PPA as shown.

$ sudo add-apt-repository ppa:nilarimogard/webupd8
$ sudo apt-get update
$ sudo apt-get install youtube-dl

Update YouTube-DL

Youtube-dl itself can be updated to the latest version using the following command.

# youtube-dl -U

How to Use YouTube-DL to Download Videos

To download a video file, simply run the following command. Where “VIDEO_URL” is the url of the video that you want to download.

# youtube-dl

[youtube] Setting language
[youtube] VMkkaQZAK3c: Downloading video webpage
[youtube] VMkkaQZAK3c: Downloading video info webpage
[youtube] VMkkaQZAK3c: Extracting video information
[download] Destination: Natural Skin Whitening Methods-VMkkaQZAK3c.mp4
[download]  15.3% of 218.88MiB at 968.72KiB/s ETA 03:16

To download a video in availabe file formats, use option “–all-formats” with the command.

# youtube-dl –all-formats

[youtube] Setting language
[youtube] VMkkaQZAK3c: Downloading video webpage
[youtube] VMkkaQZAK3c: Downloading video info webpage
[youtube] VMkkaQZAK3c: Extracting video information
Available formats:
37        :        mp4        [1080x1920]
46        :        webm       [1080x1920]
22        :        mp4        [720x1280]
45        :        webm       [720x1280]
35        :        flv        [480x854]
44        :        webm       [480x854]
34       :       flv        [360x640]
18        :        mp4        [360x640]
43        :        webm       [360x640]
5         :        flv        [240x400]
17        :        mp4        [144x176]

To download a preferred file format, use the option ‘-f’ (video format code). For example, I would like to download flv format, So I use format code as ‘34‘ as shown below.

# youtube-dl -f 34[youtube] Setting language
[youtube] VMkkaQZAK3c: Downloading video webpage
[youtube] VMkkaQZAK3c: Downloading video info webpage
[youtube] VMkkaQZAK3c: Extracting video information
[download] Destination: Natural Skin Whitening Methods-VMkkaQZAK3c.flv
[download]  16.9% of 32.57MiB at 916.81KiB/s ETA 00:30

To download a list of video files, create a file and place all the YouTube links that you wish to download.

# youtube-dl -a youtube_links.txt

Type the following command in a terminal to list all the avialable options.

# man youtube-dl


Protect Apache using Mod_evasive on RHEL/CentOS & Fedora

How to Install Mod_Evasive in RHEL/CentOS & Fedora

As we already installed required dependency packages above, so let’s install the mod_evasive module.

Step 1: Installing Mod_Evasive

Just run the following commands to install mod_evasive.

## For RHEL/CentOS 6.2/6.1/6/5.8 ##
# cd /usr/src 
# wget
# tar xzf mod_evasive_1.10.1.tar.gz
# cd mod_evasive
# apxs -cia mod_evasive20.c## For Fedora 17,16,15,14,13,12 ##
# cd /usr/src 
# wget
# tar xzf mod_evasive_1.10.1.tar.gz
# cd mod_evasive
# apxs -cia mod_evasive20.c

Step 2: Configuring Mod_Evasive

By default installation adds the following line of mod_evasive configuration to your Apache configuration file. Please verify that it should be there like similar to below. If you can’t see this below line, then add this to your httpd.conf file.

LoadModule evasive20_module   /usr/lib/httpd/modules/

Now add the mod_evasive configuration parameters to your Apache configuration at the end. Replace [email protected] with your Email Id to get email alerts.

<IfModule mod_evasive20.c>
DOSHashTableSize    3097
DOSPageCount        2
DOSSiteCount        50
DOSPageInterval     1
DOSSiteInterval     1
DOSBlockingPeriod   60
DOSEmailNotify [email protected]

Next restart the Apache service to update changes.

# /etc/init.d/httpd restart

For more additional information visit the mod_evasive Home Page.

Please drop your comments for any queries on installation, we will love to help you out and don’t forget to Subscribe to our Updates.

Protect Apache using Mod_Security on RHEL/CentOS & Fedora

These two great security modules protect Apache server from brute force attacks and DOS attacks. Before, moving for further installation guide, we would like to provide you a little description on these tow modules.

What is Mod_Security?

Mod_Security is an open source web application firewall (WAF) and intrusion detection and prevention system for web applications. It is used to protect and monitor real time HTTP traffic and web applications from brute fore attacks.

What is Mod_Evasive?

Mod_Evasive is an open source evasive maneuvers system for Apache server to provide evasive action in the event of an HTTP brute force, Dos or DDos attack. It was designed to use as a network traffic detection and network management tool and can be easily configured and integrated into firewalls, ipchains, routers etc. Presently, it sends abuses reports via email and syslog facilites.

Install Mod_Security and Mod_evasive on RHEL 6.2/6.1/6/5.8CentOS 6.2/6.1/6/5.8 and Fedora 17,16,15,14,13,12

How to Install Mod_Security on RHEL/CentOS & Fedora

Step 1: Installing Dependencies for mod_security

Firstly, we required to install some dependency packages for mod_security. Run the following commands on your selected OS.

## For RHEL/CentOS 6.2/6.1/6/5.8 ##
# yum install gcc make
# yum install libxml2 libxml2-devel httpd-devel pcre-devel curl-devel

## For Fedora 17,16,15,14,13,12 ##
# yum install gcc make
# yum install libxml2 libxml2-devel httpd-devel pcre-devel curl-devel

Step 2: Installing Mod_Security

As I said above that we use source code to install mod_security. Run the following commands as root.

## For RHEL/CentOS 6.2/6.1/6/5.8 ##
# cd /usr/src
# wget
# tar xzf modsecurity-apache_2.6.6.tar.gz
# cd modsecurity-apache_2.6.6
# ./configure
# make install
# cp modsecurity.conf-recommended /etc/httpd/conf.d/modsecurity.conf

## For Fedora 17,16,15,14,13,12 ##
# cd /usr/src
# wget
# tar xzf modsecurity-apache_2.6.6.tar.gz
# cd modsecurity-apache_2.6.6
# ./configure
# make install
# cp modsecurity.conf-recommended /etc/httpd/conf.d/modsecurity.conf

Step 3: Downloading OWASP Mod_Security Core Rule Set

Mod_Security requires OWASP (Open Web Application Security Project) core rules for base configuration, these rules are used to protect from unknown vulnerabilities which often found on web applications. So, here we are going to download and install rule set for mod_security. Run the following commands.

## For RHEL/CentOS 6.2/6.1/6/5.8 ##
# cd /etc/httpd/
# wget
# tar xzf modsecurity-crs_2.2.5.tar.gz
# mv modsecurity-crs_2.2.5 modsecurity-crs
# cd modsecurity-crs
# cp modsecurity_crs_10_setup.conf.example modsecurity_crs_10_config.conf## For Fedora 17,16,15,14,13,12 ##
# cd /etc/httpd/
# wget
# tar xzf modsecurity-crs_2.2.5.tar.gz
# mv modsecurity-crs_2.2.5 modsecurity-crs
# cd modsecurity-crs
# cp modsecurity_crs_10_setup.conf.example modsecurity_crs_10_config.conf

Step 4: Configuring Mod_Security

Now, you need to modify your Apache configuration file to load the mod_security module.

# vi /etc/httpd/conf/httpd.conf

Search for the line LoadModule in your httpd.conf and add this below line at the bottom.

LoadModule security2_module modules/

Now set the basic rule set in your httpd.conf file. Add the following lines of code at the end of the file.

<IfModule security2_module>
    Include conf.d/modsecurity.conf

Next, restart the Apache service to enable mod_security module and their rules.

# /etc/init.d/httpd restart

For more information on this topic visit the following links for your reference.

  1. ModSecurity Home Page
  2. OWASP ModSecurity Core Rule Set

The above installation is tested on CentOS 5.6 and successfully worked for me, I hope it will also work for you, now let’s move further installation of mod_evasive module.

Manage Processes with killall and kill

killall is a tool for ending running processes on your system based on name. In contrast, kill terminates processes based on process ID number or “PID.” kill and killallcan also send specific system signals to processes. Use killall and kill in conjunction with tools including ps to manage processes and end processes that have become stuck or unresponsive when necessary.



The killall command takes the following form:

killall [process name]

Replace “[process name]” with the name of any process that you wish to terminate. killall will terminate all programs that match the name specified. Without arguments,killall sends “SIGTERM“, or signal number 15, which terminates running processes that match the name specified. You may specify a different signal using the “-s” option as follows:

killall -s 9 [process name]

This sends the “SIGKILL” signal which is more successful at killing some particularly unruly processes. You may also specify signals in one of the following formats:

killall -KILL [process name]
killall -SIGKILL [process name]
killall -9 [process name]

The above group of commands are equivalent.


The kill command terminates individual processes as specified by their process ID numbers or “PIDs.” Commands take the following form:

kill [PID]

This sends “SIGTERM” to the PID specified. You may specify multiple PIDs on the command line to terminate processes with “kill“. You may also send alternate system signals with kill. The following examples all send the “SIGKILL” signal to the PID specified:

kill -s KILL [PID]
kill -KILL [PID]

System Signals

You may use kill and killall to send any of the following signals.

  10. SIGUSR1
  12. SIGUSR2
  20. SIGSTP
  23. SIGURG
  30. SIGPWR
  31. SIGSYS

Issue one of the following commands to get a list of all of the available signals:

kill -l
killall -l

If you need to convert a signal name into a signal number, or a signal number into a signal name consider the following examples:

$ kill -l 9
KILL$ kill -l kill

Finding Running Processes

You may use a utility like htop </using-linux/administration-basics#monitor_processes__memory__and_cpu_usage_with_htop> or “top` to view a real time list of process and their consumption of system resources. You may also use the ps command to view processes that are currently running and their PIDs.

$ ps aux | grep "emacs"
squire  3896  0.0  2.2  56600 44468 ?        Ss   Sep30   4:29 emacs
squire 22843  0.0  0.0   3900   840 pts/11   S+   08:49   0:00 grep emacs

This command filters the list of all processes that are currently running for the string “emacs” using grep. The number listed in the second column is the PID, which is 3896 in the case of the “emacs” process. The grep process will always match itself for a simple search, as in the second result. To view a hierarchical tree of all running processes, issue the following command:

ps auxf

Once you have obtained the PID or process name, use killall or kill to terminate the process as above.

Verifying Process Termination

The “-w” option to the killall command causes killall to wait until the process terminates before exiting. Consider the following command:

killall -w irssi

This command issues the “SIGTERM” system signal to the process with a name that matches “irssi“.“killall“ will wait until the matched processes have ended. If no process matches the name specified, killall returns an error message, as below:

$ killall -w irssi
irssi: no process found


Optimise cPanel/WHM Server

In the optimization process we will go over the Apache core configuration and modules that are part of Apache core. We think that with the correct settings of Apache and MySQL you can get excellent results and the correct level of resource use without installing third-party proxy and cache modules. So let’s start,


In the first stage we run the Easy Apache and selected the following:

* Apache Version 2+

* PHP Version 5.3+

* In step 5 “Exhaustive Options List” select

– Deflate

– Expires

– MPM Prefork

– MPM Worker

After Easy Apache finished go to your WHM » Service Configuration » Apache Configuration » “Global Configuration” and set the values by the level of resources available on your server.

Apache Directive 	 	(From 2GB memory or less and up to 12GB memory) 	 	

StartServers 	 	 	4 	 	8 	 	16 	
MinSpareServers 	 	4 	 	8 	 	16 	
MaxSpareServers 	 	8 	 	16 	 	32 	
ServerLimit 	 	 	64 	 	128 	 	256 	
MaxClients 	 	 	50 	 	120 	 	250 	
MaxRequestsPerChild 	 	1000 	 	2500 	 	5000 
Keep-Alive			On		On		On
Keep-Alive Timeout	 	5	 	5	 	 5
Max Keep-Alive Requests		50	 	120	 	120
Timeout				30		60		60


Now go to WHM » Service Configuration » Apache Configuration » Include Editor » “Pre VirtualHost Include” and allow users minimal cache and data compression to allow the server to work less for the same things by pasting the code below into the text field.

# Cache Control Settings for one hour cache
<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=3600, public"

<FilesMatch ".(xml|txt)$">
Header set Cache-Control "max-age=3600, public, must-revalidate"

<FilesMatch ".(html|htm)$">
Header set Cache-Control "max-age=3600, must-revalidate"

# Mod Deflate performs data compression
<IfModule mod_deflate.c>
<FilesMatch ".(js|css|html|php|xml|jpg|png|gif)$">
SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE no-gzip


For MySQL you need to update the configuration file that usually in /etc/my.cnf

Best config base on 1 core & 2GB memory MySQL 5.1:

    local-infile = 0
    max_connections = 250
    key_buffer = 64M
    myisam_sort_buffer_size = 64M
    join_buffer_size = 1M
    read_buffer_size = 1M
    sort_buffer_size = 2M
    max_heap_table_size = 16M
    table_cache = 5000
    thread_cache_size = 286
    interactive_timeout = 25
    wait_timeout = 7000
    connect_timeout = 15
    max_allowed_packet = 16M
    max_connect_errors = 10
    query_cache_limit = 2M
    query_cache_size = 32M
    query_cache_type = 1
    tmp_table_size = 16M
    open_files_limit = 4096
    max_allowed_packet = 16M
    key_buffer = 64M
    sort_buffer = 64M
    read_buffer = 16M
    write_buffer = 16M


Best config base on 8 core & 12GB memory MySQL 5.1:

max_connections = 600
key_buffer_size = 512M
myisam_sort_buffer_size = 64M
read_buffer_size = 1M
table_open_cache = 5000
thread_cache_size = 384
wait_timeout = 20
connect_timeout = 10
tmp_table_size = 256M
max_heap_table_size = 128M
max_allowed_packet = 64M
net_buffer_length = 16384
max_connect_errors = 10
concurrent_insert = 2
#table_lock_wait_timeout only for mysql5
table_lock_wait_timeout = 10
read_rnd_buffer_size = 786432
bulk_insert_buffer_size = 8M
query_cache_limit = 5M
query_cache_size = 128M
query_cache_type = 1
query_prealloc_size = 262144
query_alloc_block_size = 65536
transaction_alloc_block_size = 8192
transaction_prealloc_size = 4096
max_write_lock_count = 8

max_allowed_packet = 16M

key_buffer = 384M
sort_buffer = 384M
read_buffer = 256M
write_buffer = 256M

key_buffer = 384M
sort_buffer = 384M
read_buffer = 256M
write_buffer = 256M#### Per connection configuration ####
sort_buffer_size = 1M
join_buffer_size = 1M
thread_stack = 192K


Then restart MySQL and the last step is limiting the use of resources.

Go to WHM » Service Configuration » “PHP Configuration Editor” and set the parameters according to your needs:

– memory_limit

– max_execution_time

– max_input_time


Install CSF (ConfigServer Security & Firewall) at:

And go to WHM » Plugins » ConfigServer Security & Firewall » “Firewall Configuration” and set the parameters according to your needs:






Now enjoy your new fast and more effective server.

Optimise and Tweak High-Traffic Servers

If you are reaching the limits of your server running Apache serving a lot of dynamic content, you can either spend thousands on new equipment or reduce bloat to increase your server capacity by anywhere from 2 to 10 times. This article concentrates on important and poorly-documented ways of increasing capacity without additional hardware.

There are a few common things that can cause server load problems, and a thousand uncommon. Let’s focus on the common:
Drive Swapping – too many processes (or runaway processes) using too much RAM
CPU – poorly optimized DB queries, poorly optimized code, runaway processes
Network – hardware limits, moron attacks

Solutions: The Obvious
Briefly, and for completeness, here are the most obvious solutions:

Use “TOP” and “PS axu” to check for processes that are using too much CPU or RAM.
Use “netstat -anp | sort -u” to check for network problems.


Apache’s RAM Usage
First and most obvious, Apache processes use a ton a RAM. This minor issue becomes a major issue when you realize that after each process has done its job, the bloated process sits and spoon-feed data to the client, instead of moving on to bigger and better things. This is further compounded by a bit of essential info that should really be more common knowledge:

If you serve 100% static files with Apache, each httpd process will use around 2-3 megs of RAM.
If you serve 99% static files & 1% dynamic files with Apache, each httpd process will use from 3-20 megs of RAM (depending on your MOST complex dynamic page).

This occurs because a process grows to accommodate whatever it is serving, and NEVER decreases again unless that process happens to die. Quickly, unless you have very few dynamic pages and major traffic fluctuation, most of your httpd processes will take up an amount of RAM equal to the largest dynamic script on your system. A smart web server would deal with this automatically. As it is, you have a few options to manually improve RAM usage.

Reduce wasted processes by tweaking KeepAlive
This is a tradeoff. KeepAliveTimeout is the amount of time a process sits around doing nothing but taking up space. Those seconds add up in a HUGE way. But using KeepAlive can increase speed for both you and the client – disable KeepAlive and the serving of static files like images can be a lot slower. I think it’s best to have KeepAlive on, and KeepAliveTimeout very low (like 1-2 seconds).

Limit total processes with MaxClients
If you use Apache to serve dynamic content, your simultaneous connections are severely limited. Exceed a certain number, and your system begins cannibalistic swapping, getting slower and slower until it dies. IMHO, a web server should automatically take steps to prevent this, but instead they seem to assume you have unlimited resources. Use trial & error to figure out how many Apache processes your server can handle, and set this value in MaxClients. Note: the Apache docs on this are misleading – if this limit is reached, clients are not “locked out”, they are simply queued, and their access slows. Based on the value of MaxClients, you can estimate the values you need for StartServers, MinSpareServers, & MaxSpareServers.

Force processes to reset with MaxRequestsPerChild
Forcing your processes to die after a while makes them start over with low RAM usage, and this can reduce total memory usage in many situations. The less dynamic content you have, the more useful this will be. This is a game of catch-up, with your dynamic files constantly increasing total RAM usage, and restarting processes constantly reducing it. Experiment with MaxRequestsPerChild – even values as low as 20 may work well. But don’t set it too low, because creating new processes does have overhead. You can figure out the best settings under load by examining “ps axu –sort:rss”. A word of warning, using this is a bit like using heroin. The results can be impressive, but are NOT consistent – if the only way you can keep your server running is by tweaking this, you will eventually run into trouble. That being said, by tweaking MaxRequestsPerChild you may be able to increase MaxClients as much as 50%.

Apache Further Tweaking
For mixed purpose sites (say image galleries, download sites, etc.), you can often improve performance by running two different apache daemons on the same server. For example, we recently compiled apache to just serve up images (gifs,jpegs,png etc). This way for a site that has thousands of stock photos. We put both the main apache and the image apache on the same server and noticed a drop in load and ram usage. Consider a page had about 20-50 image calls — the were all off-loaded to the stripped down apache, which could run 3x more servers with the same ram usage than the regular apache on the server.

Finally, think outside the box: replace or supplement Apache

Use a 2nd server
You can use a tiny, lightning fast server to handle static documents & images, and pass any more complicated requests on to Apache on the same machine. This way Apache won’t tie up its multi-megabyte processes serving simple streams of bytes. You can have Apache only get used, for example, when a php script needs to be executed. Good options for this are:

TUX / “Red Hat Content Accelerator” –
kHTTPd –
thttpd –

Try lingerd
Lingerd takes over the job of feeding bytes to the client after Apache has fetched the document, but requires kernel modification. Sounds pretty good, haven’t tried it. lingerd –

Use a proxy cache
A proxy cache can keep a duplicate copy of everything it gets from Apache, and serve the copy instead of bothering Apache with it. This has the benefit of also being able to cache dynamically generated pages, but it does add a bit of bloat.

Replace Apache completely
If you don’t need all the features of Apache, simply replace it with something more scalable. Currently, the best options appear to be servers that use a non-blocking I/O technology and connect to all clients with the same process. That’s right – only ONE process. The best include:

thttpd –
Caudium –
Roxen –
Zeus ($$) –


PHP’s CPU & RAM Usage
Compiling PHP scripts is usually more expensive than running them. So why not use a simple tool that keeps them precompiled? I highly recommend Turck MMCache. Alternatives include PHP Accelerator, APC, & Zend Accelerator. You will see a speed increase of 2x-10x, simple as that. I have no stats on the RAM improvement at this time.


Optimize Database Queries
This is covered in detail everywhere, so just keep in mind a few important notes: One bad query statement running often can bring your site to its knees. Two or three bad query statements don’t perform much different than one. In other words, if you optimize one query you may not see any server-wide speed improvement. If you find & optimize ALL your bad queries you may suddenly see a 5x server speed improvement. The log-slow-queries feature of MySQL can be very helpful.

How to log slow queries:

# vi /etc/rc.d/init.d/mysqld

Find this line:

change it to:
SAFE_MYSQLD_OPTIONS=”–defaults-file=/etc/my.cnf –log-slow-queries=/var/log/slow-queries.log”

As you can see, we added the option of logging all slow queries to /var/log/slow-queries.log
Close and save mysqld. Shift + Z + Z

touch /var/log/slow-queries.log
chmod 644 /var/log/slow-queries.log

restart mysql
service myslqd restart
mysqld will log all slow queries to this file.

These sites contain additional, more well known methods for optimization.

Tuning Apache and PHP for Speed on Unix –
Getting maximum performance from MySQL –
System Tuning Info for Linux Servers –
mod_perl Performance Tuning (applies outside perl) –

Once again, if this has any errors or important omissions, please let me know and I will correct them.
If you experience a capacity increase on your server after trying the optimizations, let me know!