php-cgi does not give proper 404 errors

When using php-cgi via .htaccess you will find that missing files give “No input file specified” instead of a proper 404 error.

To fix this, add :


RewriteEngine On
RewriteRule ^.+\.php$ /file_name_that_does_not_exist

to your .htaccess

replace “file_name_that_does_not_exist” with any file name that does not exist – ie. something that will trigger a 404 error.



Switching to php 5.4 causing my site to crash

With versions 5.4 and onward, certain php.ini directives can cause your site to no longer load.

Make sure all references to the following are removed from your php.ini:


You can place a semi-colon in front of those lines to preserve the old values in case you need them for future reference.


Enabling apc (php alternative cache) on your Centos VPS

Here is how to enabled php’s apc on a CentOS VPS:

1. yum -y install php-pear pcre-devel php-pear php-devel httpd-devel gcc
2. pecl install apc (press enter to accept the default response for each option)
3. echo “” > /etc/php.d/apc.ini
4. service httpd restart
5. cp /usr/share/pear/apc.php /home/YOUR_USER_NAME/www/some_private_file_name.php

The apc.php page can be loaded to view the cache status. We recommend you rename it to something other than apc.php

Send mail using Pear:Mail

How can I send mail from php using a specific smtp host, for example, or my private smtp server?

Use the pear mail package.


$from = ““;
$to = ““;
$subject = “Test”;
$body = “Test”;

$host = “”; // enter the smtp server you wish to use here
$port = “25”; // smtp port
$username = “”; // your smtp-auth username
$password = “your_password”; // your smtp-auth password

$headers = array (‘From’ => $from,
‘To’ => $to,
‘Subject’ => $subject);
$smtp = Mail::factory(‘smtp’,
array (‘host’ => $host,
‘port’ => $port,
‘auth’ => true,
‘username’ => $username,
‘password’ => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {

” . $mail->getMessage() . “

} else {

Message successfully sent!


Hide eregi() deprecated errors


My script gives errors like:

Deprecated: Function eregi() is deprecated in /home/my_username/www/path/contact/include/fgcontactform.php on line 548

Why is this occuring? How can I fix it?


Newer php versions are removing support for the eregi() function. Your script will continue to work but using normal php.ini settings the deprecated errors are shown. You can hide the errors by adding:

error_reporting = E_ALL & ~E_DEPRECATED

to your /home/username/etc/php.ini file

Create the file if it does not exist. If you already have a error_reporting line, modify it hide E_DEPRECATED

If you are on a VPS, edit /etc/php.ini and restart httpd if you are running mod_php.

You should also work to update your script to no longer call the deprecated functions as future versions of php will remove support for the functions completely.

How do I upgrade php on a VPS?


The php version on my VPS is out of date. How do I update it?


Using the OS vendors normal update command can get you some updates (but perhaps not what you want – see below). For example on RedHat/CentOS run:

yum update php

However usually the OS vendors versions are not the latest. The update them to patch security issues but many times are far out of date from what you may require.

To update RedHat/CentOS to a newer php run these commands:

yum erase php-pdo php-xml php-mysql php php-common php-cli php-gd php-mbstring php-devel

yum install php53-pdo php53-xml php53-mysql php53 php53-common php53-cli php53-gd php53-mbstring

/sbin/service httpd restart

A note:

These are “unofficial” RPM’s as RedHat only official supports a particular (semi-old) version and backports security fixes to it – good for large corporate users but not so great for active developers). However the RPMS’s above are widely used in the community and most developers view them as trustworthy (just important to note that they are not actually from RedHat).

Converting from mod_php to php-cgi : Steps to take for a seemless upgrade


I’d like to change from mod_php to php-cgi. What steps should I take to make sure the change is smooth?


Most conversions are as simple as selecting the new version to use in the control panel. If a small amount of possible downtime on your site is acceptable you may want to just try the change and see. In the worst case, you’ll have to wait as long as 15 minutes to switch back to the old version.

The server looks for changes and reloads (if needed) your php configuration every 15 minutes. If you make the change and find you site has problems, you’ll need to “undo” the change by selecting the version you were running previously. You’ll then need to wait for the server to reload your config. Note: During this time your site still runs – there is no downtime – but it does not run the new php version.

If you want near-zero probability of problems (or if you tried the approach above and ran it problems), we recommend the following:

1. Make sure there are no files owned by the generic server user “nobody”. Do this:

find /home/your_user_name_here -user nobody -print

If it shows files owned by nobody, you’ll need to put in a support request for an admin to change the ownership back to your own username.

2. Use the php.ini file that your site was running under before :

mkdir /home/your_username_here/etc/
cp /usr/local/lib/php.ini /home/your_username_here/etc/

4. Make sure date.timezone is set in php.ini. A common problem ugprading to php5.3 is not having date.timezone set. It needs to be set either in your code or (easier) in php.ini

An example for EST timezone is :

date.timezone = 'America/New_York'

5. Check the changelog documentation for any functions that have been removed or changed between the version you are currently running and the version you are upgrading to.

PHPMailer will not send out mail. I get an error with PHPMailer.


Using PHPMailer, I get errors when sending out mail. Any ideas?


If you have code like :



$mail->Host = "localhost";

in your code. Change it to:


The IsSMTP() call tells PHPMailer to send via your local SMTP server. However in most cases this will not work with-out authenticating yourself. You can use PHPMailer to also do an auth but if you are sending to an SMTP server on the local server (ie. “localhost”) – it is much better to do this via sendmail directly. The call to :


tells PHPMailer to do this.

Why does my website run an old version of php?

Change php version control panel screenshot


I noticed my website is not running the latest version of php. Why not?


You can change your php version at any time by going to the php section of your control panel. Normally, we do not update your php version (other than for security patches) automatically in case your scripts rely a certain version being used. We do force minor revision upgrades that address security issues, etc.

In the past we kept all users up-to-date on the latest php versions but found that in many instances the major updates (from 4 to 5, 5.1 to 5.2 to 5.3, etc.) would break client sites. It was rare but happened enough for us to change our policy.

To summarize:

  • You can change your php version in the “php” section of the control panel
  • We perform security related upgrades automatically
  • Major version upgrades are not performed automatically. Instead, use the (one click) version update selector in the control panel

Fixing silverstripe warnings during install

Silverstripe magic_quotes asp_tags warnings screenshot


I get warnings about asp_tags and magic_quotes during my install of silverstripe.


You need to edit your php.ini and set the asp_tags and magic_quotes options to off.

However be aware that there is the potential to break your other scripts if your scripts depend on those options. You should change them and then test your other scripts. If anything breaks, you’ll need to leave them set to on or set up a separate php configuration for each part of your site.

Best regards,