Installing Nginx/Apache, MySQL, PHP 5.5 (LAMP) stack on CentOS 6.4
With the wide-spread appeal and flexibility of an VPS and Vagrant, a shift from mear FTP access to setting up a fresh installation from scratch has taken effect.
Tools like Puppet and Chef are great for certain use-cases (i.e. large deployments, dev-ops teams) but to start with the terminal is your best-friend.
In this post I will take you through the process of setting up a trival LAMP stack on CentOS 6.4, with the option to use either Apache or Nginx.
Both will take advantage of the features PHP-FPM provides you, via FastCGI.
The first step is to make sure we are currently the ‘root’ user (this saves on tedious sudoing through the installation).
We then add the EPEL and Remi YUM repositories, providing us with easy access to updated MySQL and PHP pre-compiled builds.
Installation of the MySQL server and client is the next step, followed by configuring the associated daemon to run on start-up.
It is then good practise to run the ‘secure installation’ script, which guides you through changing the root password etc.
Next we are going to install PHP 5.5 along with a host of useful packages (i.e. the new Zend OPcache).
Running the second command is useful if you wish to find other available packages.
Finally, we run a couple of commands which use ‘sed’ to quickly alter highlighted configuration in PHP.
We are then tasked with configuring the previously installed PHP-FPM, along with adding it to run on start-up.
If you wish to install Nginx you must also execute the last two commands, which correct the desired user/group settings used.
Option 1: Nginx
I am a huge fan of Nginx and would definitely recommend it over Apache even if just for its exceptional low-memory footprint.
First we must add the YUM repository and then install/configure Nginx to run at start-up.
We can then replace the inital configuration file provided at ‘/etc/nginx/conf.d/default.conf’ with the one below.
This is a trivial configuration that should help you get up-and-running, I would recommend however, that you take a look at the great work here for more ideas.
Option 2: Apache
Alternatively, you may prefer the extra modules and familiarity of Apache.
Below we are simply installing the Apache package provided in the official repository, along with enabling it at start-up.
We have to go through one extra step to successfully get Apache to use PHP-FPM.
To achieve this we must install the ‘mod_fastcgi’ module along with safely disabeling a couple of default configuration files.
We can then create a new file ‘/etc/httpd/conf.d/default.conf’ with the contents below to get up-and-running.
This configuration is very trivial, I would recommend that you take a look at the great work here for more ideas.
I tend to store my web content under ‘/srv/www’, and the example configuration files use this preference.
If you have another preference remember to update the configuration files accordingly.
It is very important to have a well configured firewall that meets you business-domain needs, the below configuration is a good start.
I will not go through each line but this helps handle common script-kiddie attacks along with accepting activity on ports 80/443/22 (http, https and ssh).
Who in the PHP world can now live without Composer?
3, 2, 1, Go…
I hope that this brief overview has helped you get accustom with configuring a base installation, allowing you to take advantage of the flexiablity gains.
I have purposely omitted detailed discusion on logging and advanced web-server configuration, as I feel they deserve their own posts and hope to fulfill this in the near future.