bugmenot3
Posts: 39
Joined: Wed Aug 15, 2012 12:27 pm
Contact: Website

Apache tuning?

Fri Dec 28, 2012 9:37 am

Hi
I've installed apache/php/owncloud on my raspi. It's working fine but it could be a bit faster. Are there any tuning tips for apache? I don't want to use lighttpd oder nginx because I find apache easier to setup.

Looking forward for any advise

chris57100
Posts: 522
Joined: Wed Sep 12, 2012 7:23 pm
Location: Thionville
Contact: Website

Re: Apache tuning?

Fri Dec 28, 2012 9:42 am

It seems that a module called php-apc can speed up the system

By the way, nginx is really not complicated to configure once you understand how it works (needs 10 minutes max) :-)

About owncloud if you are going to access it from internet think about using SSL certificates ;)
Raspberry Pi Home Server : http://www.pihomeserver.fr
Software and electronic tutorials : Samba, Airplay, CUPS, Time machine, Nginx, Owncloud, rTorrent, Wordpress, etc.
Full Wi-Fi hotspot installation on a RPi 3 including a captive portal and freeradius management: https://github.com/pihomeserver/Kupiki-Hotspot-Script

benthepoet
Posts: 28
Joined: Sun Oct 02, 2011 5:36 am
Location: Traverse City, MI USA
Contact: Website

Re: Apache tuning?

Fri Dec 28, 2012 3:57 pm

Yeah, you'll definitely want to install php-apc. This will improve response times and dramatically cut down on CPU load.

Lighttpd can certainly be confusing, but Nginx is fairly similar to Apache in how it handles it configurations. The big difference is in the way it handles PHP. With Nginx, PHP runs as a separate process that Nginx passes requests to. Learning the basics of Nginx is definitely worth your while as it will reduce the memory usage of your server and it can serve static files (pictures, video, etc.) faster than Apache can.
Ben Hanna
Ducky Pond
http://www.ducky-pond.com

permaband
Posts: 62
Joined: Wed Aug 01, 2012 2:14 pm
Location: uk
Contact: Website

Re: Apache tuning?

Sat Dec 29, 2012 9:06 am

benthepoet wrote:Yeah, you'll definitely want to install php-apc. This will improve response times and dramatically cut down on CPU load.
^^^ so much this. everyone running any php should definitely be considering this. the only time I do not install this is if I am using wordpress - in which case I go with http://wordpress.org/extend/plugins/wp-super-cache/ instead to enable the best possibe maxclients.

in raspbian apc is really easy. as root: apt-get install php-apc

then open /etc/php5/conf.d/20-apc.ini and add the following lines:

extension=apc.so
apc.enabled=1
apc.shm_size=12M*

* where this is the size of your desired cache

apachectl restart

then the finishing touch and the coolest part is to first check its working by creating a php.php info file in you web root ie /var/www/php.php and copy/paste:

<?php
phpinfo();
?>

save, visit in browser to see your php info. there should now be a section called 'apc' a few scrolls down.

now that cool bit. cd to /usr/share/doc/php-apc and edit apc.php. put in a password of your choosing. then save and cp that to your web root and visit for awesome stats/info on what is cached and tools to clear/modify entries. :D

nb: remember to move the script out of your web root or to a deny all folder for security when you're done. same with php.php!

permaband
Posts: 62
Joined: Wed Aug 01, 2012 2:14 pm
Location: uk
Contact: Website

Re: Apache tuning?

Mon Dec 31, 2012 12:38 pm

I did a little more reading and added a little more to my config file:

extension=apc.so
apc.enabled=1
apc.shm_size=12M
apc.ttl=259200 (3 days)
apc.stat=1 (I have this on as I am still tweaking my php forum code regularly)

http://php.net/manual/en/apc.configuration.php

apc.ttl= The number of seconds a cache entry is allowed to idle in a slot in case this cache entry slot is needed by another entry. Leaving this at zero means that APC's cache could potentially fill up with stale entries while newer entries won't be cached. In the event of a cache running out of available memory, the cache will be completely expunged if ttl is equal to 0. Otherwise, if the ttl is greater than 0, APC will attempt to remove expired entries.

apc.stat=1 Be careful changing this setting. This defaults to on, forcing APC to stat (check) the script on each request to determine if it has been modified. If it has been modified it will recompile and cache the new version. If this setting is off, APC will not check, which usually means that to force APC to recheck files, the web server will have to be restarted or the cache will have to be manually cleared. Note that FastCGI web server configurations may not clear the cache on restart. On a production server where the script files rarely change, a significant performance boost can be achieved by disabled stats.

For included/required files this option applies as well, but note that for relative path includes (any path that doesn't start with / on Unix) APC has to check in order to uniquely identify the file. If you use absolute path includes APC can skip the stat and use that absolute path as the unique identifier for the file.

hth

giovani
Posts: 17
Joined: Fri Sep 06, 2013 6:38 am
Location: Rome, Italy
Contact: Website

Re: Apache tuning?

Tue Dec 17, 2013 9:20 am

permaband wrote:I did a little more reading and added a little more to my config file:
extension=apc.so
apc.enabled=1
apc.shm_size=12M
apc.ttl=259200 (3 days)
apc.stat=1 (I have this on as I am still tweaking my php forum code regularly)
[...]
hth
Hi, could you share what is your average hit rate per second on APC using this setup and OwnCloud (while Owncloud is synchronizing) ?

I have a apc.shm_size = 30M and a ttl of 10 days, I am getting around 320hits/second and avoiding disk swap (my php.ini max memory is set to 200M). I wonder if this is the maximum we can get out of the Pi Model B for a webserver-only performance:

Code: Select all

General Cache Information
APC Version	3.1.13
PHP Version	5.4.4-14+deb7u7
APC Host	raspberrypi
Server Software	Apache
Shared Memory	1 Segment(s) with 30.0 MBytes (mmap memory, pthread read/write Locks locking)
File Upload Support	1

File Cache Information
Cached Files	310 ( 6.0 MBytes)
Hits	12934620
Misses	310
Request Rate (hits, misses)	323.50 cache requests/second
Hit Rate	323.50 cache requests/second
Miss Rate	0.00 cache requests/second
Insert Rate	0.00 cache requests/second
Cache full count	0

User Cache Information
Cached Variables	228 (130.0 KBytes)
Hits	11095013
Misses	99669
Request Rate (hits, misses)	221.50 cache requests/second
Hit Rate	220.24 cache requests/second
Miss Rate	2.26 cache requests/second
Insert Rate	2.26 cache requests/second
Cache full count	0

Runtime Settings
apc.cache_by_default	1
apc.canonicalize	1
apc.coredump_unmap	0
apc.enable_cli	0
apc.enabled	1
apc.file_md5	0
apc.file_update_protection	2
apc.filters
apc.gc_ttl	864000
apc.include_once_override	0
apc.lazy_classes	0
apc.lazy_functions	0
apc.max_file_size	10M
apc.mmap_file_mask
apc.num_files_hint	1000
apc.preload_path
apc.report_autofilter	0
apc.rfc1867	0
apc.rfc1867_freq	0
apc.rfc1867_name	APC_UPLOAD_PROGRESS
apc.rfc1867_prefix	upload_
apc.rfc1867_ttl	3600
apc.serializer	default
apc.shm_segments	1
apc.shm_size	30M
apc.shm_strings_buffer	4M
apc.slam_defense	1
apc.stat	1
apc.stat_ctime	0
apc.ttl	863000
apc.use_request_time	1
apc.user_entries_hint	4096
apc.user_ttl	86300
apc.write_lock	1

Return to “Networking and servers”