Tune & Test a LAMP stack. Tally the perks.
Hosting a Linux server with Apache2, MySQL, and PHP is a common setup, enough to where it has attained its own acronym and identity: it’s called a LAMP stack. Each of these four software components is essential for hosting a website. And each is tunable to match your specific needs; but frequently, users forget to take advantage of these actions.
Tuning your server to take advantage of its resources will help with uptime, increase the maximum concurrent users, and provide a speedier service.
Quite often the configurations acquired on installation are left at those starting values. While these defaults typically work, they don’t allow the server to reach its full capacity.
For example, tweaking your Apache2 configurations will dictate how many people can access your site and how its resources are allocated. Configuring your MySQL will determine its resource allowance, as well. Tuning PHP will let you alter the maximum allowable file size that can be downloaded in a single attempt.
You can choose many methods by which to tweak these services. Among them are many formulaic paths to consider traveling. Or not. There is an easier way than having to do the math: Run a tuning script.
The particular tuning scripts I recommend are Apache2Buddy and MySQLTuner. (I haven’t had to tune PHP aside from changing the memory limit value around from 128MB to 256MB.)
I recommend first running Apache2Buddy and then MySQLTuner afterwards. These scripts will look at your configurations and then suggest changes in regards to available server resources.
Here’s a screenshot of recommended changes after running them:
Apache2buddy
Mysqltuner
One fantastic way to check how well your configured server would handle traffic is by load testing it with a tool, like Siege. You can control how many concurrent users are being tested, how long it runs and how often it hits — just about anything you need to get a good idea on how well your server would work under pressure. You can find our guide on Siege here.
For example, I’ve configured my server to only serve a small number of users, prohibiting an excessive amount of users at one time. I then run Siege to show how many users it could actually handle at an instance.
I then tuned my server using Apache2Buddy and followed this with MySQLTuner, setting the recommendations shown in the examples above. Finally, I reloaded the services and ran Siege again.
As you can see, the numbers indicate quite a massive jump in concurrent users. However, most servers will not register such a dramatic increase — my example jumped from a pathetically bad setting to a very good one for a static page. Nevertheless, most users definitely should see a difference when tuning their configurations effectively.
(Please note that these scripts provide general tuning, specific enhancements will depend on the nature of the content being served.
If you want to tune the Apache2 configuration manually, give Answer 1 at this serverfault forum a look. This answer is for an older instance of Ubuntu, such as 12.04, but this information should be still useful. One thing to keep in mind is that prefork maxclients has been replaced with maxrequestworkers.)
Because several decisions go into making the best setup, the only person who can really make the tuning call is someone who is intimately knowledgeable about the server, someone who understands the stress it’ll go through and what resources it has available. If you manually run equations on how to best configure your server, then you probably don’t need to use any of these third-party scripts (but Siege remains invaluable).
Configuring your server to make best use of your resources can exponentially increase the amount of users accessing your service as well as increase its reliability. As a nice little bonus, this means you probably don’t need to upgrade that suspiciously slow server, keeping more money in pocket. Aside from saving some money, tuning your server to use the right amount of resources can keep it running longer and prevent issues, such as running out of memory (OOM).
With tools like Apache2Buddy and MySQLTuner to help tune your server and Siege to help load test, achieving better uptime, accommodating more users at once, and saving money - a trio of sweet perks for your efforts - become more easily attainable.
Have any questions or comments about tuning your LAMP stack? Feel free to jot your ideas down in the comments section below or send me a message on Twitter @feelingsohsoh.