Easy AWS scalability with PHP and Linux Server Monitor Agents

By Posted in Tech Topics, Using Our Products 30 August 2013

This article was written by Walden Bodtker, Tech Support Engineer

Amazon’s AWS Elastic Beanstalk is a fantastic, scalable infrastructure that more and more people are relying on New Relic for application monitoring. If installed correctly, a user’s application will effortlessly scale to fit their production needs. The optimal way to do this is through a series of commands that execute when the new EC2 instance is spawned.

Amazon’s deployment system uses AWS command line utilities to push revisions to server instances. This functions essentially the same way that git does, but with a few extra steps. You still initialize add and commit as you normally would, but following that you’d use the AWS command line utilities and then initialize and start their EC2 instance. When you start the instance, it will prompt to push your latest commit. If you’ve created a folder “.ebextensions” at the base directory of your application, you can then place yml formatted config files into the directory and Elastic Beanstalk will execute the commands when the instance is loading. Please be aware, however, that commands entered here have to follow this structure:

* Packages
* Files
* Commands
* Services
* Container Commands

The YML parser skips the character “0″ in the commands section, so numbers should be wrapped in quotes to ensure functionality. It’s also important to note the indentation of the lines as the config file will not parse correctly if the spacing is wrong. Using this method, you can scale an application to fit your needs with our PHP and Linux Server Monitor agents compiling and starting when the instance is spawned.

Once the application is built and ready to push, you should save a script as “filename.config” with the following contents to their .ebextensions folder:

example.config

packages:

  yum:

    newrelic-php5: []

    newrelic-sysmond: []

  rpm:

    newrelic: http://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm

commands:

  "01":

    command: newrelic-install install

  env:

    NR_INSTALL_SILENT: true

    NR_INSTALL_KEY: NewRelicLicenseKey

  "02":

    command: echo newrelic.appname="NameOfYourApp" >> /etc/php.ini

  "03":

    command: nrsysmond-config --set license_key=NewRelicLicenseKey

  "04":

    command: /etc/init.d/newrelic-sysmond start

This should be saved. When the AWS instance is loading it will read all of the config scripts in the .ebextensions directory in alpha-numeric order, and multiple scripts can be loaded in succession.

In the above script, the packages section searches for the latest version of the package in our repo because of the double brackets [ ]. Following that, the first two commands are used specifically for the PHP agent. Notice we are telling the newrelic-install command to run in silent mode since this will be unattended. The last two commands are for the Linux System Monitor, and can install without any special instruction. Provided that the license key is set and the monitor is told to run in the config file, you should have a great experience with scalability that automatically updates as your needs grow.

This example is good for simultaneously installing both the PHP agent and the LSM. You can remove the lines newrelic-php5: [] and the commands “01” and “02” to only install the server monitor, or remove the newrelic-sysmond: [] and commands “03” and “04” to install the PHP agent only.

Be sure to take a look at the following docs for more information:

* Develop, Test and Deploy
* Customizing the Software on EC2 Instances Running Linux
* Connecting to Your Linux/Unix Instances Using SSH

About the author

walden@newrelic.com'

Tell us your thoughts Or Send us an internal high five

Talk to @newrelic