Speed up web server with APC cache for PHP on Raspberry Pi (lighttpd)
Raspberry Pi is also suitable for operation as a web server. Unfortunately, he is a bit weak on his chest because of his hardware. That is, the web server gets you up and running fast enough. It looks different if the web server (for example lighttpd) works with PHP5. Then the execution speed depends on the model a bit sluggish or even extremely slow.
This is where caching helps. For example with APC. APC stands for Alternative PHP Cache. This is an extension for PHP that can accelerate the PHP code by caching and optimizing already interpreted versions of the scripts. When called again, the interpreted code comes from the cache, not the interpreter.
Thanks to the PHP cache APC gets Raspberry Pi together with lighttpd and PHP to an acceptable working speed.
- Extend the web server lighttpd with the PHP cache APC.
First, install the PHP cache APC to:
sudo apt-get update sudo apt-get install php-apc
Then some settings have to be made on the APC cache. To do this, open the APC configuration file:
sudo nano /etc/php5/mods-available/apcu.ini
Here you make the following changes.
extension = apcu.so apc.enabled = 1 apc.file_update_protection = 2 apc.optimization = 0 apc.shm_size = 32M apc.include_once_override = 0 apc.shm_segments = 1 apc.gc_ttl = 7200 apc.ttl = 7200 apc.num_files_hint = 1024 apc.enable_cli = 0
Note: A cache size of 32MB is certainly useful (“apc.shm_size = 32M”). However, there are applications that need more. So if APC does not seem to bring any improvement you can also experiment with values of 64MB and 128MB. Keep in mind that this value is missing for other applications in memory.
To apply the changes, reload the configuration of the web server.
sudo service lighttpd force-reload
Leave a Reply