40

How can I install APCu in Windows?

I found this. But I need a solution for Windows.

I use PHP 5.5.6 (I have the XAMPP package).

Priyantha
  • 4,839
  • 6
  • 26
  • 46
kemal89
  • 931
  • 2
  • 8
  • 20
  • Hi there user3481997! Robert's answer below is the correct one. The only difference for you is you are using XAMPP. In my case, the folder to copy the 'correct' dll is "C:\xampp\php\ext". Your XAMPP directory might be different. Check your PHP error log to make sure it installs correctly. – Alvin Bunk Feb 06 '16 at 17:34

4 Answers4

94

This short and straight to the point tutorial should help you

Install APCu on Windows

Assumptions

  • I assume that you know what is APC - Alternative PHP cache
  • You want to install APCu because APC is not compatible anymore with PHP 5.5.x
  • You want to install APCu for wamp, xampp. Mostly windows web development platforms for PHP

Instructions

Pre: All directory locations might be different for you depending on your wamp installation folder and your PHP/apache versions.

  1. Go to http://pecl.php.net/package/APCu, there is a table with available releases
  2. Choose whatever release suits you better (latest stable version that supports your php version)
  3. Choose package from DLL list, depending on what Windows you are using:
    • PHP version (5.5 in your case)
    • x64 (64 bits) OR x86 (32 bits windows)
    • Thread Safe (for Apache compatibility)
  4. Unzip the archive, copy php_apcu.dll in C:\wamp\bin\php\php5.5.6\ext.
  5. Go to C:\wamp\bin\apache\apache2.4.9\bin open php.ini and add the following lines (I just added them at the end of the file):

    [apcu]
    extension=php_apcu.dll
    apc.enabled=1
    apc.shm_size=32M
    apc.ttl=7200
    apc.enable_cli=1
    apc.serializer=php
    

    This are recommended configurations located in INSTALL file from the php_apcu archive, excepting the location of the DLL file.

  6. Restart wamp

  7. Go to http://localhost/phpinfo.php and check if apcu configuration table appears and apcu is enabled
  8. If you also want to use apcu for PHP CLI then you only need to add in C:\wamp\bin\php\php5.5.6\bin\php.ini the config lines you added at step 5 in apache's php.ini.

The end!

Claudiu
  • 3,700
  • 1
  • 38
  • 35
Robert
  • 1,117
  • 8
  • 10
  • Do I need the thread-safe or non-thread-safe version if I'm hosting in IIS? Is there ever a time to choose NTS over TS? – Jacob Stamm Jun 18 '19 at 13:44
14

For those who want APCu with backward APC compatibility (1:1 replacement without changing codebase, for example apc_cache_info > apcu_cache_info)

  1. Download php_apcu.dll from release page (choose proper PHP version, architecture and thread safety mode)

  2. Download php_apcu_bc.dll from PECL

  3. Save both files in ext dir under your PHP installation folder

  4. Load extensions in php.ini:

    extension=php_apcu.dll
    extension=php_apcu_bc.dll
    
  5. Configure APCu in php.ini

    [APCu]
    apc.enabled=1
    apc.shm_size=32M
    apc.ttl=7200
    apc.enable_cli=1
    apc.serializer=php
    

INFO: APC extension with APCu-BC 1.0.3 must be named exactly php_apcu.dll in order to work. When I named it php_apcu_bc-1.0.3-7.1-ts-vc14-x86.dll XAMPP did not start properly (error about missing php_apc.dll)

Additional Note: the downloaded zip file from the source above for vc15 contained a file named php_apc.dll (in file: 'php_apcu_bc-1.0.4-7.2-ts-vc15-x86.zip' date: 13/06/2018) - just renaming it to php_apcu_bc.dll worked.

Community
  • 1
  • 1
Wirone
  • 3,304
  • 1
  • 29
  • 48
  • I did exactly what you said. When I downloaded the php_apcu_bc.dll it came with php_apcu.dll name still (from the PECL , point 2.) that you said), and I renamed it to that, and still doesn't fix it. Errors: PHP Warning: PHP Startup: Unable to load dynamic library 'php_apcu.dll' PHP Warning: PHP Startup: Unable to load dynamic library 'php_apcu_bc.dll' – Jess Jun 08 '20 at 21:58
  • I'm sorry @JessicaPereira but it was 3 years ago and I'm not using Windows for development anymore. Unfortunately I can't help you more than giving a tip that you should check if you downloaded proper version of APCu (PHP version, architecture, thread safety etc.). – Wirone Jun 19 '20 at 07:43
  • many many thanks. did exactly how u suggested and it worked: 1 - downloaded php_apcu.dll for 7.3;ts | then 2 - downloaded php_apc.dll (that is apcu_bc) for 7.3;ts | then 3 - renamed php_apc.dll|pdb to php_apcu_bc.dll|pdb | finally added extension = php_apcu.dll extension = php_apcu_bc.dll to php.ini and restarted httpd - tested with phph -m = both apc and apcu modules running. you are the best, man! – Striker Mar 15 '23 at 01:31
1

It matters if you use the thread safe or non thread safe version of the DLL. For me only the NTS worked in Windows 10 x64 and PHP 7.4 using the PHP built in server. It was confusing because the error msg PHP gave when run php -i was Unable to load dynamic library 'php_apcu.dll' (tried: ext\php_apcu.dll) as if the file was not there.

user2292978
  • 31
  • 1
  • 5
  • Running a `phpinfo()` gives your version type (NTS or TS). Read it as "Thread Safety: Enabled (TS)" or "Thread Safety: Disabled (NTS)" – Erdal G. Jan 03 '21 at 12:48
-2

Please refer to the official documentation:
https://secure.php.net/manual/en/opcache.installation.php

In my case, I'm using PHP 5.6 on XAMPP and everything I need to do is to update my php.ini file with (recommended settings):

opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=1
Pang
  • 9,564
  • 146
  • 81
  • 122
Ivan
  • 514
  • 5
  • 21
  • 2
    opcache is not APCu. opcache caches opcode, i.e. an intermediate code that is generated out of your php scripts. Any php script benefits from this (if its code does not change all the time). APCu is a data cache that allows php applications to cache data in memory. Only php scripts that explicitly use it benefit from this. – Christopher K. Mar 20 '19 at 09:35