How to chown/chmod all files in current directory?

So – you migrated some file to a plesk/cpanel server and the ownership is wrong. Here is how to change it.

[root@austin httpdocs]# cd /var/www/vhosts/
[root@austin httpdocs]# chown -R  user:group *


[root@austin httpdocs]# cd /home/user/public_html/
[root@austin httpdocs]# chown -R  user:group *



[root@austin httpdocs]# chown -R  user:group /var/www/vhosts/*


[root@austin httpdocs]# chown -R  user:group /home/user/public_html/*

Move a site from one plesk domain to another

How do you move a site from one plesk domian to another on the same server?

The ftp and export method.

Get your data.

1. Ftp to the old site and download the files to your local computer.
2. Login to the plesk panel and go to Manage Hosting for the old domain. Go to Websites and Domains. Go to databases. Click on the database name. Click Webadmin. Click Export Tab. Click Custom. make sure all the databases tables are selected (blue). Click Go. This should produce a popup so you can save the file locally.

New Domain.

1. Login to pelsk and click subscriptions. Click Add New Subscription. Fill out the details (make note of the new username and password) and and click okay.
2. ftp to the new domain and upload the files from the old domain.
3. Go to Manage Hosting for the new domain. Go to Websites and Domains. Go to databases. Click add new database. Click on the database name after creation and add a new database user. Click on Webadmin and go to the import tab. Locate the file for the database download and upload. You should see all the tables at this point.
4. Locate the database config file in the new database and edit it with the new database name, user and password.

Atomic repo php Upgrade error

Servers popping up that are having php failures or issues with php_admin_value or php_admin_flag when apache restarts. This is occurring on servers running PHP 5.3.26. It appears when this update was pushed out, mod_php is no longer being loaded by default.

The symptoms are outlined here:

You should be able to add the following to the top of php.conf file to resolve the issue:

<IfModule prefork.c>
  LoadModule php5_module modules/
<IfModule worker.c>
  LoadModule php5_module modules/


If you come across a managed server that has the atomic repo enabled and has updated to PHP 5.4.x it more than likely killed their sites.

If this is the case and they were on a newer version of 5.3.x from atomic I’ve got the couple of one liners that I used to remove all the install PHP packages and then install the webtatic repo (which installed disabled) and then to install a base set of php modules from their repo.

This command will figure out what php-5.4.x packages are installed from atomic. Just to verify that you won’t be killing off anything other than the offending atomic packages.

rpm -qa | grep php | grep 5.4

This one-liner will remove all packages that match the above criteria even if they refer to multiple packages or are listed more than once.

for i in `rpm -qa | grep php | grep 5.4` ; do rpm -ev --allmatches --nodeps $i; done

Once they are all removed install the webtatic repo

rpm -Uvh

Then you can install the basic set of packages for php 5.3

yum --enablerepo=webtatic install php php-devel php-mysql php-imap php-xml php-pdo php-gd php-soap

Manage Processes

If you connect to the server via SSH and run the command:

ps afwux


[root@austin ~]# ps afwux | grep php
root       998  0.0  0.3 335940 25100 ?        Ss   Jun18   1:10 /usr/bin/sw-engine -c /usr/local/psa/admin/conf/php.ini /usr/local/psa/admin/bin/modules/watchdog/wdcollect -c /usr/local/psa/etc/modules/watchdog/
root     19926  0.0  0.0 103244   848 pts/0    S+   14:39   0:00          _ grep php
10016    23321  0.0  0.1 257956 10956 ?        S    Jul01   0:00 /usr/bin/php-cgi -c /var/www/vhosts/system/
10016    19924  0.5  0.7 275928 57464 ?        SN   14:39   0:00  |   _ /usr/bin/php-cgi -c /var/www/vhosts/system/

Plesk server using resources – process is pigz. This is a process used like gzip or zip and is part of the backup process.

Compression with pigz

Panel now uses the pigz library instead of gzip to compress backup data. This ensures better CPU utilization and speeds up the compression 3.5 times on a physical server and 1.2 times on a virtual server (depending on the disk I/O).

See more:

Duplicated Data Removed

Duplicated data is removed from server.xml: Now top-level XML nodes do not contain information about child nodes.

Connection Speed

Now you can see the estimated connection speed between the source and destination servers during data transfer.

Storing Backup Files

You can set the path for storing a temporary backup file, which is created when a customer downloads a backup from the server.

Fastcgi Error

