Press "Enter" to skip to content

Richy's Random Ramblings

New Relic, cPanel, Apache and FastCGI PHP

We tend to operate RedHat Enterprise/CentOS based cPanel web hosting accounts for ourselves and our customers and for security, they are configured running PHP under suPHP via CGI/FastCGI. However, for server monitoring, we wanted to be able to use NewRelic for monitoring the sites on an individual level but without the customers having to add newrelic.appname to each of their applications – and we didn’t want each site to have to have its own php.ini, and under suPHP PHP ignores any php_value settings in the Apache configuration. So what to do?

Install New Relic
Well, first of all install New Relic according to your server architecture, then run “newrelic-install” and select all. Now we move on to the cPanel specific setup.

Getting PHP to notice the NewRelic PHP Module
In WHM (:2087), select “PHP Configuration Editor” and then “Advanced mode”. Search for Core “extension” and change the list from something like:
/usr/lib/php/extensions/no-debug-non-zts-20090626/apc.so, pdo.so, pdo_sqlite.so, sqlite.so, pdo_mysql.so, timezonedb.so, uploadprogress.so
to:
/usr/lib/php/extensions/no-debug-non-zts-20090626/apc.so, pdo.so, pdo_sqlite.so, sqlite.so, pdo_mysql.so, timezonedb.so, uploadprogress.so, newrelic.so

Restart Apache (via either WHM or /scripts/restartsrv_apache on the command line) and check everything is still working.

Configuring the newrelic.appname settings – Apache
From from command line/shell, cd into /var/cpanel/templates/apache2_2 (or whichever version of Apache you are running) and copy vhost.default to vhost.local (cp vhost.default vhost.local) if there isn’t already a vhost.local file. Now open that file up in your favourite text editor (for simplicities sake, I’m using nano : nano -w /var/cpanel/templates/apache2_2/vhost.local).

Near the top of the file it will say something like:

<VirtualHost[% FOREACH ipblock IN vhost.ips %] [% ipblock.ip %]:[% ipblock.port %][% END %]>
ServerName [% wildcard_safe(vhost.servername) %]
[% IF vhost.serveralias_array.size -%]
[% FOREACH alias IN vhost.serveralias_array -%]
ServerAlias [% alias %]
[% END -%]

Add a suitable “SetEnv newrelic_appname” line. For example, I want all of the sites to be recorded against the main virtual host’s server name, so I would use:

<VirtualHost[% FOREACH ipblock IN vhost.ips %] [% ipblock.ip %]:[% ipblock.port %][% END %]>
ServerName [% wildcard_safe(vhost.servername) %]
SetEnv newrelic_appname [% wildcard_safe(vhost.servername) %]
[% IF vhost.serveralias_array.size -%]
[% FOREACH alias IN vhost.serveralias_array -%]
ServerAlias [% alias %]
[% END -%]

You could also use the user’s username SetEnv newrelic_appname [% % vhost.user %] if you wanted to.

Use the Distiller to check everything looks good:
/usr/local/cpanel/bin/apache_conf_distiller --update
and if it does, rebuild the Apache configuration:
/usr/local/cpanel/bin/build_apache_conf
and again restart Apache and test.

Now, there is an environment variable called “newrelic_appname” available for usage. But we’re not using it yet: so we move onto:

Configuring the newrelic.appname settings – PHP
Using a <?php phpinfo(); ?> script find where your php.ini file – ours was in /usr/local/lib/php.ini . Open it open in your text editor again (nano -w /usr/local/lib/php.ini) and search for the newrelic.appname setting which should appear (Press Ctrl+W and then type appname in nano). You should see something like:

; Setting: newrelic.appname
; Type : string
; Scope : per-directory
; Default: “PHP Application”
; Info : Sets the name of the application that metrics will be reported into.
; This can in fact be a list of up to 3 application names, each of
; which must be separated by a semi-colon. The first name in any such
; list is considered the ‘primary’ application name and must be unique
; for each account / license key.
;
;newrelic.appname = “PHP Application”

;
; Beginning with version 3.0 of the agent, the daemon can be automatically
; started by the agent. There is no need to start the daemon before starting

Remove the colon and the start of the line and change it to read from ${newrelic_appname} for example:

; for each account / license key.
;
newrelic.appname = “${newrelic_appname}”

