We generally expect questions to be reasonably scoped. You can write whole books about securing servers, stacks etc. - that's the reason why your question was closed - it's way too broad. 

Having said that we have an [excellent canonical Q&A][1] on securing a LAMP server which would be a good place to start. Once you've done that then you could also work your way through the Q&A in [this search][2]. 


  [1]: https://serverfault.com/questions/212269/tips-for-securing-a-lamp-server
  [2]: https://serverfault.com/search?q=securing%20LAMP