APC is an Important Part For WordPress Like Web Software to Speed Up. Here is How To Install, Configure APC on PHP 7.2 on Ubuntu LAMP Server. We have older guides on this website to setup APC for PHP 7.0. However, PHP 7.2 needs slight different commands (which may be difficult for an not so used to configure). Although Zend Op Cache is sufficient for many web software, APC Object Cache backend for WordPress on single-server sites perform a lot better.
Update : This guide is an update to this article for installing PHP 7.4
WordPress has a built-in object caching API which is used to store complex data objects (may be HTML structures as well). The Alternative PHP Cache (APC) and OPcache both provide opcode caching. However, Zend OPcache is like a quick fix whereas APC is the full version. After installation of APC, you may test disabling Opcache to chec difference and also both together.
---
Steps of How To Install APC on PHP 7.2
First SSH to your instance and update, upgrade :
1 2 | apt update -y apt upgrade -y |
If you have installed PHP in our normal way, then just run this command to install APC :
1 | pecl install apcu |
You’ll receive huge output like this :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | pecl install apcu downloading apcu-5.1.12.tgz ... Starting to download apcu-5.1.12.tgz (105,890 bytes) ........................done: 105,890 bytes 39 source files, building running: phpize Configuring for: PHP Api Version: 20151012 Zend Module Api No: 20151012 Zend Extension Api No: 320151012 Enable internal debugging in APCu [no] : yes building in /tmp/pear/temp/pear-build-rootoK2n7A/apcu-5.1.12 running: /tmp/pear/temp/apcu/configure --with-php-config=/usr/bin/php-config --enable-apcu-debug=yes checking for grep that handles long lines and -e... /bin/grep checking for egrep... /bin/grep -E checking for a sed that does not truncate output... /bin/sed checking for cc... cc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o .... |
You’ll get an end like this :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | Libraries have been installed in: /tmp/pear/temp/pear-build-rootoK2n7A/apcu-5.1.12/modules If you ever happen to want to link against installed libraries in a given directory, LIBDIR, you must either use libtool, and specify the full pathname of the library, or use the '-LLIBDIR' flag during linking and do at least one of the following: - add LIBDIR to the 'LD_LIBRARY_PATH' environment variable during execution - add LIBDIR to the 'LD_RUN_PATH' environment variable during linking - use the '-Wl,-rpath -Wl,LIBDIR' linker flag - have your system administrator add LIBDIR to '/etc/ld.so.conf' See any operating system documentation about shared libraries for more information, such as the ld(1) and ld.so(8) manual pages. ---------------------------------------------------------------------- Build complete. Don't forget to run 'make test'. running: make INSTALL_ROOT="/tmp/pear/temp/pear-build-rootoK2n7A/install-apcu-5.1.12" install Installing shared extensions: /tmp/pear/temp/pear-build-rootoK2n7A/install-apcu-5.1.12/usr/lib/php/20151012/ ... install ok: channel://pecl.php.net/apcu-5.1.12 configuration option "php_ini" is not set to php.ini location You should add "extension=apcu.so" to php.ini |
To start using APCu, you should run the following command for PHP 7.2:
1 | echo "extension=apcu.so" | tee -a /etc/php/7.2/mods-available/apcu.ini |
And the following command for PHP 7.0:
1 | echo "extension=apcu.so" | tee -a /etc/php/7.0/mods-available/apcu.ini |
Reload apache :
1 | systemctl restart apache2 |
If you run :
1 | php -i | grep apcu |
You’ll get confirmed path of the settings file for CLI, like :
1 | /etc/php/7.2/cli/conf.d/20-apcu.ini |
Modify to the following in mods_enabled
file (like /etc/php/7.2/mods-available/apcu.ini
) :
1 2 3 4 5 6 7 8 9 10 11 | extension=apcu.so apc.enabled=1 apc.shm_size=1024M apc.max_file_size=10M apc.num_files_hint=20000 apc.user_entries_hint=20000 apc.ttl=7200 apc.user_ttl=7200 apc.gc_ttl=3600 apc.include_once_override=0 apc.enable_cli=1 |
Save it. Open PHP.ini
file which is under Apache’s path, like :
1 | nano /etc/php/7.2/apache2/php.ini |
Add a block above settings of cURL
(usually opcache
settings written above it) :
1 | nano /etc/php/7.2/apache2/php.ini |
Reload apache :
1 | systemctl restart apache2 |
Tuning APC on production server not funny. APC’s one settings can make site not loading. You have to delete that settings file and restart Apache, then try finding which settings was faulty. You can slowly try this settings :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | extension=apc.so apc.enabled = 1 apc.shm_segments = 1 apc.shm_size = 40M apc.optimization = 0 apc.num_files_hint = 4096 apc.ttl = 7200 apc.user_ttl = 7200 apc.gc_ttl = 0 apc.cache_by_default = 1 apc.filters = "" apc.mmap_file_mask = "/tmp/apc.XXXXXX" apc.slam_defense = 0 apc.file_update_protection = 2 apc.enable_cli = 0 apc.max_file_size = 10M apc.stat = 1 apc.write_lock = 1 apc.report_autofilter = 0 apc.include_once_override = 0 ;apc.rfc1867 = 0 ;apc.rfc1867_prefix = "upload_" ;apc.rfc1867_name = "APC_UPLOAD_PROGRESS" ;apc.rfc1867_freq = 0 apc.localcache = 0 apc.localcache.size = 512 apc.coredump_unmap = 0 apc.stat_ctime = 0 |
You can check APC settings in system with this command :
1 | php -r 'phpinfo();' | grep -i 'apc' |
It is what expected :
1 2 3 4 5 6 7 | APCu Support => Enabled APCu Debugging => Enabled apc.coredump_unmap => Off => Off apc.enable_cli => On => On apc.enabled => On => On ... ... |
Getting that APCu Support => Enabled
not easy.
Go to your public directory, like /var/www/html
:
1 | cd /var/www/html |
wget
this file there :
1 | https://github.com/krakjoe/apcu/blob/master/apc.php |
Like :
1 2 | cd /var/www/html wget https://raw.githubusercontent.com/krakjoe/apcu/master/apc.php |
Open that webpage on browser. That makes you sure that APC actually working.
Tagged With php7 2 apc , install APC PE6U21W , install apc cache ubuntu , How to install ubutu on apc , how to install apc , build apcu so , apcu ini , apc y php 7 2 , apc php 7 , ubuntu install apc