[stextbox id=”warning”]Connection reset by peer: mod_fcgid: error reading data from FastCGI server[/stextbox]

Connection reset by peer: mod_fcgid: error reading data from FastCGI server
[Thu Jul 31 13:05:21 2014] [error] [client] Premature end of script headers: cron.php

Edit fastcgi.conf and add the following:

nano /etc/nginx/fastcgi.conf
FcgidBusyTimeout 3600

PHP Spam Scripts

PHP Spam Scripts

I finally decided this topic deserves its own page.
To find the script sending spam

Ver -11.0

cat /var/www/vhosts/ | grep POST > /tmp/post.log

Ver 11.5+

cat /var/www/vhosts/system/ | grep POST > /tmp/post.log

WHM cPanel

cat /usr/local/apache/domlogs/ | grep POST > /tmp/post.log

View the results

cat /etm/post.log - - [02/Jan/2014:10:51:41 -0500] "POST /tmp/sys09725841.php HTTP/1.1" 200 181 "-" "-" - - [02/Jan/2014:10:52:54 -0500] "POST /tmp/sys09725841.php HTTP/1.1" 200 181 "-" "-" - - [02/Jan/2014:10:54:13 -0500] "POST /tmp/sys09725841.php HTTP/1.1" 200 181 "-" "-" - - [02/Jan/2014:10:55:18 -0500] "POST /tmp/sys09725841.php HTTP/1.1" 200 181 "-" "-" - - [02/Jan/2014:10:56:32 -0500] "POST /tmp/sys09725841.php HTTP/1.1" 200 181 "-" "-"


This file often appears in /tmp/sysNNNNNNNN.php file
1. /tmp is 777
2. the sysNNNNNNNN.php is usually accompanied by a .zip file
3. .php and .zip are owned by apache

Zero Out Log File

> logfile


cat /dev/null > logfile

if you want to be more eloquent, will empty logfile (actually they will truncate it to zero size).

You can also use

truncate logfile --size 0

to be perfectly explicit or, if you don’t want to,

rm logfile

(applications usually do recreate a logfile if it doesn’t exist already).

However, since logfiles are usually useful, you might want to compress and save a copy. While you could do that with your own script, it is a good idea to at least try using an existing working solution, in this case logrotate, which can do exactly that and is reasonably configurable.

Optimize only fragmented tables in MySQL

When you are using MySQL, you will (likely) have tables that can be fragmented. In MySQL terms this is called “OPTIMIZE”.

You could simply OPTIMIZE every table in every database, but during an OPTIMIZE, the tables are locked, so writing is not possible.

To minimize the time that MySQL will be locked (and results cannot be written), here is a script that checks fragmentation of every table of every database. Only if a table is fragmented, the table is OPTIMIZED.


echo -n "MySQL username: " ; read username
echo -n "MySQL password: " ; stty -echo ; read password ; stty echo ; echo

mysql -u $username -p"$password" -NBe "SHOW DATABASES;" | grep -v 'lost+found' | while read database ; do
mysql -u $username -p"$password" -NBe "SHOW TABLE STATUS;" $database | while read name engine version rowformat rows avgrowlength datalength maxdatalength indexlength datafree autoincrement createtime updatetime checktime collation checksum createoptions comment ; do
  if [ "$datafree" -gt 0 ] ; then
   fragmentation=$(($datafree * 100 / $datalength))
   echo "$database.$name is $fragmentation% fragmented."
   mysql -u "$username" -p"$password" -NBe "OPTIMIZE TABLE $name;" "$database"

Another one:


# --- Variabls


        echo "$TABLE_SCHEMA.$TABLE_NAME is $PRC% fragmented and has $TABLE_ROWS rows."

Mysql Report

Another tool of a similar nature is the MySQLReport tool which can be found at

Information can be found here about how to read and analyse the report that is produces from this link

You can load it up remotely and build it on your server in a similar way making use of an HTTP tool like CURL or WGET etc:


–2011-11-13 02:58:47–
Connecting to||:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 38873 (38K) [application/x-perl]
Saving to: `mysqlreport’

100%[======================================>] 38,873 –.-K/s in 0.1s

2011-11-13 02:58:47 (254 KB/s) – `mysqlreport’ saved [38873/38873]

Once loaded give the newly installed file execute permission with the following command

chmod +x

You then call it by passing through the details of the system you want to analyse e.g:

mysqlreport --user root --host localhost --password mypsw100