Saturday 13 September 2014

vi Find And Replace Text Command


How do I find and replace (substitute) test using vi or vim text editor under UNIX / Linux / BSD or Apple OS X operating systems?


Both vi and vim text editor comes with substitute command for finding and replacing text.


Syntax


The syntax is as follows:
:%s/WORD-To-Find-HERE/Replace-Word-Here/g
OR
:%s/FindMe/ReplaceME/g


Examples


The substitute command can be used as per your requirements.


Task: VI / Vim Basic Find and Replace


To find each occurrence of 'UNIX', and replace it with 'Linux', enter (press ESC, type : and following command):
:%s/UNIX/Linux/g


Task: Find and Replace with Confirmation


Find a word called 'UNIX' and replace with 'Linux', but ask for confirmation first, enter:
:%s/UNIX/Linux/gc


Task: Find and Replace Whole Word Only


Find whole words exactly matching 'UNIX' to 'Linux'; and ask for confirmation too:
:%s/<UNIX>/Linux/gc


Task: Case Insensitive Find and Replace


Find 'UNIX' (match UNIX, unix, UnIx, Unix and so on) and replace with 'Linux':
:%s/unix/Linux/gi
Same command with confirmation:
:%s/unix/Linux/gic


Task: Case sensitive Find and Replace


Find each 'UNIX' and replace with 'bar':
:%s/UNIX/bar/gI
Same command with confirmation:
:%s/UNIX/bar/gIc


How Do I Replace In the Current Line Only?


Find 'UNIX' and replace with 'Linux' in the current line only (note % is removed from substitute command):
:s/UNIX/Linux/g
NOTE: You need to prefix % the substitute command to make changes on all lines:
:%s/UNIX/Linux/g


How Do I Replace All Lines Between line 100 and line 250?


:{START-n},{END-n}s/word1/word2/g
Find 'UNIX' and replace with 'Linux' all lines between line 100 and line 250, enter:
:100,200s/UNIX/Linux/g
OR
:100,200s/UNIX/Linux/gc

ffmpeg installer

Enabling mbstring Library in PHP.ini

cPanel to cPanel migration via SSH - Multiple domains

Know more about localdomains and remotedomains

Services for one domain do not need to be on one server. The site host and email server for a domain do not need to be on the same physical server.


DNS is used to direct the traffic to the correct place, but DNS alone will not get all the bits to where they are supposed to be. Exim, cPanel’s SMTP service needs a little help beyond DNS in order to know how to handle mail that is generated locally.


This is where /etc/localdomains and /etc/remotedomains come into play.





  • How do it works




Email sent out from a cPanel server, exim has to checks /etc/localdomains and /etc/remotedomains in order to send the email to the correct location.


If the domain is in /etc/localdomains, the mail is routed locally to the machine. If the domain is in /etc/remotedomains, the email is routed out to the Internet.


This is useful if the domain has some software installed that sends email notifications, such as a content management system like WordPress. This ensures that mail will get sent to the correct location.


If domain uses a third party mail server for email and the domain is not in remotedomains, notifcations from the CMS will not be delivered.





  • Setting email option during account creation




At the bottom of the account creation page in the Webhost Manager.


If Local Mail Exchanger is set, cPanel places the domain in localdomains. If Remote Mail Exchanger is selected, it places the domain in remotedomains. If Backup Mail Exchanger is selected, the domain will be added to localdomains but will only accept mail if there are no other mail servers available.


Automatically Detect Configuration will check the DNS Mail Exchanger records to see where the DNS is pointed, and make the configuration based off of that. Most of the time, this is the best option to select. However, if DNS has not been setup for the domain yet, you may wish to set the Exchanger manually.


Automatically Detect Configuration will check the DNS Mail Exchanger records to see where the DNS is pointed, and make the configuration based off of that. Most of the time, this is the best option to select. However, if DNS has not been setup for the domain yet, you may wish to set the Exchanger manually.



How to modify my hosts file?

