Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Apache, Mysql, and PHP configuration and optimization [HELP]
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Apache, Mysql, and PHP configuration and optimization [HELP]

I am running a 512mb RAM, 1 core, 20GB SSD VPS from Digital Ocean.

First off, please don't tell me to use the lowendscript, it uses nginx. I need to run Apache for my WordPress websites. Yes I have tried running ngnix and php-fpm. I had a heck of a time setting them up without the script (spent 15+ hours), and I hate running scripts without understanding what they are doing. I prefer Apache because I need the .htaccess support, I run WordPress websites, and I like the configs/virtual host setup. Plus, with a 512mb box, I feel that I should be able to handle Apache.

I need help optimizing my server. If you need to see any of my configs let me know, i'll gladly upload it to pastebin. Oh, and I also have APC installed and no WP cache plugins installed.

I am testing my site with blitz.io. Right now my server can only handle 40ish users when aimed at the homepage of my WP site >>> https://www.blitz.io/report/65ba0ec5762aa86f17185bfda7065f91 and 240+users when aimed at a static site.
https://www.blitz.io/report/65ba0ec5762aa86f17185bfda725d5ca

I've hired two sysadmins and they don't know what to do.

Comments

  • MunMun Member

    Okay,

    so apache won't be of much help to you as it can only handle ~125 concurrent connection by default and you really shouldn't push it more then that.

    Nginx is a far better solution, and you could just put it in front for caching mode, or install varnish.

    I also suggest you install "quick Cache" for wordpress.

    I run nginx for my wordpress installs on Nginx with no issue:

    http://www.gaming-servers.net/
    http://www.lowendhelp.com/

  • marshallfordmarshallford Member
    edited June 2013

    what do you mean Apache can only handle 125 concurrent connections? What about big websites running apache?

    Anyway, thanks for the tips. I just hate all of the junk in the nginx configs with php-fpm and such.

    Question: Suggestions for most updated lowendscript?

    Update: Wow! The Quick Cache plugin helped a ton! Thanks man. I was taught to not rely on those kinds of plugins, but it really helps! I handled 250+users a second!

  • vanarpvanarp Member
    edited June 2013

    @marshallford said:
    Update: Wow! The Quick Cache plugin helped a ton! Thanks man. I was taught to not rely on those kinds of plugins, but it really helps! I handled 250+users a second!

    Did you ever try W3 Total Cache plugin? By enabling Object Cache (APC), Database Cache (APC) and Page Cache (Disk Enhanced) you should be getting some very good performance. To improve Google Page Speed score you need to enable Browser Cache too.

  • bcrlsnbcrlsn Member
    edited June 2013

    Use jsdelivr for all the css and js files. Their is even a wordpress plugin - http://wordpress.org/extend/plugins/jsdelivr-wordpress-cdn-plugin/

  • @Mun said:
    so apache won't be of much help to you as it can only handle ~125 concurrent connection by default and you really shouldn't push it more then that.

    This is a config option you can easily change :-)

    @marshallford said:
    what do you mean Apache can only handle 125 concurrent connections? What about big websites running apache?

    Apache can be optimized a lot. The defaults are what they are: defaults. Apache can be a beast. It's almost always wise to use the MPM worker and not the prefork module. If you've got Apache 2.4, you can even use the MPM event module, which handles requests similar to nginx (event-driven).

  • MunMun Member

    ~ the 125 statement is yes the default, but still it is a good number. On my old dedi more then 125 would kill the node.

    Also you still probably want to setup a varnish front end. Make the site not only snappy but handles caching much much better.

  • Thanks everyone for the suggestions!

    1. I have played with the apache configs and used a script to determine my max clients number.

    2. I've been told to stay away from Worker when using WordPress/PHP.

    3. The WordPress plugin looks great, however does it automatically switch out the jquery that WordPress needs without loading it multiple times? In the past I have had lots of issues with loading my own copy of jquery and such. WP wants you to use enqueue to load js.

    4. Just ran Yslow and I got a 96/100! Question: How do I implement expires headers easily with Apache?

    Again, thanks for all of the suggestions!

  • MunMun Member
    edited June 2013

    @marshallford said:
    Thanks everyone for the suggestions!

    1. I have played with the apache configs and used a script to determine my max clients number.

    2. I've been told to stay away from Worker when using WordPress/PHP.

    3. The WordPress plugin looks great, however does it automatically switch out the jquery that WordPress needs without loading it multiple times? In the past I have had lots of issues with loading my own copy of jquery and such. WP wants you to use enqueue to load js.

    4. Just ran Yslow and I got a 96/100! Question: How do I implement expires headers easily with Apache?

    Again, thanks for all of the suggestions!

    4 = varnish

  • The worker is actually faster for PHP in my experience. Mostly used in combination with fcgi or fpm, since mod_php is also a resource hog.

    Just out of curiosity: where did you read/got told otherwise?

    By the way: nice to have some discussions about these kinds optimalizations here!!

  • MunMun Member

    @mpkossen who is this directed at?

  • MunMun Member
    edited June 2013
    ` Server Software:        nginx/1.4.1
    Server Hostname:        www.lowendhelp.com
    Server Port:            80
    

        
    Document Path: /
    Document Length: 24260 bytes
        
    Concurrency Level: 500
    Time taken for tests: 5.678 seconds
    Complete requests: 10000
    Failed requests: 0
    Write errors: 0
    Total transferred: 246660000 bytes
    HTML transferred: 242600000 bytes
    Requests per second: 1761.13 [#/sec] (mean)
    Time per request: 283.908 [ms] (mean)
    Time per request: 0.568 [ms] (mean, across all concurrent requests)
    Transfer rate: 42421.94 [Kbytes/sec] received
        
    Connection Times (ms)
    min mean[+/-sd] median max
    Connect: 11 30 101.5 14 1037
    Processing: 56 182 287.2 102 3703
    Waiting: 34 120 238.4 58 2790
    Total: 67 211 307.1 128 4423
        
    Percentage of the requests served within a certain time (ms)
    50% 128
    66% 148
    75% 161
    80% 169
    90% 360
    95% 1101
    98% 1292
    99% 1359
    100% 4423 (longest request)
        
    `

    That is with nginx, some caching techniques and a few other things

  • MunMun Member

    someone fix it so its code C:<

  • AbdussamadAbdussamad Member
    edited June 2013

    A control panel less 512MB RAM LAMP server can support around 30-40 simultaneous Apache prefork processes serving dynamic pages and associated static content. But that is not the same as 40 users. The number of users will be higher because not all of them will be using the server's resources at the exact same time (some will be reading too).

    Unless you are expecting a lot of traffic in a short period of time (bursty traffic) 30-40 processes should be more than enough. For most websites traffic is spread out over many hours.

    Another thing, you are correct that prefork MPM is your only option if you want to use mod_php. The reason is that there is question mark about the thread safety of some PHP extensions so it is not safe to run them under worker or event MPM.

    In case you are wondering mod_php is definitely the way to go on a single user server. In such a scenario it is actually more secure than PHP running under PHP-FPM or fastcgi and faster. On shared hosting fastcgi/php-fpm is safer.

    Anyway if you want further help I can take a look at your server or you can DIY:

    http://abdussamad.com/archives/535-Apache-MaxClients.html

    http://abdussamad.com/archives/169-Apache-optimization:-KeepAlive-On-or-Off.html

  • marshallfordmarshallford Member
    edited June 2013

    @mpkossen said:
    Just out of curiosity: where did you read/got told otherwise?

    I've been told by various people on irc (DO's channel and Frantech) that php should be run threaded and that WordPress can create memory leaks which prefork can stop.

    Edit: I've also gone ahead and uploaded a phpinfo file and my apache2 conf to my keys server for those interested at viewing my current settings.

    http://keys.marshallford.me

  • @Abdussamad said:
    Unless you are expecting a lot of traffic in a short period of time (bursty traffic) 30-40 processes should be more than enough. For most websites traffic is spread out over many hours.

    My main traffic comes from when I submit one of my articles to HackerNews, so I want to be ready for bursts.

    I have max clients (which means number of processes right?) set at 20.

  • MunMun Member

    if you install varnish then ignore the next bit, but if you don't change keepAlive off to on.

  • marshallfordmarshallford Member
    edited June 2013

    After taking a look at http://tuxlite.com I am really considering scraping my current setup and using the script to install php-fpm and such.

    However several people have stated that mod_php is better for single server setup's like the one I have, while both apache and nginx would use php-fpm when I run the tuxlite script.

    To be honest, besides setting up the basics of my server (which I can now do much faster now that I understand what I am doing and what it means) I have only really installed wordpress and configured it (plugins and database stuff).

    Should I backup my vhosts and trying the script and install vanish with it too? I notice it also uses the event mpm. Is this safe with php/wordpress?

    Sorry for such long posts!

  • jcalebjcaleb Member

    i suggest get another cheap vps and play around with it for some configurations

  • @jcaleb said:
    i suggest get another cheap vps and play around with it for some configurations

    I can boot up a DO instance and pay for it hourly, great idea mate.

  • jcalebjcaleb Member

    for optimizing, i wish to suggest having a cache in front of your apache. like varnish or others. then maybe you dont need wordpress cache plugin

  • jcalebjcaleb Member

    i read redis is also nice and easy to setup

  • @marshallford said:
    I've been told by various people on irc (DO's channel and Frantech) that php should be run threaded and that WordPress can create memory leaks which prefork can stop.

    I don't know about the memory leaks (as in: never had them), but prefork is the non-threaded "version" of apache. The worker is the threaded one. I've been running WordPress for over five years on several servers where PHP runs through FastCGI and I've never had any memory issues. I'm just a bit surprised at what people are telling you. Did they cite sources? I'd like to know if this configuration can result in memory leaks.

    @marshallford said:
    However several people have stated that mod_php is better for single server setup's like the one I have, while both apache and nginx would use php-fpm when I run the tuxlite script.

    mod_php is definitely the easiest option and if it doesn't bother you performance-wise, it's definitely not a bad option. Both fastcgi and php-fpm have a more complex setup.

    @marshallford said:
    Sorry for such long posts!

    No worries! Yours are not long :-)

  • @mpkossen said:
    The worker is the threaded one.

    My bad, I had that mixed up.

    Any opinions on apache 2.2 with the event mpm? I may look into that as an alternative to using the tuxlite script.

  • MunMun Member
    edited June 2013

    Hmmm are you running an older OS version as 2.4.4 is out with a ton of improvements.

    http://httpd.apache.org/

  • @marshallford said:
    Any opinions on apache 2.2 with the event mpm? I may look into that as an alternative to using the tuxlite script.

    Haven't tried it myself, but from what I read, 2.4 has a more stable event MPM than 2.2.

  • MunMun Member

    plus better memory use and other nice fixes.

  • Hmmm, i'll have to upgrade then. Can you add a repo or do you need to install it from source?

  • @marshallford said:
    Hmmm, i'll have to upgrade then. Can you add a repo or do you need to install it from source?

    Well, upgrading to ubuntu 13.04 from 12.10 works.

Sign In or Register to comment.