January 21, 2014
SSHFS-MUX mounting.Optimizing server for APC, and PHP.
Many times our servers struggle to answer to connections in time, this is why we need to optimize.
First we assume we have installed Virtualmin on Debian 7.
Second, we assume you know some of PHP and common Linux utilities.
We’ll install memcached and php5-memcache [Memcache plugin for memcached].
php5-memcache and memcached
apt-get install memcached php5-memcache
We are assuming you’ll use Memcached on the local server, so just restart the service as follows:
/etc/init.d/memcached restart
Now we restart apache… to load up everything correctly including PHP.
/etc/init.d/apache2 restart
Now lets get dirty with APC!
apt-get install php-pear
This will allow us to build new modules into php.
Now we need some dependencies to be able to compile APC.
apt-get install php5-dev apache2-prefork-dev build-essential
A long list of dependencies you’ll receive, accept them, they are GCC and others.
Now lets build APC!
pecl install apc
As I don’t have the rest on my terminal right now…
server2:~# pecl install apc
downloading APC-3.0.17.tgz ...
Starting to download APC-3.0.17.tgz (116,058 bytes)
.........................done: 116,058 bytes
47 source files, building
running: phpize
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
Use apxs to set compile flags (if using APC with Apache)? [yes] : <-- ENTER
[...]
----------------------------------------------------------------------
Libraries have been installed in:
/var/tmp/pear-build-root/APC-3.0.17/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.
(It is safe to ignore warnings about tempnam and tmpnam).
running: make INSTALL_ROOT="/var/tmp/pear-build-root/install-APC-3.0.17" install
Installing shared extensions: /var/tmp/pear-build-root/install-APC-3.0.17/usr/lib/php5/20060613+lfs/
running: find "/var/tmp/pear-build-root/install-APC-3.0.17" -ls
998152 4 drwxr-xr-x 3 root root 4096 Mar 28 15:23 /var/tmp/pear-build-root/install-APC-3.0.17
998214 4 drwxr-xr-x 3 root root 4096 Mar 28 15:23 /var/tmp/pear-build-root/install-APC-3.0.17/usr
998215 4 drwxr-xr-x 3 root root 4096 Mar 28 15:23 /var/tmp/pear-build-root/install-APC-3.0.17/usr/lib
998216 4 drwxr-xr-x 3 root root 4096 Mar 28 15:23 /var/tmp/pear-build-root/install-APC-3.0.17/usr/lib/php5
998217 4 drwxr-xr-x 2 root root 4096 Mar 28 15:23 /var/tmp/pear-build-root/install-APC-3.0.17/usr/lib/php5/20060613+lfs
998213 416 -rwxr-xr-x 1 root root 418822 Mar 28 15:23 /var/tmp/pear-build-root/install-APC-3.0.17/usr/lib/php5/20060613+lfs/apc.so
Build process completed successfully
Installing '/var/tmp/pear-build-root/install-APC-3.0.17//usr/lib/php5/20060613+lfs/apc.so'
install ok: channel://pecl.php.net/APC-3.0.17
You should add "extension=apc.so" to php.ini
server2:~#[FROM https://www.howtoforge.com/apc-php5-apache2-debian-etch](link is external)
If this didn’t go well, just go with apt-get install php-apc !
Now its when everything goes fuzzy… as we use virtualservers, you’ll need to configure each virtualserver APC individually and decide how much cache etc.
In our case, lets go with a client.
This should be good enough for you to start enjoying APC.
At your php.ini add this information: [if using vhosts with virtualmin…] cd /home/user/etc/->Php.ini in here.
[APC] extension=apc.so apc.enabled=1 apc.shm_segments=1 apc.shm_size=256M ===> This value depends on kernel.shmmax in our case would read 268435456 that would be around 256M. ;cat /proc/sys/kernel/shmmax => to read the size apc.optimization=0 ;Control TTL of Cache apc.ttl=108000 apc.user_ttl=108000 apc.gc_ttl=108000 apc.cache_by_default=1 apc.filters="-/home/user/public_html/apc/apc\.php$" apc.slam_defense=0 apc.use_request_time=1 apc.mmap_file_mask=/tmp/apc-user.XXXXXX ;apc.mmap_file_mask=/dev/zero apc.file_update_protection=2 apc.enable_cli=1 apc.max_file_size=5M ;WARNING => APC.STAT checks if file changed every time b4 opening. apc.stat=0 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.rfc1867_ttl=3600 apc.lazy_classes=0 apc.lazy_functions=0
I’d also recommend you changing the swappiness of the server to a low value, remember IO is a killer… and it’s better to max out the ram, and leave the swap for emergencies.
Normally it would be set to 60.
My test’s proven for my configurations its best to have it ~15 – ~30.
To check the actual value:
cat /proc/sys/vm/swappiness
That should print: 60 on the screen.
To change it on the fly and test it:
sysctl vm.swappiness=[value]
On reboot that will reset to default, to make it stick:
edit /etc/sysctl.conf
and add at the end of the file:
vm.swappiness=[value]
Now that will stick on every restart.
Stay tuned, i’ll keep expanding my guide into getting the best out of your servers.