Installing Node.js, Nginx, PHP 5.6 & MongoDB on an Amazon Linux AMI EC2 Instance

This guide gives step-by-step instructions for installing Node.js, Nginx, PHP 5.6 and MongoDB on an AWS EC2 instance running the Amazon Linux AMI. If you notice any errors, changes or have suggestions for alternatives/clarifications, please let me know.

Assumptions

This guide assumes that you are familiar with Amazon Web Services and using the Linux command line. This guide also assumes that you are performing these tasks on a fresh Amazon Linux AMI instance.

Setup

This guide was written using a fresh Amazon EC2 instance with the following configuration:

  • Instance type: t2.micro
  • Operating System: Amazon Linux AMI 2015.09.1 (HVM), SSD
  • Storage: 8GB (default)

If you are using a newly-created instance, don’t forget to install the latest updates:

Protect your web content with a free dmca.com protection badge

Node.js & NPM

This section shows the commands used to install and update Node.js and NPM.

Install Node.js and NPM

Update Node.js (if necessary)

Update NPM to Latest Version

Nginx & PHP 5.6

This section shows the commands used to install and configure Nginx.

Install Nginx

Configure Nginx

Open the following file with the text editor of your choice:

Paste the following lines:

Install PHP 5.6 & Some Extensions

Install MongoDB PHP Extension

Open the following file with the text editor of your choice:

Add the following line to the Dynamic Extensions section:

Install and Configure PHP-FPM

Open the following file with the text editor of your choice:

Modify the following lines as necessary to appear like these:

Grant Nginx permission to the PHP-FPM socket file:

A2 Hosting - Up to 20x Faster

MongoDB

This section shows the commands used to install MongoDB.

Add Repository

Open the following file with the text editor of your choice:

Add the following lines:

Install MongoDB

Start Services

To start the services you just install manually, run the following commands:

To configure these services to start automatically when the server restarts, run these commands:

You are now ready to start building your application.

Leave a Reply

Your email address will not be published. * Denotes required field.
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Tip: Do you want an image (avatar) next to your posts? Sign up for a free Gravatar account. It only takes 5 minutes - simply click the "Create Your Own Gravatar" button, provide your e-mail address and upload a photo to associate with it.