Archive for 'Web Hosting'

Installing APC Opcode cache

Today while trying to install the APC Opcode cache on my WiredTree account, I encountered the error “Cannot run code from this file in conjunction with non encoded files in…”  As it turns out, the APC Opcode cache has an incompatibility with Zend Optimizer.  The solution was to disable the Zend Optimizer (Which wasn’t really optimizing anything to begin with).  Just open your php.ini file and comment out the lines that look like the following:

zend_extension_manager.optimizer=/usr/local/Zend/lib/Optimizer-3.3.3
zend_extension_manager.optimizer_ts=/usr/local/Zend/lib/Optimizer_TS-3.3.3
zend_optimizer.version=3.3.3
zend_extension=/usr/local/Zend/lib/ZendExtensionManager.so
zend_extension_ts=/usr/local/Zend/lib/ZendExtensionManager_TS.so

Fixing 500 Errors on Media Temple DV 3.5 Running FastCGI

I’ve gotten a lot of questions about 500 errors on Media Temple. I’m currently running a Media Temple DV 3.5 Extreme server with Magento. It’s been quite a process getting things tuned up, but I’ve got the performance to an acceptable level now. See for yourself… http://www.bcsports.com/. When I first switched to the FastCGI version of PHP, there were a few issues to deal with, the most important were the sporadic 500 errors that would pop up.

You know, it was odd, I thought I had everything running smoothly, but my client would call me and say “I’m getting a 500 error right now”. I’d hit the server myself and … no problems. Pages loaded fine. So I decided to load test the server with a service that hits the server from many locations around the world. Whamo… 500 errors popping up. I immediately switched back to mod_php and ran it that way for a while. It was much slower, but more reliable.

So after a while, I realized that I needed the performance of FastCGI to run Magento with a reasonable amount of speed. I spent some additional time looking into the source of the 500 errors, and through some tuning and testing, I believe I’ve got it nailed. It seems that the timeout settings were causing the CGI to die before PHP got a chance to respond. So, without further ado, below is the configuration that cured my server…

1. With your favorite text editor, edit /etc/httpd/conf.d/fcgid.conf to the following:

# added by psa-mod-fcgid-configurator
LoadModule fcgid_module /usr/lib/httpd/modules/mod_fcgid.so

<IfModule mod_fcgid.c>
  SocketPath /var/lib/httpd/fcgid/sock
</IfModule>

# added by psa-mod-fcgid-configurator
<IfModule mod_fcgid.c>
IdleTimeout 300
ProcessLifeTime 10000
MaxProcessCount 64
DefaultMaxClassProcessCount 15
IPCConnectTimeout 600
IPCCommTimeout 600
</IfModule>

2. Restart apache by running “/etc/init.d/httpd restart”

Run PHP as a FastCGI on a MediaTemple DV 3.5 Server

If you found this article, you probably have a reason to want to move away from mod_php.  Mine was because I was trying to operate a Magento install on a MediaTemple DV 3.5 server with periodic problems and outages.  The symptoms were that the site would slow down tremendously, to the point that requests would just hang… no response from the server.  Eventually, I was able to look at server resources in the Plesk interface and this is what I saw:

load_average_100

The CPU usage was through the roof.  And it stayed there too.  In case you’re not familiar with Plesk, you can find the CPU usage by logging into Plesk, then going to Virtuozzo >> Resources.  So I performed various upgrades to the server to try and get this system under control.  First, I installed APC (Alternative PHP Cache) which is a handy little program that caches the compiled PHP opcode to save the computer some processor cycles.  That helped a bit, but still didn’t solve the periodic problem of server slowdowns.  I decided to install php as a FastCGI to free up some resources.  Doing so on Media Temple was not as easy as I’d have liked, and the lack of documentation made it a bit of a challenge.  Here are the steps I took:

  1. You must enable root access on your Media Temple DV account.  This is required, since some of the files you’ll be creating need to go into directories where only root is allowed. Media Temple has a knowledgebase article on the subject.  Basically you click a button on your Media Temple Account Center page.
  2. Enable CGI and FastCGI on the domain where this will be applied.  Here’s how: 1. Log into Plesk  2. Click on Domains on the left side   3. Click the blue VR icon next to your domain   4. Under services check the boxes next to CGI support and FastCGI support  5. Click the OK button at the bottom
  3. Now your domain is ready to run FastCGI.  Log into your server via SSH as root.
  4. Run the commands below (without the quotes.  replace yourdomain.com with your actual domain name)
  5. “cd /var/www/vhosts/yourdomain.com/”
  6. “cp /usr/bin/php-cgi bin/”
  7. “chown -R username:psacln bin” (replace username with your FTP login name for this domain)
  8. “vi conf/vhost.conf”  (using vi or your favorite editor, create this file)
    AddHandler fcgid-script .php

    FCGIWrapper /var/www/vhosts/yourdomain.com/bin/php-cgi .php
    Options ExecCGI
    allow from all
  9. Save the file, then if you’re using SSL on this server, run this command: “cp conf/vhost.conf conf/vhost_ssl.conf”
  10. Now, restart the server: “/etc/init.d/httpd restart”
  11. If you want to see if it really worked, you can create a php page on your server with the line phpinfo();  Look through the page and you should see “Server API: CGI/FastCGI”  if so, you’re in business.
  12. Good luck.

UPDATE: Due to popular demand, I’ve written an article on how to cure 500 errors using this configuration. Click here to read.

Installing APC on Media Temple DV 3.5 Server

Here are some quick and easy steps to install APC on a Media Temple DV 3.5 Server

A. Install Developer Tools and enable SSH access.

  1. Log into Account Center on Media Temple
  2. Click on the Admin button next to your domain
  3. Click on the “Root Access and Developer Tools” button
  4. Click the enable button next to Root access
  5. Click the install button next to Developer Tools
  6. This process takes 10-15 minutes to complete, so hold your britches

B. Download, compile and install APC.  Log into your system using an SSH client (Like Terminal on a Mac or Putty on a PC), then run the commands below in order.

  1. cd /usr/local/src
  2. wget http://pecl.php.net/get/APC-3.0.19.tgz
  3. tar -xvf APC-3.0.19.tgz
  4. cd APC-3.0.19
  5. phpize
  6. ./configure –enable-apc-mmap –with-apxs –with-php-config=/usr/local/php/bin/php-config –with-php-config=/usr/bin/php-config
  7. make
  8. make install
  9. echo “extension=apc.so” > /etc/php.d/apc.ini
  10. /etc/init.d/httpd restart

C. The last thing you want to do is copy the apc.php file to your web server to see if APC is running properly.  You can do that with the following command.  Make sure you replace the words “yourdomain.com” with your actual domain name for your web site.

  1. cp apc.php /var/www/vhosts/yourdomain.com/httpdocs/

Now go to http://www.yourdomain.com/apc.php and you should see the caching stats there.

Good luck.