Wednesday 30 July 2014

Changing Time Zones via php.ini file in cpanel servers 

You can change the parameter date.timezone to change it to appropriate time zone. 

eg : -

date.timezone = "America/Denver";

Use the appropriate option at http://php.net/timezones



Changing wordpress theme to default theme via command line


Log in to mysql server and issue the command :

SELECT * FROM wp_options WHERE option_name = 'template' OR option_name = 'stylesheet' OR option_name = 'current_theme';

UPDATE wp_options SET option_value = 'twentyeleven' WHERE option_name = 'template' or option_name = 'stylesheet' or option_name = 'current_theme';

Pointing your home site's URL to a subdirectory in wordpress

In some cases, you may have a WordPress site that changes significantly every year, such as with a conference website. If you want to install each year's version of the site in a subdirectory, such as /2010, /2011, and /2012, but have the root domain (yoursite.com) automatically redirect to a particular subdirectory (usually the latest), follow this technique:

Install WordPress in a subdirectory, such as /2012.

In your root folder (not the subdirectory folder), download and open your .htaccess file.

Add the following to your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?YourDomain.com$
RewriteRule ^(/)?$ blog [L]

In the above code, change the "YourDomain.com" value to your root domain.

In the above code, change the "blog" value to the subdirectory.

Save and upload the .htacess file back to your root directory.

Now when users to go your root domain (yoursite.com), it will automatically redirect to the subdirectory you specified. When you want to redirect to a new subdirectory, such as the conference site for next year, just update the .htaccess redirect code.

Finding Document root of the domains in Cpanel servers

grep -C 1 www.yourdommain.com  /etc/httpd/conf/httpd.conf

Rsync command

rsync -uavz --progress /home/positive/ -e "ssh -p 15554" root@192.168.1.118:/home/positive/

Installing git in Cpanel servers

However the solution is simple - it's already installed! (as of cPanel 11.36)

Just run:

/usr/local/cpanel/3rdparty/bin/git

if you want to add it to your path you can symlink it using something like this:

ln -s /usr/local/cpanel/3rdparty/bin/git /usr/bin/git

Spamming Detection 

Checking compromised devcot logins :

egrep -o 'dovecot_login[^ ]+' /var/log/exim_mainlog | sort|uniq -c|sort -nk 1

Check whether emails are sent using scripts 

grep "cwd=" /var/log/exim_mainlog|awk '{for(i=1;i<=10;i++){print $i}}'|sort|uniq -c|grep cwd|sort -n

By checking the domlogs in the location /usr/local/apache/domlogs (cpanel servers) we can find the exact script which is used to send the spam. eg :- 

grep POST /usr/local/apache/domlogs/domain.com(The domain in which the spam are sent)



Add/Remove Reseller Privileges in WHM


Home >> Resellers >> Reseller Center)

Using a set of pull-down menus and buttons, you are able to add or remove reseller status on existing accounts. It is important to keep in mind that you are not able to add a new account here. You must first create the account you wish to modify using the Create a New Account feature.

To add reseller privileges :

Select the appropriate account from the pull-down menu on the left.

Click the checkbox if you wish to allow the reseller to access his or her account via WHM. (You will be able to configure the user’s WHM options by clicking Edit Privileges/Nameservers below.)

Click the corresponding ok button.


To remove reseller privileges:

Select the appropriate account from the pull-down menu on the right.

Click the corresponding ok button.

Code to test PHP function mail()

In order to test PHP function mail() on your server, create a test PHP file (e.g., testmail.php) with the following contents:

<?php
$message = '';

if (isset($_POST['email']) && !empty($_POST['email'])){
  if (mail($_POST['email'], $_POST['subject'], $_POST['body'], '')){
    $message = "Email has been sent to <b>".$_POST['email']."</b>.<br>";
  }else{
    $message = "Failed sending message to <b>".$_POST['email']."</b>.<br>";
  }
}else{
  if (isset($_POST['submit'])){
    $message = "No email address specified!<br>";
  }
}

if (!empty($message)){
  $message .= "<br><br>n";
}
?>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>
      Mail test
    </title>
  </head>
  <body>
    <?php echo $message; ?>
    <form method="post" action="">
      <table>
        <tr>
          <td>
            e-mail
          </td>
          <td>
            <input name="email" value="<?php if (isset($_POST['email'])
            && !empty($_POST['email'])) echo $_POST['email']; ?>">
          </td>
        </tr>
        <tr>
          <td>
            subject
          </td>
          <td>
            <input name="subject">
          </td>
        </tr>
        <tr>
          <td>
            message
          </td>
          <td>
            <textarea name="body"></textarea>
          </td>
        </tr>
        <tr>
          <td>
            &nbsp;
          </td>
          <td>
            <input type="submit" value="send" name="submit">
          </td>
        </tr>
      </table>
    </form>
  </body>
