Tell me more ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This is a Canonical Question about Securing a LAMP stack

What are the absolute guidelines for securing a LAMP server?

share|improve this question

2 Answers

David's answer is a good baseline of the general principles of server hardening. As David indicated, this is a huge question. The specific techniques you take could depend highly on your environment and how your server will be used. Warning, this can take a lot of work in a test environment to build out and get done right. Followed by a lot of work to integrate into your production environment, and more importantly, business process.

First, however, check to see if your organization has any hardening policies, as those might be the most directly relevant. If not, depending on your role, this might be a great time to build them out. I would also recommend tackling each component separately from the bottom up.

The L
There are lots of good guides available to help you out. This list may or may not help you depending on your distribution.

The A
Apache can be fun to secure. I find it easier to harden the OS and maintain usability than either Apache or PHP.

The M

The P
This runs headlong into the whole idea of Secure Programming Practices, which is an entire discipline of its own. SANS and OWASP have a ridiculous amount of information on the subject, so I won't try to replicate it here. I will focus on the runtime configuration and let your developers worry about the rest. Sometimes the 'P' in LAMP refers to Perl, but usually PHP. I am assuming the latter.

share|improve this answer
1  
I want to up vote this answer at least 10 times. – user58859 Jan 24 '11 at 16:32
3  
The silent N - With either IPTables or an external firewall, block network connections to only what is necessary for the public to access. – mindthemonkey Aug 28 '12 at 21:03

You've asked a question that is, quite frankly, worthy of a few books on the topic. But there are some general basic guidelines that work well:

  1. Keep Updated. This means the OS, all services, and ESPECIALLY all webapps you're running.
  2. Disable any unneeded services, limit those that are needed to the minimum exposure (if you're not remotely connecting to MySQL, then don't have it listening on TCP), and run a host-based firewall. (If it's strictly LAMP, you should be good with 80 and 443, but maybe SSH as well for administration.))
  3. Use strong passwords. Better yet, if you use SSH, use only key-based auth.
  4. Make sure you're not logging in as root. Log in as users and use su & sudo.
  5. While it doesn't make things more secure, you should run tools like logwatch so you're aware of what's happening on your server.

Hope that helps you get started.

share|improve this answer
Thanks this gives me a good start. – Aditya Shukla Dec 14 '10 at 2:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.