Modifying your hosts file will allow you to override the DNS for a domain, on that particular machine. This can be used to test your site without the test link, prior to going live with SSL, verify an alias site works prior to DNS changes, or for other DNS related reasons. This causes your local machine only to look directly at the IP specified.


Your hosts file will need to have two entries added that will contain the IP address you want the site to resolve to and the address. Adding the below two lines for example will point www.domain.com and domain.com to our current PHP5-ITK ("Refreshed" PHP5) cluster:


1.2.3.4 www.domain.com
1.2.3.4 domain.com


Below is how to locate and edit the hosts file on several OS platforms. Once the proper domain information is added you will save the file and your system will begin resolving to the specified IP. Once testing is finished these entries should be removed.


Contents:-   
Windows Vista and Windows 7
Windows NT/2000/XP
Linux
Mac OSX 10.0 - 10.1.5
Mac OSX 10.6 - 10.8


 


 

Mail queue alert script for cPanel server via email

We need to monitor our server mail queue for cPanel servers, Possible outgoing spam as well as to maintain the server performance. Often large mail queue causes server overloading issues. It is very easy to get an alert if your server mail queue contains more than X  numbers of mails. You can use the following script to monitor your server mail queue for your cPanel servers:




#!/bin/bash
# use: Bash Shell script to monitor or Check Mail queue


EMAIL=”your email address”

MQUEUE=`find /var/spool/exim/input -name ‘*-H’ | wc -l | sed -e “s/ //g”`

if [ $MQUEUE -gt XXX ]; then
echo “Mail queue at `hostname` has $MQUEUE messages!!!” | mail -s “MAIL QUEUE ALERT: Mail queue for `hostname`” $EMAIL
fi

Better WP Security

Easiest and most effective way to secure your WordPress to Improve security of any your wordpress site's in minutes.


#1 WORDPRESS SECURITY PLUGIN


Better WP Security now by iThemes


Get ready for Better WP Security to get even better! It's now being maintained and developed full-time by Chris Wiegman for iThemes. Not only will this take Better WP Security to the next level but it will bring a new level of security to the best ecommerce solution on the market, iThemes Exchange as well as all of iThemes excellent plugins and themes.


Better WP Security takes the best WordPress security features and techniques and combines them in a single plugin thereby ensuring that as many security holes as possible are patched without having to worry about conflicting features or the possibility of missing anything on your site.


With one-click activation for most features as well as advanced features for experienced users Better WP Security can help protect any site.


Professional Installation and Support Now Available


Need help or want to make sure your setup is as secure as possible? Professional support is now available! Purchase support or installation today through our partner FooPlugins


Obscure


As most WordPress attacks are a result of plugin vulnerabilities, weak passwords, and obsolete software. Better WP Security will hide the places those vulnerabilities live keeping an attacker from learning too much about your site and keeping them away from sensitive areas like login, admin, etc.



  • Remove the meta "Generator" tag

  • Change the urls for WordPress dashboard including login, admin, and more

  • Completely turn off the ability to login for a given time period (away mode)

  • Remove theme, plugin, and core update notifications from users who do not have permission to update them

  • Remove Windows Live Write header information

  • Remove RSD header information

  • Rename "admin" account

  • Change the ID on the user with ID 1

  • Change the WordPress database table prefix

  • Change wp-content path

  • Removes login error messages

  • Display a random version number to non administrative users anywhere version is used


Protect


Just hiding parts of your site is helpful but won't stop everything. After we hide sensitive areas of the sites we'll protect it by blocking users that shouldn't be there and increasing the security of passwords and other vital information.



  • Scan your site to instantly tell where vulnerabilities are and fix them in seconds

  • Ban troublesome bots and other hosts

  • Ban troublesome user agents

  • Prevent brute force attacks by banning hosts and users with too many invalid login attempts

  • Strengthen server security

  • Enforce strong passwords for all accounts of a configurable minimum role

  • Force SSL for admin pages (on supporting servers)

  • Force SSL for any page or post (on supporting servers)

  • Turn off file editing from within WordPress admin area

  • Detect and block numerous attacks to your filesystem and database


