Im looking for a tutorial to install and configure APC on CentOS 7. I see there is one for Ubuntu but not for CentOS.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Hi @riahc4 Do you mean APC as in the PHP module? If yes, then it’s been replaced by OPcache, which is many times faster. OPcache is available from 5.6 and activated by default from 7.0
Heya,
Here’s a step-by-step tutorial on how to install and configure APC (Alternative PHP Cache) on CentOS 7. APC is a free and open-source opcode cache for PHP, which can optimize PHP performance by storing precompiled script bytecode in shared memory, thereby removing the need for PHP to load and parse scripts on each request.
APC is available through the PECL repository. If you haven’t installed PHP and PECL, you can do so with the following commands:
sudo yum install php
sudo yum install php-devel
sudo yum install php-pear
Now, install APC using PECL:
sudo pecl install apc
Create an APC Configuration File:
After installing APC, you need to create a configuration file for it so that PHP can use it.
/etc/php.d/). The file can be named 40-apc.ini to ensure it loads after the default PHP configurations:sudo vi /etc/php.d/40-apc.ini
Add Configuration Directives:
Inside this file, add the following configuration directives:
; Enable APC extension module
extension=apc.so
; The following can be adjusted according to your needs
; The size of each shared memory segment in MB
apc.shm_size=32M
; The number of seconds a cache entry is allowed to idle in a slot before APC dumps the cache
apc.ttl=7200
; The number of seconds a user cache entry is allowed to idle in a slot before APC dumps the cache
apc.user_ttl=7200
; The number of seconds that a cache entry may remain on the garbage-collection list
apc.gc_ttl
Adjust the shm_size, ttl, user_ttl, and gc_ttl values according to your server’s resources and your application’s requirements.
Restart Apache:
After making changes to PHP configuration, restart your web server to apply them. If you are using Apache, use this command:
sudo systemctl restart httpd
To verify that APC is installed and configured correctly, create a PHP file with the following content and place it in your web server’s document root:
<?php
phpinfo();
?>
When you access this file via a web browser, you should see the APC settings and status displayed.
To monitor APC usage and status, you can use a script like apc.php which is bundled with APC. It provides a detailed view of the cache usage.
Locate the apc.php File:
This file is usually located in the APC source folder. You can also find it online or in the PECL/APC package.
Copy apc.php to Your Web Server Document Root:
Make sure it’s in a protected directory or password-protected to prevent public access, as it can reveal detailed server information.
Access apc.php via Browser:
Navigate to this file through your web browser to view APC’s cache information.
phpinfo.php or apc.php can be a security risk.By following these steps, you should be able to install and configure APC on CentOS 7 for PHP. Remember, APC is mainly beneficial for older PHP versions (PHP 5.x). If you’re using PHP 7.x or later, consider using the newer alternatives.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.