How to Upgrade PHP – cPanel

Whether you compiled manually or with EasyApache, running a PHP upgrade from a previous version is super easy but also one of the most common questions I get. There are 3 likely assumptions about your current environment (specific to Linux servers, sorry Windows users):

1. You are running a cPanel server and have PHP compiled by EasyApache

2. You compiled PHP manually from source

3. You used Yum, Aptitude, or another package manager

EasyApache

Perhaps the easiest (but least efficient time-wise), simply log into WebHost Manager > Apache Update and select “Previously Saved Config” option and “Start Customizing Based on Profile“. The next screen should take you to the Apache version, which you can keep the same or upgrade as well. Then you’ll be taken to select either PHP 4 or PHP 5, proceeded by the actual version you wish to run and then the options for both Apache and PHP on the next two steps (Advanced Configuration). You usually do not need to change the options if your target is just a simple upgrade within the same version family, but if you changed the Apache version, updated cPanel recently, or are upgrading to a different PHP version family (like 4.4.7 to 5.2.x), then you’ll want to double-check the Apache/PHP build options to make sure they are what they need to be before selecting “Save and Build.” If you are running older versions of EasyApache (usually with cPanel 10 or early versions of cPanel 11 STABLE) then all you have to do is select ‘Load Previous Config‘, pick your PHP version, and ‘Build‘.

Source

If you’ve compiled PHP from source (./configure && make && make install method), you can use your previous configure arguments to compile against a different version. Refer to your server’s phpinfo file (if you don’t have one just create a PHP script with <?php phpinfo(); ?>) and copy the entire ./configure statement into notepad and remove the single quotes. Once you’ve done this, download the source tarball of the new PHP version, untar, and then enter the installation directory. From there, all you have to do is paste the configure statement from notepad. For instance, for PHP 5.2.5:

wget http://www.php.net/get/php-5.2.5.tar.gz/from/this/mirror

tar -xvzf php-5.2.5.tar.gz

cd php 5.2.5

./configure –options-from-your-phpinfo

After the configuration is complete, the script may indicate at the end of its output that you’ve specified configuration options that do not exist. This usually will not affect your build, but you’ll want to review them and consult the PHP documentation on the correct syntax or alternatives to the invalid build options, as these can change depending on which version of PHP you are installing. Doing a ./configure –help will also display the valid options you can use.

Once you have a good configuration, you can go ahead with the make and make install to install the new version of PHP. If you have PHP integrated with Apache (usually you would unless you compiled as CGI) then the installation should have already updated the PHP binary for Apache and module loader in httpd.conf. However, you may need to manually comment out old module loaders if there are conflicts. You’re looking for something like this:

LoadModule php5_module        modules/libphp5.so

Package Installation

Some people have PHP installed via package manager, like Yum or Aptitude. Since the package software usually handles all aspects of the configuration and installation (outside of modules you may have installed via PEAR or Pecl), then you can use its update function to take care of the upgrade as well. Most have a specific option for upgrades, for instance Yum uses:

yum update php

For more information, see NixCraft’s article on PHP installations with Yum.

Fixing Common Perl Issues – cPanel

Sometimes you’ll notice that a certain function of cPanel or WHM was working fine, now all of a sudden you’re getting results that you’ve never seen before. Believe it or not, many problems with cPanel functionality related to processes running off of scripts is because of a perl corruption. To resolve this, usually the first step you should take is running a cPanel update, as this will correct most issues. If the problem persists, you may need to recompile perl from it’s core.

Before we start, here are a few of the most common indicators that there is a perl issue on your server:

  • Accounts are not created properly, like missing files
  • Frontpage extensions refuse to be installed
  • Stats won’t run, result in cryptic perl errors
  • Error messages that look like this:
(internal death) Sat Jun 3 21:01:55 2006 [32719] error: List::Util object version 1.14 does not match
 bootstrap parameter 1.18 at /usr/lib/perl5/5.8.7/i686-linux/XSLoader.pm line 92.
==> Starting cpbandwd (bandwidth monitoring for IMAP/POP)
Can't locate Class/Std.pm in @INC (@INC contains: /usr/local/cpanel /usr/lib/perl5/5.8.7/i686-linux
/usr/lib/perl5/5.8.7
BEGIN failed--compilation aborted at /usr/lib/perl5/site_perl/5.8.7/Unix/PID.pm line 8.
Compilation failed in require at /usr/local/cpanel/bin/cpbandwd line 15.
BEGIN failed--compilation aborted at /usr/local/cpanel/bin/cpbandwd line 15.

In some cases, the error is specific about a perl module missing. If this is the case, look for the perlmod format in the error message. In the above example you can see ‘List::Util’ being referenced, so you can try to reinstall that either manually or from WHM:

/scripts/perlinstaller –force List::Util

If reinstalling the perl module itself does not solve the problem, you can recompile perl. First, do a perl -v from command line to see what version you are running. Then follow these steps:

wget http://layer1.cpanel.net/perl587installer.tar.gz
tar xvzf perl587installer.tar.gz
cd perl587installer
./install

/usr/local/cpanel/bin/checkperlmodules

If you are running 5.8.8, use the installer from:

http://layer1.cpanel.net/perl588installer.tar.gz

The recompile may take as long as 20 minutes to complete.

Downgrading MySQL to 4.x – cPanel

If you’ve upgraded MySQL via WebHost manager, the downgrade process is slightly more complex than the upgrade. This tutorial mainly covers a downgrade from 4.1 to 4.0, but also applies to downgrading from 5.x to 4.x.

*Back up all databases before proceeding, as all existing databases will be deleted!

1. Uninstall existing MySQL packages:

rpm -qa | grep -i mysql-

This should return a list of several rpm’s installed. You will need to remove them all with the rpm -e command .

2. Delete the active MySQL directory:

rm -Rfv /var/lib/mysql

3. Get cPanel Ready

Edit /var/cpanel/cpanel.config and change the version to the one that you are downgrading to (4.0, 4.1, etc)

mysql-version=4.0

Make sure that MySQL updates aren’t being skipped:

rm /etc/mysqldisable
rm /etc/mysqlupdisable

4. Install MySQL:

/scripts/mysqlup –force

5. Update the perl module:

/scripts/perlinstaller –force Bundle::DBD::mysql

Finally, recompile Apache and PHP via Web Host Manager.

Disabling SMTP Tweak – cPanel

The SMTP tweak will prevent users from bypassing the mail server to send mail (this is a common practice used by spammers). It will only allow the MTA (mail transport agent), mailman, and root to connect to remote SMTP servers.  In order words, users will need to use ‘localhost’ as their SMTP server for local mailing scripts to sent mail (source).  SMTP Tweak can be enabled or disabled in the ‘Security Center’ of WHM, or from command line using:

/scripts/smtpmailgidonly on|off

Upgrading phpMyAdmin – cPanel

The phpMyAdmin version is usually automatically upgraded when you run a cPanel update to a newer version. However, if you’re not quite ready to upgrade cPanel, you easily install a newer version of phpMyAdmin. Please be aware that future cPanel updates will overwrite your manual installation.

You will need to go to the phpMyAdmin download page and pick your version. This tutorial is specific to version 2.11, but should work for any:

cd /usr/local/cpanel/base/3rdparty
mv phpMyAdmin hold_phpmyadmin

wget http://prdownloads.sourceforge.net/phpmyadmin/phpMyAdmin-2.11.2.2-english.tar.gz?download

tar -xvzf phpMyAdmin-2.11.2.2-english.tar.gz
mv phpMyAdmin-2.11.2.2-english phpMyAdmin
cp hold_phpmyadmin/config.inc.php phpMyAdmin/
chown -R cpanel:cpanel phpMyAdmin

Then load up phpMyAdmin from cPanel or WHM and you should see the new version

Installing PostgreSQL – cPanel

Run the install script from command line

/scripts/installpostgres

Now in WHM under SQL Services locate Postgres Config and do an Install Config. You can also set the root password from here, but this password should only be alphanumeric.
PostgreSQL is installed now, but PHP is not compiled for it, so you’ll need to recompile PHP/Apache with postgreSQL support. You can do this manually, or through WHM. If doing so manually, here is the configure switch:

–with-pgsql=/usr

In your feature manager in cPanel, check the boxes for PostgreSQL and phpPgAdmin to enable them in your users’ cPanels.

ow when you log into cPanel you’ll see a section for PostgreSQL and phpPgAdmin which is the database management tool for Postgres.

Incorrect Disk Usage and Unlimited Quotas – cPanel

This is a common bug on cPanel 11 systems, where you do an account listing through Webhost manager or try to set a user’s quota and everyone is showing as using 0mb out of unlimited.  The most common fix for this is to run:

/scripts/fixquotas

This will re-initialize the quota system and usually fix the error.

On VPS servers running Virtuozzo, a kernel bug in earlier versions of CentOS and Redhat have been attributed to this error (and similar errors) as well.

Users Can’t Change Password – cPanel

When trying to change their password in cPanel, users get the following error:

There was an error manipulating the password file.
This generally means you entered your old password incorrectly.

This has been seen on CentOS and Redhat servers running cPanel 11. The known fix is to run:

chmod +s /usr/bin/passwd

Wrong Version Numbers in cPanel

It’s common that when moving a cPanel account between servers with differing software versions, the version numbers (specifically MySQL) on the side of cPanel still reflect those of the old server. This can be changed by editing the version files for the account that was moved:

The files holding the version numbers are located in:

cpanel 10: /home/username/.cpanel-datastore/

cpanel 11: /home/username/.cpanel/datastore/

The following files control the version display in user cPanels:

Apache Version:

_usr_local_apache_bin_httpd_-v

Perl Version:

_usr_bin_perl_-v

MySQL Version:

_usr_sbin_mysqld_–version