Install PHP APC on Amazon EC2 Linux AMI or CentOS

Installing PHP APC is usually a two step process as seen in this earlier post using php-pecl-apc, but sometimes we might need to install APC manually. The following steps therefore, outline the procedure for installing APC from the PHP PECL library:

 

1. Install Linux updates, set time zones, followed by GCC and Make

sudo yum -y update
sudo ln -sf /usr/share/zoneinfo/America/Indianapolis \
     /etc/localtime
sudo yum install -y gcc make

 

2. Install PHP and PHP extension to enable PHPIZE

sudo yum install -y php
sudo yum install -y php-devel

 

3. Install PCRE-DEV

Note: This is an important step, and without installing PCRE-DEV, you will see errors related to “apc_regex” during MAKE such as:
error: ‘apc_regex’ has no member named ‘preg’
error: ‘apc_regex’ has no member named ‘nreg’
sudo yum install -y pcre-devel

 

4. Install Apache httpd

sudo yum -y install httpd
sudo service httpd start

 

5. Download Latest APC Version

wget http://pecl.php.net/get/APC
In this particular case, it downloaded APC 3.1.10

 

6. Untar APC, and Compile the Extension

tar -xzf APC
In this particular case, it downloaded APC 3.1.10 so, 
cd APC-3.1.10
phpize

 

7. Configure and Make

./configure --enable-apc --enable-apc-mmap \
   --with-apxs --with-php-config=/usr/bin/php-config
make
make install
In case you do not know the location of your php-config, run the command below:
whereis php-config

 

8. Add APC Extension to PHP

sudo touch /etc/php.d/apc.ini
sudo echo "extension=apc.so" >> /etc/php.d/apc.ini;

 

9. Restart Apache

sudo service httpd restart

 

10. Verify APC Installed and Running

php -i | grep apc

 

11. Install the APC Monitor

From the root of your APC download and installation folder:
mv apc.php /var/www/html/
This should allow you to monitor APC using:

www.your-domain.com/apc.php

If this tutorial was helpful to you, then please do not forget to leave a comment, or two. :)

  • Pingback: Install Apache, PHP, APC and MySQL on Amazon Linux AMI - Coding Steps

  • ChristianJules

    Thanks a lot ! It really helped me, before I read and follows your instructions, I was unable to have APC run …

    • saxenap

      You are very welcome Christian. I am glad the installation worked out for you. 

  • Pingback: Php script installation service

  • unixer

    you are the best
    thanks for guide.

  • MagicPanties

    This was SO helpful. Thanks!

  • Seong Bae

    Thank you. Your tutorial was very helpful!

  • Mathias

    I have an error message when I do make install (I’m using bitnami): cp: cannot create regular file `usr/lib64/php/modules/#INST@8218#’ : Permission Denied
    make: *** [install-modules] Error 1

  • mathias

    worked with sudo make install but now sudo echo “extension=apc.so” >> /etc/php.d/apc.ini; gets denied.

    • Vinod Sudharshan

      first do ‘sudo su’
      and then run the above command

  • mathias

    Can’t make it work any help would be greatly appreciated.

  • Pingback: Install Apache 2.4, PHP 5.4, APC, & MySQL on Amazon EC2 with Amazon Linux AMI - Coding Steps

  • Paulo Santos

    Thank You. After my WS into a VPS, with your infos, I put on a DataServer running very fast at Amazon. THANK YOU Very much.