How to Install PHP APC on VPS & Dedicated Hosting? 

Home Website How to Install PHP APC on VPS & Dedicated Hosting? 
,
13 Mins Read
What Are SSH Connections - How To Edit In PuTTY, Mac, & Linux

Summarize this blog post with:

Key highlights 

  • Learn step-by-step installation processes for Alternative PHP Cache on VPS and dedicated hosting environments. 
  • Explore detailed configuration methods for Debian, Windows and AWS hosting environments. 
  • Uncover professional techniques for monitoring cache hit ratios, memory usage patterns and performance metrics 
  • Understand how to configure APC for high-traffic websites and maintain cache stability during peak traffic periods. 

Is your PHP application running slower than you’d like? Are page load times frustrating your visitors and hurting your conversion rates? If you’re managing a website on VPS or dedicated hosting, you’ve probably asked yourself how to squeeze every ounce of performance from your server. 

PHP APC (Alternative PHP Cache) was once the go-to solution for accelerating PHP applications through opcode caching. While newer alternatives like OPcache have largely replaced it in modern PHP versions, understanding how to install PHP APC remains valuable for legacy systems and specific use cases. This comprehensive php apc tutorial will walk you through everything you need to know about installing and configuring alternative PHP cache on your PHP VPS or dedicated server. 

In this guide, you’ll learn: 

  • What PHP APC is and how opcode caching improves performance 
  • Step-by-step installation instructions for Debian, Ubuntu and CentOS 
  • How to configure APC for optimal performance 
  • Troubleshooting common installation issues 

So, let’s dive into the details. 

What is PHP APC (Alternative PHP Cache)? 

PHP APC is a free, open-source opcode cache for PHP that significantly improves application performance by storing compiled PHP bytecode in shared memory. Instead of recompiling PHP scripts on every request, APC caches the compiled version, reducing server load and speeding up execution times by 30-50% in most cases. 

Understanding opcode caching 

Every time a PHP script runs, the PHP interpreter must parse and compile it into opcode before execution. This compilation process consumes valuable CPU cycles and memory. Opcode caching eliminates this repetitive work by storing the compiled bytecode in memory, ready for immediate execution. 

Think of it like this: instead of translating a book from one language to another every time someone wants to read it, you keep the translated version ready to go. The result is dramatically faster response times and reduced server resource consumption. 

How APC improves PHP performance? 

APC delivers performance improvements through several key mechanisms: 

  1. Reduced CPU usage by eliminating redundant compilation 
  2. Lower memory consumption through shared memory storage 
  3. Faster page load times, improving user experience 
  4. Increased server capacity to handle more concurrent requests 
  5. Reduced database load for applications that cache query results 

Studies show that PHP applications running with APC can handle 3-5 times more requests per second compared to non-cached configurations. 

APC vs. OPcache vs. APCu: What’s the difference? 

Before we dive into installation, it’s important to understand the evolution of PHP caching: 

  • PHP APC: This is the original caching solution that provided both opcode caching and user data caching. However, it’s no longer actively maintained and doesn’t support PHP 5.5 and later versions. 
  • OPcache: This is the modern replacement bundled with PHP 5.5+ that focuses exclusively on opcode caching. It’s faster, more efficient and actively maintained. 
  • APCu: This is the user cache component of APC, maintained separately for storing application data. It works alongside OPcache for PHP 5.5+. 

If you’re running PHP 5.5 or newer, you should use OPcache instead of APC. However, for legacy systems running PHP 5.4 or earlier, this php apc tutorial will help you implement proper caching. 

Prerequisites for installing PHP APC 

Before you begin the installation process, you’ll need to ensure your server meets the necessary requirements and that you have the proper access and tools configured. 

1. Server requirements and compatibility 

To install APC PHP successfully, verify the following: 

  • VPS or dedicated server with root access (shared hosting typically doesn’t allow custom PHP extensions) 
  • PHP version 5.4 or earlier (for PHP 5.5+ use OPcache instead) 
  • Minimum 512MB RAM (1GB or more recommended for production environments) 
  • Linux-based operating system (Debian, Ubuntu, CentOS or RHEL) 
  • Apache or Nginx web server 

2. Required system packages 

Your system needs several development tools and libraries before compiling APC. You’ll need: 

  • PHP development headers (php-dev or php-devel package) 
  • PECL (PHP Extension Community Library) 
  • Build essentials (gcc, make, autoconf) 
  • Apache development headers (if using Apache) 

3. Root access and SSH connection 

Installing PHP APC requires administrative privileges. Here’s how to prepare: 

  1. Connect to your server via SSH using your preferred terminal application 
  2. Switch to root user with sudo su or use sudo before each command 
  3. Verify you have write permissions to PHP configuration directories 
  4. Back up your existing php.ini file before making changes 

