Premature end of script headers

Timeout received during file upload/downloads using Plesk 11

During extended uploads or download you are getting an Internal Server Error, the error_log looks like this:

[Mon Mar 04 08:12:58 2013] [error] [client 19.149.54.29] Premature end of script headers: index.php, referer: http://www.site.co.uk

If you are running PHP as FastCGI you may want to look at the parameters in this file:

# vi /etc/httpd/conf.d/fcgid.conf

FcgidIdleTimeout 30
FcgidProcessLifeTime 30
FcgidMaxProcesses 20
FcgidMaxProcessesPerClass 8
FcgidMinProcessesPerClass 0
FcgidConnectTimeout 30
# FcgidIOTimeout 45
FcgidIOTimeout 240

Usually a tweak of the FcgidIOTimeout resolved the problem.

Don’t forget to restart Apache afterwards.

How to delete files older than a specific number of minutes

Re: Use BASH to delete files older than so many minutes

When working with temporary files it is often good housekeeping to clear (delete) files older than a specific number of minutes. Use the following in bash command to achieve this goal:

# find /tmp/file* -type f -mmin +65 -delete

The above command will delete all files older than 65 minutes. Modify as appropriate.

How to Install ImageMagick on Plesk

Re: ImageMagick on a Plesk Server

ImageMagick is not installed on your Plesk server by default. However, the installation is quite simple using the yum repositories and packages.

# yum install gcc
# yum install ImageMagick
# yum install ImageMagick-devel
# yum install php-pear
# yum install php-devel
# pecl install imagick
# echo "extension=imagick.so" > /etc/php.d/imagick.ini
# service httpd restart

To test it is working, try the following:

# php -i | grep imagick
imagick
imagick module => enabled
imagick module version => 3.0.1
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator
imagick.locale_fix => 0 => 0
imagick.progress_monitor => 0 => 0

This output confirms that the imagick.so module is operating and active. That completes this ImageMagick installation tutorial, we hope you found it useful.

How to show total number of files in folders

Re: Display folder list with numbers of files in each folder and it’s sub folders

If you need to find where you may have large numbers of files stored it is useful to display a list of folders together with how many files are contained within that folder and its subfolders. This enables you to drill down to the area where the most files are stored.

# du -a | cut -d/ -f2 | sort | uniq -c | sort -nr

As an example, I will run this command in my /httpdocs folder, here is the output:

1959 wp-content
424 wp-includes
333 wp-admin
30 img
28 test
22 var

This immediately informs me where the most files are stored and that I have 1,959 files within my wp-content folder and it’s sub folders.

To get the disk usage of these folders instead, do this:

# du -h --max-depth=1

The output is as follows:

98M ./wp-content
4.0K ./plesk-stat
4.0K ./picture_library
20K ./css
128K ./test
5.7M ./wp-includes
3.8M ./wp-admin
8.0K ./blogs
144K ./img
4.0K ./tmp
124K ./var
108M .

These are useful tools when investigating disk space usage problems.

How to list folders with disk usage totals

Re: Show Folders with total disk space used

When finding out where your web space is being used it is useful to be able to list your directories and folders showing total usage for each folder, this allows you to further drill down by concentrating on folders that contain the most usage.

You can perform this task using the du (disk usage) utility:

# du -h --max-depth=1

The output will be in the format as follows:

98M ./wp-content
4.0K ./plesk-stat
4.0K ./picture_library
20K ./css
128K ./test
5.7M ./wp-includes
3.8M ./wp-admin
8.0K ./blogs
144K ./img
4.0K ./tmp
124K ./var
108M .

The -h option shows the usage in human readable form. The –max-depth option ensures we summarise folders in the current directory and not the individual sizes of sub folders.