Detect


Should all the protection fail Better WP Security will still monitor your site and report attempts to scan it (automatically blocking suspicious users) as well as any changes to the filesystem that might indicate a compromise.



  • Detect bots and other attempts to search for vulnerabilities

  • Monitor filesystem for unauthorized changes


Recover


Finally, should the worst happen Better WP Security will make regular backups of your WordPress database (should you choose to do so) allowing you to get back online quickly in the event someone should compromise your site.



  • Create and email database backups on a customizable schedule


Other Benefits



  • Make it easier for users to log into a site by giving them login and admin URLs that make more sense to someone not accustomed to WordPress

  • Detect hidden 404 errors on your site that can affect your SEO such as bad links, missing images, etc.


Compatibility



  • Works on multi-site (network) and single site installations

  • Works with Apache, LiteSpeed or NGINX (NGINX will require you to manually edit your virtual host configuration)

  • Some features can be problematic if you don't have enough RAM to support them. All my testing servers allocate 128MB to WordPress and usually don't have any other plugins installed. I have seen issues with file check and database backups failing on servers with 64MB or less of RAM, particularly if there are many other plugins being used.


Translations



  • Brazilian Portuguese by Rafael Funchal

  • Bulgarian by Nikolay Kolev of Gymnastics and Bodyweight Tutorials and Martin Halachev

  • Chinese (Traditional) by Toine Cheung

  • French by SCUDELLER Eric

  • German by Rene Wolf

  • Hindi by Outshine Solutions

  • Lithuanian by Vincent G

  • Persian by Ibrahim Jafari

  • Russian

  • Simplified Chinese by ??

  • Slovak by Erich Szabó

  • Spanish by Pablo Romero

  • Tagalog by Hanne

  • Turkish by Hakan Er


Please let us know if you would like to contribute a translation.


Warning


Please read the installation instructions and FAQ before installing this plugin. It makes some significant changes to your database and other site files which, without a proper backup, can cause problems if something goes wrong. While problems are rare, most (not all) support requests I get for this plugin involve the users failure to make a proper backup before installing.


Setup a CentOS IPSEC VPN Server

Install the Nikoforge Repository


rpm -ivH http://repo.nikoforge.org/redhat/el6/nikoforge-release-latest


Install EPEL Repo


yum -y install http://vesta.informatik.rwth-aachen.de/ftp/pub/Linux/fedora-epel/6/i386/epel-release-6-8.noarch.rpm


Install IPSEC Tools


yum -y install ipsec-tools


The ipsec-tools package from the nikoforge repo is a patched version that allow the use of a wildcard ‘’ as the IPSec identifier [1]. Not needed for Android, but iOS.*


Install Layer 2 Tunneling Protocol Daemon


yum -y install xl2tpd


Create script ”/etc/racoon/init.sh”


Insert the following:


    #!/bin/sh
# set security policies
echo -e “flush;n
spdflush;n
spdadd 0.0.0.0/0[0] 0.0.0.0/0[1701] udp -P in ipsec esp/transport//require;n
spdadd 0.0.0.0/0[1701] 0.0.0.0/0[0] udp -P out ipsec esp/transport//require;n”
| setkey -c
# enable IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward


Then set the correct permissions


chmod 750 /etc/racoon/init.sh


Add a call of the script to rc.local


sed –in-place ‘//etc/racoon/init.sh/d’ /etc/rc.d/rc.local
echo /etc/racoon/init.sh >> /etc/rc.d/rc.local


IPSEC CONFIGURATION


Racoon Config ”/etc/racoon/racoon.conf” (If there is one already there, bcack it up to .old)