4. Command line PHP tests 

  1. Verify PHP is installed and check the version: php --version You should see PHP version information. APC requires PHP 5.4 or earlier. 
  2. List all loaded PHP modules: php -m This displays currently active extensions. 
  3. Locate your php.ini configuration file: php --ini Note the “Loaded Configuration File” path for later configuration steps. 
  4. Test PHP execution with a simple command: php -r "echo 'PHP is working: ' . phpversion();" 
  5. Common error interpretation: “command not found” means PHP isn’t installed or not in your PATH. “wrong version” indicates you’re running PHP 5.5+ which requires OPcache instead of APC. 

These quick checks ensure your environment meets APC requirements before proceeding with installation. 

How to install PHP APC on Debian and Ubuntu? 

Installing PHP APC on Debian-based systems like Ubuntu is straightforward using either PECL or the package manager. This Debian install PHP APC walkthrough covers both methods. 

Installing APC using PECL 

PECL provides the most up-to-date version of APC. Follow these steps: 

  1. Update your package lists: sudo apt-get update 
  2. Install PHP development tools: sudo apt-get install php-pear php5-dev build-essential 
  3. Install APC via PECL: sudo pecl install apc 
  4. When prompted, press Enter to accept default settings 
  5. Create APC configuration file: sudo echo "extension=apc.so" > /etc/php5/mods-available/apc.ini 
  6. Enable the extension: sudo php5enmod apc  

Installing APC using apt-get 

For a simpler installation process, you can use the package manager: 

  1. Update package repositories: sudo apt-get update 
  2. Install the APC package: sudo apt-get install php-apc 
  3. The package manager automatically configures the extension 
  4. Restart Apache or Nginx: sudo service apache2 restart 

Verifying the installation 

After installation, confirm that APC is working correctly: 

  1. Check if APC is loaded: php -m | grep apc 
  2. View APC information: php -i | grep apc 
  3. Create a PHP info file to check via browser: echo "" | sudo tee /var/www/html/info.php 
  4. Visit http://[yourserver].com/info.php in your browser and search for “apc” 
  5. Remove the info file for security: sudo rm /var/www/html/info.php 

 Following the above steps will let you install and verify PHP APC on Debian based systems. Now let’s learn the installation steps for Red Hat-based distributions.  

How to install PHP APC on CentOS and RHEL? 

The installation process on Red Hat-based distributions differs slightly from Debian systems. Here’s your complete guide for CentOS and RHEL. 

Installing development tools 

First, install the necessary build tools: 

  1. Update system packages: sudo yum update 
  2. Install development group: sudo yum groupinstall "Development Tools" 
  3. Install PHP development packages: sudo yum install php-pear php-devel httpd-devel 

Installing APC via PECL on CentOS 

With prerequisites in place, proceed with the APC installation: 

  1. Install APC through PECL: sudo pecl install apc 
  2. Accept default configuration options when prompted 
  3. Create configuration file: sudo echo "extension=apc.so" > /etc/php.d/apc.ini 
  4. Add basic APC configuration to the file: sudo nano /etc/php.d/apc.ini 
  5. Restart Apache: sudo systemctl restart httpd 
  6. Verify installation: php -m | grep apc 

Troubleshooting common installation errors 

If you encounter issues during installation, here are common problems and solutions: 

  • Error: “pecl command not found” 
    Solution: Install php-pear package using your distribution’s package manager. 
  • Error: “Cannot find autoconf” 
    Solution: Install autoconf with sudo yum install autoconf or sudo apt-get install autoconf. 
  • Error: “phpize failed” 
    Solution: Ensure php-devel (or php-dev) package is installed with matching PHP version. 
  • Warning: Module already loaded 
    Solution: Check for duplicate extension declarations in multiple configuration files. 

Once PHP APC is installed we’ll have to configure it for optimal performance. Let’s learn how. 

Configuring PHP APC for optimal performance 

Installation is just the beginning. Proper configuration is essential to maximize APC’s performance benefits for your specific workload. 

1. Essential APC configuration directives 

Add these settings to your apc.ini configuration file for optimal performance: 

extension=apc.so 
apc.enabled=1
apc.shm_size=128M 
apc.ttl=7200
apc.user_ttl=7200 
apc.gc_ttl=3600 
apc.max_file_size=1M 
apc.stat=1 

These settings enable APC with 128MB of shared memory, appropriate time-to-live values and automatic stat checking. 

2. Memory allocation and cache sizing 

The apc.shm_size directive determines how much memory APC uses. Here’s how to size it correctly: 

  • Small sites (low traffic): 32-64MB is typically sufficient 
  • Medium sites (moderate traffic): 128-256MB handles most applications 
  • Large sites (high traffic): 512MB-1GB for complex applications 
  • Enterprise applications: 1GB+ for massive codebases 

