Installing Accelerated PHP Cache (APC) on MediaTemple DV 4.0

WordPress Tweaks

I highly recommend using the powerful W3 Total Cache WordPress plugin for enhancing the speed of your WordPress site. Because I’m running on a MediaTemple dedicated virtual (dv) 4.0 server, I wanted to try harnessing the power of APC (Alternative PHP Cache) as an opcode cache to speed things up!

image

To do this, I logged in via SSH and ran this command:

[[email protected] ~]# pecl install apc

Unfortunately, when it tried installing I received the following error:

checking whether the C compiler works... configure: error: cannot run C compiled programs.

I discovered the problem by reading this article. Evidently, the /tmp and /var/tmp folders default to having the “noexec” permission. They will need to have “exec” permission in order to install APC. The solution would be to use the mount command to temporarily assign them the “exec” permission, install APC, and then reassign them back with the safe “noexec” permission. So I ran this command:

[[email protected] ~]# mount -o remount,exec /tmp

However, a new error occurred:

mount: permission denied

I was running as the root user, so this wasn’t the problem. At first I thought this error may have been caused by MediaTemple disallowing the mount command. However, the helpful MediaTemple support agent assured me that this is not the case. He mentioned that the permission error might be cause by the /tmp directory being in used. He pointed me to a helpful article on Noexec and /tmp troubleshooting, which shows a way to get around this by using a chrooted /tmp directory:

[[email protected] ~]# mkdir -p /root/chroot /root/tmp
[[email protected]:~]# mount --bind / /root/chroot
[[email protected]:~]# mount --bind /root/tmp /root/chroot/tmp
[[email protected]:~]# chroot /root/chroot

Success! I was then able to run the “pecl install apc” command without a problem. Type exit to leave the chrooted environment.The final step was installing the APC extension for PHP. The simplest way to do this on MediaTemple was to drop a file named apc.ini into the /etc/php.d directory. It contained one line:

extension = apc.so

Then I restarted Apache and and APC was up and running!

[[email protected] ~]# /etc/init.d/httpd graceful

11 Comments

  1. Drew at (mt) Media Temple

    Thanks for the great article! I’m sure this will prove helpful for a lot of (dv) Dedicated-Virtual Server customers. Let us know if we can ever help you with anything, we’re available 24/7 on Twitter 🙂

    Drew J
    MediaTemple.net
    @MediaTemple

    Reply
  2. Chris

    I am also trying to do this on my Media Temple DV 4. I am getting a command not found error when I try chroot /root/chroot. Why is this happening? Very frustrating when you find what looks like a simple solution and it does not want to work.

    Reply
    • Robert Staddon

      Good question, Chris. I don’t know why you wouldn’t be able to run the “chroot” command. You might get on with MediaTemple tech support. They’re great.

      Reply
  3. davak

    @Robert – Thanks for the article!

    @Chris – I couldn’t run chroot if I elevated access via su; however, if I logged in directly as root it worked fine.

    Reply
  4. Steve

    Nice!
    I’m upgrading to dv (from gs) because of this article!!!

    Reply
  5. Andrei

    Hi and thanks for the great tutorial!
    I have a problem though: I’m getting random blank pages, any way I can debug it?

    Regards,
    Andrei

    Reply
  6. Nick Yeoman

    Took me about 20 minutes to figure out why chroot wasn’t working, it really ticked me off when man chroot worked. but yea as @davak said, just ssh root@yourDV and it will work. I also had a problem with /etc/init.d/httpd graceful it killed my DV and I had to Reboot from the MT admin.

    Next time I’ll use /etc/init.d/httpd restart

    Hope that helps someone out. Thanks for the article it helped me out.

    Reply
  7. Brandon

    I got a totally different error when I ran: pecl install apc

    The error was:

    /usr/bin/phpize: /var/tmp/APC/build/shtool: /bin/sh: bad interpreter: Permission denied
    Cannot find autoconf. Please check your autoconf installation and the
    $PHP_AUTOCONF environment variable. Then, rerun this script.

    ERROR: `phpize’ failed

    ——————–

    Searching “autoconf” on MT’s knowledge base and will let you know what I find out.

    Reply
  8. Robert Staddon

    Thanks for sharing this, Brandon, I’m glad you got it running!

    Reply
  9. Brandon Moeller

    Thank you for this article. It helped me install APC on a VPS with FutureHosting. The chroot saved the day after many hours staring at the blinking command line cursor.

    Reply

Submit a Comment

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.