Over a million developers have joined DZone.

Easy AWS scalability with PHP and Linux Server Monitor Agents

· Performance Zone

See Gartner’s latest research on the application performance monitoring landscape and how APM suites are becoming more and more critical to the business, brought to you in partnership with AppDynamics.

This article was written by Walden Bodtker, Tech Support Engineer at New Relic.

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:


    newrelic-php5: []
    newrelic-sysmond: []
    newrelic: http://yum.newrelic.com/pub/newrelic/el5/x86_64/newrelic-repo-5-3.noarch.rpm
    command: newrelic-install install
    NR_INSTALL_KEY: NewRelicLicenseKey
    command: echo newrelic.appname="NameOfYourApp" >> /etc/php.ini
    command: nrsysmond-config --set license_key=NewRelicLicenseKey
    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 that 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

The Performance Zone is brought to you in partnership with AppDynamics.  See Gartner’s latest research on the application performance monitoring landscape and how APM suites are becoming more and more critical to the business.


Published at DZone with permission of Leigh Shevchik, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}