PHP: Fatal error: Allowed memory size of xx bytes exhausted (tried to allocate xx bytes)

When you see the following error message it means that the PHP script is exceeding the memory limit which is set for PHP.

Fatal error: Allowed memory size of xx bytes exhausted (tried to allocate xx bytes) in /path/to/script.php

To change the memory limit for one specific script, add the following line at the top of the script:

ini_set(“memory_limit”,”64M”);

You can also change the memory limit server-wide for all scripts.

1. Locate the PHP configuration file

# php -i | grep ini
Configuration File (php.ini) Path => /usr/local/lib
Loaded Configuration File => /usr/local/lib/php.ini
Scan this dir for additional .ini files => (none)
additional .ini files parsed => (none)

As you see the php.ini is being used which is in /usr/local/lib

2. Open the configuration file

# nano -w /usr/local/lib/php.ini

3. Search for memory_limit and raise the limit, it should look like:

memory_limit = 64M

4. Save and exit.

5. Restart Apache

# /etc/init.d/apache2 restart
or
# /etc/init.d/httpd restart

Monitoring server load on Linux

I wrote a simple bash script to monitor the server load, once the server load reaches the threshold it will send out an e-mail.

Once you have received an e-mail from this monitoring script, you have to reset the $fileCHECK file to ‘0’:

# echo ‘0’ >  $fileCHECK

# In this example script it should be:
# echo ‘0’ > /root/monitor/values/load

The script is very basic and simple, I will keep this script updated if necessary.

Script:

#!/bin/bash

fileCHECK=’/root/monitor/values/load’
fileVALUE=`/bin/cat $fileCHECK`

# On what load average an e-mail should be sent
# Example: 5
topTHRESHOLD=’1′

# Grep load average from /proc/loadavg
loadAVERAGE=`cat /proc/loadavg | /usr/bin/cut -d ” ” -f 1 | /usr/bin/cut -d “.” -f 1`

if [ “$fileVALUE” -eq “0” ]
then
        # No e-mail or SMS has been sent yet
        # Now check if average is above threshold
        if (( “$loadAVERAGE” >= “$topTHRESHOLD” ))
        then
                # Load average is higher than $topTHRESHOLD
                # We should send an alert
                /bin/echo echo “Load averag abose threshold: $loadAVERAGE” | /usr/bin/mail -s “Load average above threshold” “info@how2forge.info”
                /bin/echo ‘1’ > $fileCHECK
        else
                # Load average is lower
                # Load is OK, do nothing
                exit
        fi
else
        # E-mail has already been sent, do nothing
        exit
fi

WARNING: mismatch_cnt is not 0 on /dev/md1

Since a couple of days I have seen the following message on (CentOS) servers:

WARNING: mismatch_cnt is not 0 on /dev/md1

I have Googled some around, posted on forums, but couldn’t find the cause of this.
Anyways, I managed to fix it with a workaround:

# echo repair >/sys/block/md1/md/sync_action
# wait a bit ….
# echo check >/sys/block/md1/md/sync_action 

Should be fixed now!

If you know what it exactly means and what the reason is, let me know please!

Difficulties with setting up your network in Ubuntu

Today I had some problems with setting up the network in Ubuntu.

Restarting the network resulted in the following error message:

# /etc/init.d/networking restart
* Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces
* Reconfiguring network interfaces…
/etc/network/if-up.d/upstart: 43: cannot create /run/network/ifup.eth0: Directory nonexistent
run-parts: /etc/network/if-up.d/upstart exited with return code 2

I have a workaround for this:

# cd /run
# ln -s /var/run/network network

Restart your network and you will see that the error message is disappeared.

MegaCli for Debian / Ubuntu

Unfortunately LSI and Dell doesn’t provide the MegaCli tool as source or .deb package, therefor it is not possible (by default) to install MegaCli on Debian servers.

I managed to get MegaCli working on a Debian server.

Download MegaCli from LSI:

# cd ~
# wget “http://www.lsi.com/downloads/Public/MegaRAID%20Common%20Files/8.00.46_Linux_MegaCLI.zip”

Unpack the downloaded file:

# unzip 8.00.46_Linux_MegaCLI.zip

if unzip is not installed, please install:
# apt-get install unzip

There is a .zip file in this .zip file (logical?), unzip again:

# unzip MegaCliLin.zip

This will extract a .rpm package, on Debian servers it is not possible to install this package, but using rpm2cpio it is possible to extract it:

# rpm2cpio MegaCli-8.00.46-1.i386.rpm | cpio -idmv

if rpm2cpio is not found, please install:
# apt-get install rpm2cpio

Now MegaCli and MegaCli64 are extracted, run:

# ./opt/MegaRAID/MegaCli/MegaCli -AdpAllInfo -aALL
# ./opt/MegaRAID/MegaCli/MegaCli64 -AdpAllInfo -aALL

hdparm: HDIO_DRIVE_CMD(null) (wait for flush complete) failed: Inappropriate ioctl for device

I just wanted to benchmark the read speed of the hard drives in my server using hdparm, but got the following warning message:

HDIO_DRIVE_CMD(null) (wait for flush complete) failed: Inappropriate ioctl for device

I have fixed this by updating hdparm to its newest version:

Download, untar and install hdparm:

# wget “http://downloads.sourceforge.net/project/hdparm/hdparm/hdparm-9.37.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fhdparm%2F&ts=1318527426&use_mirror=sunet” -O hdparm.tgz
# tar zxvf hdparm.tgz
# cd hdparm-9.37/
# make
# make install
# hdparm -V
hdparm v9.37

Re-run hdparm and you will see that the warning message is not there anymore.

cPanel: Service status showing down while it is up and running

I just worked on a CentOS server with cPanel/WHM. The problem was that Service Status was showing the status for some services (httpd, ftpd, exim, imap) as down while they were up and running. It took me some hours to find the cause of this, but at the end I found the cause.

The problem was that ‘lo’ was not active, I have activated it by running:

# ifup lo

After ‘lo’ was activated I had to restart cPanel:

# service cpanel restart

All services were showing up after the restart, but imap was still shown as down. I quickly solved this by regenerating the ‘check script’ for imap:

# rm -rf /etc/chkserv.d/imap

Then go to Service Manager via cPanel, enable imap (if it is not) and press Save.

Good luck!

Howto: RAID status on HP servers

Here is how you can view the status of your RAID configuration and the status of your physical drives.
First we have to download and install the hpacucli tool.

CentOS:

# wget http://how2forge.info/files/hpacucli-8.60-8.0.noarch.rpm
# rpm -ivh hpacucli-8.60-8.0.noarch.rpm

Debian:

# wget http://how2forge.info/files/hpacucli_8.60-8.0_i386.deb
# dpkg -i hpacucli_8.60-8.0_i386.deb

Once the tool is installed, start it:

# hpacucli
HP Array Configuration Utility CLI 8.60-8.0
Detecting Controllers…Done.
Type “help” for a list of supported commands.
Type “exit” to close the console.

=>

Now we are in the CLI mode of the RAID controller.
We have to find out on which slot the RAID controller is connected to, in this case it is connected on slot 2:

=> ctrl all show

Smart Array P410 in Slot 2                (sn: PACCRID11081R39)

As we know that the RAID controller is connected on slot 2, we can continue.
To view/check the status of your RAID array, use the following command:

=> ctrl slot=2 ld all show

Smart Array P410 in Slot 2

   array A

      logicaldrive 1 (558.7 GB, RAID 1+0, OK)

It seems that the logicaldrive/RAID array is OK, but we also want to check the physical drives:

=> ctrl slot=2 pd all show

Smart Array P410 in Slot 2

   array A

      physicaldrive 1I:1:1 (port 1I:box 1:bay 1, SAS, 300 GB, OK)
      physicaldrive 1I:1:2 (port 1I:box 1:bay 2, SAS, 300 GB, OK)
      physicaldrive 1I:1:3 (port 1I:box 1:bay 3, SAS, 300 GB, OK)
      physicaldrive 1I:1:4 (port 1I:box 1:bay 4, SAS, 300 GB, OK)

Should you have any further questions regarding hpacucli, just let me know by sending an e-mail.

Plesk: After upgrade to Plesk 10, www prefix is not working anymore

Since Plesk 10.x the domain-handling is changed, if your Apache configuration is not configured correctly the default plesk page will be shown when you browse to your domain with the www prefix.

The resolution for this problem is that you have to add a CNAME record and reconfigure the Apache configuration for your domain(s). I will use domain ‘how2forge.info’ as example.

1. Add the correct CNAME record

1a. Login to Plesk Control Panel as user, not as admin.
1b. Go to Websites & Domains.
1c. Click on DNS Settings.
1d. Click on Add Record.

Record type: CNAME
Domain name: www.how2forge.info.
Canonical name: how2forge.info.

Click on OK to save the record.

Now you have to log in via SSH on to your server and reconfigure the Apache configuration for your domain:

# /usr/local/psa/admin/sbin/httpdmng –reconfigure-domain how2forge.info
(please note the double ‘-‘ before reconfigure-domain, wordpress is removing the double dashes)

Done! Your website should now be accessible with the www prefix.

If this have not solved the problem, probably you still have an A record for www.how2forge.info. Remove the A record and it should work.

Good luck!

Plesk: How to switch from Qmail to Postfix and vice versa

There are two MTA that are supported by Plesk since version 9:
– Qmail
– Postfix

You can change the MTA using the autoinstaller script of Plesk:

# /usr/local/psa/bin/autoinstaller

On the 4th page select the currently installed Plesk version. Disable all other applications.
On the Main components list page select the MTA you want to use and click enter to complete the installation.

It is also possible to change the MTA without running the autoinstaller interface:
To switch from Qmail to Postfix:

# /usr/local/psa/admin/sbin/autoinstaller –select-release-current –install-component postfix

To switch from Postfix to Qmail:

# /usr/local/psa/admin/sbin/autoinstaller –select-release-current –install-component qmail

Ads

Ads