</html>

Upload the created file to a publicly accessible directory (e.g. public_html, www, htdocs or another depending on the server configuration).

Run the test file by typing its URL in the browser address bar, e.g. http://mydomain.com/testmail.php.

Enter an email address, a message subject and body in the text fields of the page that will appear and click on "send" to send a test email message.
In case of a successful dispatch of the email a message of kind "Email has been sent to …" will appear in the browser. Otherwise "Failed sending message to..." will appear.

Rvsite builder update script

perl /usr/local/cpanel/whostmgr/docroot/cgi/rvsitebuilderinstaller/autoinstaller.cgi --force 

script to view encrypted password in Plesk 

/usr/local/psa/bin/admin --show-password

Friday 20 June 2014

/Var issues check :

ls -lh /var/log/* >> check for the log files which is consuming high size


 ls -hrSal /var/spool/mail/*  >> Check for the account usernames which is consuming high size (above 50 MB) then,

tail -2000 /var/spool/mail/username


ls -lh /var/spool/mqueue/*  >> check the recent email headers using the command :

tail -2000 /var/spool/mqueue/id
Semaphores

# ipcs -s
If you see a list of semaphores, Apache has not cleaned up after itself, and some semaphores are stuck. Clear them out with this command:

 for i in `ipcs -s | awk '/httpd/ {print $2}'`; do (ipcrm -s $i); done
Command to check the most recent resources usage in cpanel servers

/usr/local/cpanel/bin/dcpumonview

Log location : /var/log/dcpumon/
Command to get recent reboot logs

 grep -A 10 -B 30 syslogd /var/log/messages

Command to check memory usage in windows server

tasklist /fi "memusage gt 90000" | sort /R /+58

Sunday 9 February 2014

Clam Scan Manual Installation


cd /usr/local/src
rm -Rf clamav-*
wget http://downloads.sourceforge.net/clamav/clamav-0.96.tar.gz
tar -xzf clamav-*
cd clamav-*
if [ -d "/usr/lib64" ]; then libdir=”–libdir=/usr/lib64″ ; fi ; ./configure –prefix=/usr $libdir –sysconfdir=/etc –disable-ipv6 –disable-zlib-  vcheck
make
make install
freshclam
echo “ClamAV update complete!”



Reset Mysql Root password 


Recover a MySQL root password via the folowing steps :

Stop the MySQL server process :

/etc/init.d/mysql stop

Start again with no grant tables.

mysqld_safe --skip-grant-tables &

Login to MySQL as root.

mysql -u root
use mysql;

Set new password.

update user set password=PASSWORD("newrootpassword") where User='root';
flush privileges;
quit

Exit MySQL and restart MySQL server.

/etc/init.d/mysql stop
/etc/init.d/mysql start

Install Php Module yaml in Cpanel server


Try installing yaml using pecl :

pec install yaml

You may encounter an error:

configure: error: Please install libyaml

wget http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz

tar -xvzf yaml-0.1.4.tar.gz

cd yaml-0.1.4

./configure

make

make install

Then run pecl again :

pec install yaml

Then verify it from php -m :

# php -m | grep yaml
yaml

Editing different Document Root for Cpanel domain


You can follow the below steps for changing the document root other than public_html for a cpanel domain.

Change the document root in the following files.

/var/cpanel/userdata/user/domain.com

/usr/local/apache/conf/httpd.conf

Then:

/usr/local/cpanel/bin/apache_conf_distiller –update
/usr/local/cpanel/bin/build_apache_conf



Find the number of  HTTP connections to the server


netstat -plane | grep :80 | awk {'print$5'} | cut -f1 -d ':' | sort | uniq -c | sort -n




Cpanel shows 0 MB size for all databases after migration



vi /var/cpanel/cpanel.config

Change : 

disk_usage_include_sqldbs=1

And run the following command :

/scripts/update_db_cache

Find Max apache connections to a domain from IPs



cat /usr/local/apache/domlogs/domain.com  | awk '{print $1}'|cut -d'@' -f2|sort|uniq -c|sort -nr


Clear Memory Cache on Linux servers


After loging in to the server type the following command :

sync; echo 3 > /proc/sys/vm/drop_caches

======================================