Monitor your cache hit rate using apc.php to determine if you need more memory. A hit rate below 95% suggests insufficient cache size. 

3. Editing php.ini for APC settings 

To add APC configuration to your main PHP configuration: 

  1. Locate your php.ini file: php -i | grep "php.ini" 
  2. Open the file with your preferred editor: sudo nano /etc/php5/apache2/php.ini 
  3. Add APC configuration section at the end of the file 
  4. Save changes and restart your web server 
  5. Verify settings took effect: php -i | grep apc.shm_size 

Now we’ll learn how to use apc.php for insights into cache performance. 

Using apc.php to monitor cache performance 

APC includes a powerful monitoring script that provides real-time insights into cache performance. Understanding how to use apc.php is crucial for optimization. 

1. Installing and securing apc.php 

The apc.php monitoring script comes with the APC package. Here’s how to set it up securely: 

  1. Locate the apc.php file (usually in /usr/share/doc/php-apc/ or similar) 
  2. Copy it to your web folder apc: sudo cp /usr/share/doc/php-apc/apc.php /var/www/html/ 
  3. Edit the file to add password protectionsudo nano /var/www/html/apc.php 
  4. Find the defaults section and set a username and password 
  5. Access via browser: http://[yourserver].com/apc.php 

Never leave apc.php accessible without authentication in production environments. 

2. Understanding apc.php metrics and statistics 

The apc info dashboard displays critical performance metrics: 

  • Cache hit rate: Percentage of requests served from cache (aim for 95%+) 
  • Memory usage: Shows allocated vs. used memory 
  • Cache entries: Number of cached files and user data 
  • Fragmentation: Memory fragmentation percentage (lower is better) 
  • Uptime: Time since cache was last cleared 

3. Accessing apc.php?scope= for detailed analysis 

The apc.php script supports URL parameters for deeper analysis. Use the ‘apc.php?scope=’ parameter to filter information: 

  • apc.php?scope=A – Shows active cached files 
  • apc.php?scope=D – Displays deleted entries 
  • apc.php?scope=C – Shows configuration settings 

These views help diagnose caching issues and identify which files consume the most memory. 

Optimizing WordPress and PHP applications with APC 

While APC works automatically once installed, you can take additional steps to maximize its benefits for specific applications like WordPress. 

WordPress-specific APC optimization 

WordPress benefits tremendously from opcode caching. Here’s how to optimize your WordPress site with APC: 

  1. Ensure APC is enabled and properly configured 
  2. Install a WordPress caching plugin that leverages APC for object caching 
  3. Set apc.stat=0 in production to skip file modification checks 
  4. Increase apc.shm_size for sites with many plugins and themes 
  5. Monitor cache hit rates and adjust memory accordingly 

A properly configured WordPress site on php vps hosting with APC can achieve page load times under 1 second. 

APC configuration for high-traffic websites 

High-traffic sites require special attention to APC configuration: 

  • Allocate more shared memory (512MB-1GB minimum) 
  • Set longer TTL values to reduce cache churn 
  • Enable apc.write_lock to prevent cache stampedes 
  • Use apc.slam_defense to protect against simultaneous writes 
  • Monitor fragmentation and periodically restart if needed 

Measuring performance improvements 

To quantify APC’s impact, measure these metrics before and after implementation: 

  • Average page load time (should decrease 30-50%) 
  • Server response time (typically improves 40-60%) 
  • CPU usage (often reduced by 30-40%) 
  • Concurrent user capacity (can increase 3-5x) 
  • Memory efficiency (better utilization of available RAM) 

While the above PHP APC measures will optimize your website performance, choosing the right VPS or dedicated hosting provider goes a long way toward ensuring optimal page load times. Bluehost gives you unmatched performance with VPS and dedicated hosting. Let’s see how. 

Why choose Bluehost for PHP APC hosting? 

While installing PHP APC on any VPS or dedicated server is possible, choosing the right hosting provider makes all the difference in performance and ease of management. 

VPS hosting with full root access 

Our VPS hosting serves the perfect environment for custom PHP optimization like APC installation. With complete root access, you control every aspect of your server configuration.  

Benefits of Bluehost VPS Hosting: 

  • SSD storage accelerates both APC’s cache operations and overall performance. 
  • Guaranteed resources ensure consistent performance even during traffic spikes.  
  • Complete root access lets you control every aspect of your server configuration.  

The intuitive management interface makes server administration straightforward, even for those new to VPS environments. You get the flexibility to install and configure apc hosting solutions exactly as your applications require. 

Dedicated hosting for maximum performance 