;
; Beginning with version 3.0 of the agent, the daemon can be automatically

This will read in the newrelic_appname environment variable upon run and dynamically replace it in the PHP settings. Restart Apache again (just to be safe) and check a few sites are working. Within a couple of minutes, you should see the records appear in NewRelic.

All done! Have fun!

Android: Fixed: Google Play Store not working/crashing?

For the last few days, I’ve been having a problem with my Samsung Galaxy S II mobile phone running Android 4.1.2 (JellyBean) in that the Google Play store (which is used to download/update apps) just kept crashing. Sometimes it’ll load and showing a “Loading” screen before turning black and closing, other times it’ll just flash a black screen. I also got the “com.google.process.gapps has stopped working” when restarting the phone.

I did try going into Settings->Application Manager and stopping the Play Store, clearing the cache, uninstalling the updates: all with the same results. What did fix it however, was going into Settings->Application Manager selecting “All” finding “Download Manager” (which was right at the bottom of the alphabetical list!) and selecting “Enable” (for some reason, it was disabled). Reopen the Google Play Store and all seems well.

I’ve got no idea why the “Download Manager” became disabled nor why the Android PlayStore uses it.

[Techy] localdomain settings in Linux Mint using DNSMasq

If you are developing websites on Linux Mint, then you might want to set a DNS Wildcard so that anything on localdomain (*.localdomain) resolves to your machine (i.e. test.localdomain , anything.localdomain). So how can you do this?

First of all, you need to install dnsmasq “a lightweight, easy to configure DNS forwarder and DHCP server”, this can be simply done using:
sudo apt-get install dnsmasq

Now you just need to configure it. Create a file in /etc/dnsmasq.d/ using something like nano, pico, vi, emacs :

sudo nano -w /etc/dnsmasq.d/localdomain.conf

with the following settings:

address=/localdomain/127.0.0.1
listen-address=127.0.0.1

This will tell DNSMasq to setup a wildcard for everything on “localdomain” to point to 127.0.0.1 and to listen for DNS requests on 127.0.0.1. Now just restart DNSmasq:
sudo service dnsmasq restart
and you are nearly done.

You now just need to change your DNS servers in network manager. On the Linux Mint task bar, right click on the network icon and select “Edit connections” and edit the connection you are using. Select “IPv4 Settings”. If you have “Automatic (DHCP)” selected, change it to “Automatic (DHCP Addresses only)”. Then add the DNS server 127.0.0.1 and others of your choosing (such as the Google 8.8.8.8 and 8.8.4.4 ones). All should now be working!

Magento: Class Zend_log not found in GoMage Lightcheckout Help file

Do you receive an error message such as:

Fatal error: Class 'Zend_Log' not found in /.../app/code/local/GoMage/Checkout/Block/Adminhtml/System/Config/Fieldset/Help.php on line 48

when running the GoMage Lightcheckout v3.1 plugin for Magento? If so, it’s a quick fix: just open up that file and remove the section:

protected function _getFieldsetCss()
{
$configCss = (string)$this->getGroup()->fieldset_css;
return 'config collapseable'.($configCss ? ' ' . $configCss : '');
}

and your Magento ecommerce shop should start working! (Basically, in a recent version of Magento CE – version 1.7.0.2 or before – that method was set as “protected” in Mage_Adminhtml_Block_System_Config_Form_Fieldset and so the child class GoMage_Checkout_Block_Adminhtml_System_Config_Fieldset_Help was not able to redeclare it).

Magento: Associating customer accounts

If you run a Magento e-commerce store, you may occasionally find existing customers placing orders without being logged into their account. This isn’t a problem usually, unless the customer is one of those vary rare ones which actually logs into the customer frontend to track/check their order(s). If they weren’t logged in, they won’t see the ecommerce order.

So how do you fix this? Well, there is a Magneto module available to do this, but (as is increasingly common in the Magento world) it costs $99. Or there is my way which is free and requests two SQL statements:

UPDATE sales_flat_order, customer_entity
SET sales_flat_order.customer_id=customer_entity.entity_id
WHERE
sales_flat_order.customer_email=customer_entity.email

UPDATE sales_flat_order_grid,sales_flat_order
SET sales_flat_order_grid.customer_id=sales_flat_order.customer_id
WHERE
sales_flat_order_grid.increment_id=sales_flat_order.increment_id

Done.