VPS & Dedicated Hosting: How to Install PHP APC
PHP APC (Alternative PHP Cache) is a handy tool that speeds up your PHP websites and applications by storing compiled code in memory. This means your server doesn’t have to recompile scripts every time someone visits, making things faster and more efficient. While APC works well with older PHP versions like 5.x, newer versions (7.x and above) use an updated version called APCu, which is better suited for modern setups. In this guide, we’ll take you step-by-step through installing and setting up PHP APC or APCu on AlmaLinux 9 — a popular Linux server operating system often used for VPS and dedicated hosting.
- Step 1: Update Your System Packages
- Step 2: Install PHP and Development Tools
- Step 2.1: Troubleshoot PHP Package Exclusions
- Step 3: Install PHP APC or APCu Extension
- Step 4: Enable the Extension
- Step 5: Configure APC or APCu Settings
- Step 6: Restart Your Web Server
- Step 7: Confirm Installation
- Related Articles
- Summary
- Root or sudo privilege.
- PHP is installed on your server (version 7.x or higher recommended).
- Basic familiarity with terminal commands.
Step 1: Update Your System Packages
Unlike Debian-based distributions that use apt-get, AlmaLinux is RHEL-based and uses dnf or yum. Update your package lists and upgrade packages with:
sudo dnf update -y
Step 2: Install PHP and Development Tools
Ensure PHP and the required development tools are installed. These are needed to compile and install PHP extensions like APC/APCu.
sudo dnf install -y php php-devel php-pear gcc make autoconf
Troubleshoot PHP Package Exclusions
If you receive errors like All matches were filtered out by exclude filtering for argument: php, your AlmaLinux system likely has a global DNF exclusion for PHP packages.
To check for such exclusions, run:
grep exclude /etc/dnf/dnf.conf /etc/yum.repos.d/*.repo
You may see output like this:
/etc/dnf/dnf.conf:exclude=bind-chroot dovecot* exim* filesystem p0f proftpd* pure-ftpd* php*
This means PHP packages are excluded globally.
To fix this, edit /etc/dnf/dnf.conf to remove php* from the exclude list using your preferred text editor, for example:
sudo nano /etc/dnf/dnf.conf
Locate the exclude= line and remove php* leaving it as:
exclude=bind-chroot dovecot* exim* filesystem p0f proftpd* pure-ftpd*
Save and exit. Alternatively, use the following command to remove it automatically:
sudo sed -i 's/php\*//g' /etc/dnf/dnf.conf
After making the change, clean the dnf cache and update metadata:
sudo dnf clean all
sudo dnf makecache
Step 3: Install PHP APC or APCu Extension
Using PECL (Common Method)
For PHP 7.x and above, APCu is the preferred cache extension. You can install it via PECL:
sudo pecl install apcu
If your PHP version is 5.x, you might need the original APC extension:
sudo pecl install apc
During the installation, if prompted with Enable internal debugging? [yes] :, just press Enter to skip.
Troubleshooting PECL Installation
If the pecl install apcu command fails or pecl is not found even after troubleshooting dependencies and exclusions, consider the following:
- Ensure
php-pear,php-devel, and build tools likegcc,make, andautoconfare installed. - Check that the PHP version you're using supports PECL extensions correctly.
- Verify you have enabled proper repositories (like EPEL) and that your system can access PHP packages.
Alternative: Install via AlmaLinux Official Repositories
Often, you can avoid PECL complications by installing the prebuilt APCu package from AlmaLinux official repositories using dnf:
sudo dnf install php-pecl-apcu
After installation, restart your web server as appropriate for your setup:
For Apache:
sudo systemctl restart httpd
For Nginx with PHP-FPM:
sudo systemctl restart php-fpm
sudo systemctl restart nginx
Step 4: Enable the Extension
Next, you'll create a configuration file to tell PHP to load the APC or APCu extension:
For APCu (PHP 7+):
sudo tee /etc/php.d/20-apcu.ini <<EOF
extension=apcu.so
EOF
For APC (PHP 5.x):
sudo tee /etc/php.d/20-apc.ini <<EOF
extension=apc.so
EOF
Step 5: Configure APC or APCu Settings
You can add recommended configuration parameters in the same ini file or a separate APC config file:
[apcu]
apc.enabled=1
apc.shm_size=128M
apc.ttl=7200
apc.user_ttl=7200
apc.gc_ttl=3600
apc.num_files_hint=1024
apc.mmap_file_mask=/tmp/apc.XXXXXX
apc.shm_size according to your server’s RAM.Step 6: Restart Your Web Server
Apply changes by restarting your web server.
For Apache:
sudo systemctl restart httpd
For Nginx with PHP-FPM:
sudo systemctl restart php-fpm
sudo systemctl restart nginx
Step 7: Confirm Installation
Create a PHP info file to verify that APC/APCu is loaded.
Create /var/www/html/info.php containing:
<?php phpinfo(); ?>
Then browse to:
http://your-server-ip/info.php
Related Articles
Summary
By installing PHP APC/APCu on your AlmaLinux 9 VPS or dedicated server, you leverage caching to dramatically improve PHP application performance and reduce server load. Remember to choose the right extension based on your PHP version and keep your server updated for best security and stability.
If you need further assistance, feel free to contact us via Chat or Phone:
- Chat Support - While on our website, you should see a CHAT bubble in the bottom right-hand corner of the page. Click anywhere on the bubble to begin a chat session.
- Phone Support -
- US: 888-401-4678
- International: +1 801-765-9400
You may also refer to our Knowledge Base articles to help answer common questions and guide you through various setup, configuration, and troubleshooting steps.