For applications with demanding performance requirements, Bluehost dedicated servers offer enterprise-grade infrastructure. You’ll benefit from:  

  • OCI infrastructure 
  • Unmetered bandwidth 
  • 3 dedicated IPs 

With enhanced infrastructure and higher stability, the performance of your website will be in good hands. 

Let’s learn how to troubleshoot PHP APC installation issues. 

Troubleshooting PHP APC installation issues 

Even following instructions carefully, you may encounter issues. Here are solutions to the most common problems. 

APC not loading after installation 

If PHP doesn’t show APC as loaded after installation, try these diagnostic steps: 

  1. Verify the extension file exists: ls -l /usr/lib/php5/*/apc.so 
  2. Check for syntax errors in configuration: php -m (look for error messages) 
  3. Ensure the extension directive is correct in your configuration file 
  4. Check file permissions on apc.so (should be readable by web server) 
  5. Verify you restarted the web server (not just reloaded) 
  6. Check error logs for specific issues: tail -f /var/log/apache2/error.log 

Memory exhaustion and cache full errors 

If you see “cache full” warnings or memory exhaustion messages: 

  1. Increase apc.shm_size in your configuration 
  2. Review cache hit rates to ensure efficiency 
  3. Check for memory leaks in your application 
  4. Implement proper TTL settings to expire old entries 
  5. Consider clearing the cache and starting fresh 

Prevention tip: Monitor memory usage regularly through apc.php to catch issues before they impact performance. 

Compatibility issues with PHP versions 

PHP version compatibility is a common source of problems with APC: 

  • PHP 5.5 and later: APC is not compatible; use OPcache instead 
  • PHP 5.4: APC 3.1.13 or later required 
  • PHP 5.3: Full APC support available 
  • PHP 5.2 and earlier: Older APC versions work but are unsupported 

If you’re running a newer PHP version, consider migrating to OPcache rather than attempting to force APC compatibility. 

Final thoughts 

Installing PHP APC on your VPS or dedicated server is a powerful way to accelerate legacy PHP applications through efficient opcode caching. Throughout this php apc tutorial, you’ve learned how alternative php cache works, how to install it on various Linux distributions and how to configure it for optimal performance. 

Remember these key takeaways: 

  • APC can improve PHP performance by 30-50% through opcode caching 
  • VPS and dedicated hosting provide the necessary root access for installation 
  • Proper configuration and monitoring through apc.php ensures maximum benefits 
  • For PHP 5.5+ systems, migrate to OPcache for modern opcode caching 
  • Regular monitoring and adjustment optimize cache hit rates and memory usage 

Ready to implement PHP APC or explore modern hosting solutions with optimized PHP performance? Bluehost VPS and dedicated hosting provide the perfect foundation with full root access, expert support and enterprise-grade infrastructure. Whether you’re optimizing legacy applications with APC or deploying modern PHP solutions, the right hosting environment makes all the difference. 

Take your PHP performance to the next level with Bluehost Dedicated Hosting

FAQs 

Is PHP APC still supported? 

PHP APC is no longer actively maintained. The last stable release was in 2012. For PHP 5.5 and later, OPcache has replaced APC as the recommended opcode cache. However, APC remains functional for legacy PHP 5.4 and earlier installations. 

What is the difference between APC and APCu? 

APC provided both opcode caching and user data caching. APCu (APC User Cache) is the maintained user cache component that works alongside OPcache in PHP 5.5+. APCu stores application data only, while OPcache handles opcode caching. 

Can I use APC on Windows servers? 

While apc windows builds exist, they’re not officially supported or maintained. Windows users should use WinCache for opcode caching or migrate to OPcache with PHP 5.5+. Linux remains the recommended platform for APC. 

How much memory should I allocate to APC? 

Start with 128MB for most applications. Monitor your cache hit rate and memory usage through apc.php. If hit rates drop below 95% or you see frequent cache flushes, increase allocation. Large applications may need 512MB or more. 

Does APC work with PHP 7 and PHP 8? 

No, APC is incompatible with PHP 7 and PHP 8. These versions include OPcache by default, which provides superior performance. If you need user caching functionality, install APCu alongside OPcache. 

Can I use APC on shared hosting? 

Most shared hosting environments don’t allow custom PHP extension installation. APC requires root access and works best on VPS or dedicated servers where you control the PHP configuration completely. 

How do I clear the APC cache? 

You can clear APC cache in several ways: restart your web server, use the clear cache button in apc.php, call apc_clear_cache() in a PHP script or use the command php -r “apc_clear_cache(); apc_clear_cache(‘user’);” 

  • I’m a web hosting and WordPress enthusiast dedicated to helping you enhance your online presence. I love making tech simple and accessible for everyone with my writing.

Learn more about Bluehost Editorial Guidelines
View All

Write A Comment

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