path include “/etc/racoon”;
path pre_shared_key “/etc/racoon/psk.txt”;
path certificate “/etc/racoon/certs”;
path script “/etc/racoon/scripts”;
remote anonymous
{
exchange_mode aggressive,main;
passive on;
proposal_check obey;
support_proxy on;
nat_traversal on;
ike_frag on;
dpd_delay 20;
proposal
{
encryption_algorithm aes;
hash_algorithm sha1;
authentication_method pre_shared_key;
dh_group modp1024;
}
proposal
{
encryption_algorithm 3des;
hash_algorithm sha1;
authentication_method pre_shared_key;
dh_group modp1024;
}
}
sainfo anonymous
{
encryption_algorithm aes,3des;
authentication_algorithm hmac_sha1;
compression_algorithm deflate;
pfs_group modp1024;
}


Set the relevant permissions


chmod 600 /etc/racoon/racoon.conf


Racoon Pre shared Keys


Create the pre-shared keys file for IKE authentication. The 1st column the IPSec Identifier, the 2nd column is the IPSec preshared key.


”/etc/racoon/psk.txt”


ANDROID


myhomelan d41d8cd98f00b204e980


IOS



* d41d8cd98f00b204e980




Set the correct permissions



chmod 600 /etc/racoon/psk.txt



CONFIGURING L2TP DAEMON


Create file ”/etc/xl2tpd/xl2tpd.conf




[global]
ipsec saref = yes
force userspace = yes
[lns default]
local ip = 10.203.123.200
ip range = 10.203.123.201-10.203.123.210
refuse pap = yes
require authentication = yes
ppp debug = yes
length bit = yes
pppoptfile = /etc/ppp/options.xl2tpd



CONFIGURING PPP


Create PPP option file ”/etc/ppp/options.xl2tpd



    ms-dns 10.203.120.41
ms-dns 8.8.8.8
require-mschap-v2
asyncmap 0
auth
crtscts
lock
hide-password
modem
debug
name l2tpd
proxyarp
lcp-echo-interval 10
lcp-echo-failure 100



Create the CHAP Secrets file ”/etc/ppp/chap-secrets”



    # client server secret IP addresses
janedoe * jd480227 *



Set the Correct permissions


 


chmod 600 /etc/ppp/chap-secrets


START THE SERVICES


    chkconfig racoon on
chkconfig xl2tpd on
service racoon start
service xl2tpd start
/etc/racoon/init.sh


ANDROID CLIENT SETUP


    NAME – ANYTHING
TYPE – L2TP/IPSec PSK
SERVER ADDRESS – IP or hostname of server
L2TP SECRET – NOT USED
IPSec IDENTIFIER – what was set in first colum of racoon psk file
PRE-SHARED KEY – What was in the second column of racoon psk file


For my VPS to pass traffic through i had to execute the following


iptables –table nat –append POSTROUTING –jump MASQUERADE


echo “net.ipv4.ip_forward = 1? | tee -a /etc/sysctl.conf
echo “net.ipv4.conf.all.accept_redirects = 0? | tee -a /etc/sysctl.conf
echo “net.ipv4.conf.all.send_redirects = 0? | tee -a /etc/sysctl.conf
for vpn in /proc/sys/net/ipv4/conf/*; do echo 0 > $vpn/accept_redirects; echo 0 > $vpn/send_redirects; done
sysctl -p


for vpn in /proc/sys/net/ipv4/conf/*; do echo 0 > $vpn/accept_redirects; echo 0 > $vpn/send_redirects; done
iptables –table nat –append POSTROUTING –jump MASQUERADE


 

What is PHP Composer?

If you have ever written anything in PHP before, you have probably found that it feels like you have to keep re-inventing the wheel anytime you want to do a common task such as User Authentication, Database Management or Request Routing. PHP now has a handful of mature frameworks that have already solved all of these problems, so wouldn’t it be easier to cherry pick the bits that you needed from each framework?


If you were to start manually picking the bits you wanted from Zend, or Laravel or Symfony, then it would become very difficult to manage. Each library might also have dependencies, and so you would end up in a mess, particularly if you required other people to work on your project.


This is where Composer comes in. Composer is a dependency manager for PHP. Composer will manage the dependencies you require on a project by project basis. This means that Composer will pull in all the required libraries, dependencies and manage them all in one place.


This kind of management for dependencies in a project is not a new concept, and in fact, much of Composer is actually inspired from npm from Node.js and Bundler from Ruby.


You might also be aware of PEAR. PEAR is an established PHP package manager that has been around for years. PEAR however, has been abandoned by many PHP developers for a number of reasons. Firstly, much of the code in PEAR is out-of-date. Secondly, PEAR forces you to install packages system wide, rather than on a project-by-project basis. This means that if you already have a project that relies on a slightly older package, you are screwed. For an excellent history of PHP packages, read Packages: The Way Forward for PHP by Phil Sturgeon.


Installing Composer


Installing Composer is really easy as it can all be done through the command line. I’m using OS X, but the following should be the same for any *nix operating system.


So fire up Terminal and run the following commands:


$ curl -s https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer


The first command downloads the composer.phar file to your computer. The second line moves the composer.phar file in to your bin so that is accessible globally on your computer.


Now run the following command:


$ composer


If you have installed Composer successfully, you should be given a list of available commands and descriptions.
Installing on Windows?


If you are looking to install Composer on a Windows machine, take a look at the guide on the Composer website.
Using Composer


Now that you have Composer installed, you can use it to require some packages into your project. To make a Composer configuration file, we just need to make a JSON file in the root of the project.


For example, if you wanted to use Slim Framework you could create the following composer.json file.


{
"require": {
"slim/slim": "2.*"
}
}


To install Slim via Composer, you can simply run the following command through Terminal.


$ composer install


This will automatically download Slim into your project under the directory vendor/slim/slim.


See, how easy was that?
Autoloading


Now that you have all of these different packages, you need the ability to autoload them into your project. Fortunately Composer also comes with an autoload file, which is capable of autoloading any of the files in the projects that you download.


To use the Composer autoloader, simply include the following line in your project’s index or bootstrap file.


require 'vendor/autoload.php';


Now you can start using the new libraries without having to worry about loading them up.


For example:


// Autoload
require 'vendor/autoload.php';


// Instantiate a Slim application
$app = new SlimSlim();


// Define a HTTP GET route
$app->get('/hello/:name', function ($name) {
echo "Hello, $name";
});


// Run the Slim application
$app->run();
Conclusion


Package management is clearly the right route forward for PHP. Languages such as Ruby have shown how incredibly easy it is to use packages within projects so common problems can be solved once, and you can stop wasting time as a developer by constantly reinventing the wheel.


Many of the most popular frameworks have already positioned themselves to use Composer, and many more individual developers are releasing code that is Composer ready from the get go.


As a PHP developer, Composer will become your best friend, and as it’s usage increases, it will become an essential part of writing PHP on a day-to-day basis.


By following conventions, PHP can become a much better language to use. Composer has already solved a big problem in the PHP community, so there’s really no reason why you shouldn’t start using it today.

How to install htop

To install htop with yum, the EPEL repository must be installed.

Redhat / CentOS 5 (most likely version in use)


32bit: rpm -Uvh http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
64bit: rpm -Uvh http://download.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm

Redhat / CentOS 6


32bit: rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
64bit: rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

Now that the repository is installed to the server, we can install htop
yum install htop

 

Tuesday 9 September 2014

Install NixTree PHP Selector in CloudLinux cPanel server

NixTree PHP Selector plugin allows a domain user to select preferred PHP version per directory on the same domain.
Note :This plugin requires SuPHP on the system; it will not work with any other PHP handlers for now.

To install ntPHPselector, run the following commands:

cd /usr/local/src
wget -N http://nixtree.com/download/free/ntphpselector_manage.sh
sh ntphpselector_manage.sh install


To recompile php in ntPHPselector, run the following command:

sh ntphpselector_manage.sh recompile <option>


– option
2 for 5.2
3 for 5.3
4 for 5.4
5 for 5.5

eg: recompile php5.2

sh ntphpselector_manage.sh recompile 2


For uninstalling the plugin:

sh ntphpselector_manage.sh uninstall