Posts Tagged ‘cpanel’

New Relic, cPanel, Apache and FastCGI PHP

May 29th, 2013

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!

cPanel: Error: Package system can not be repaired automatically

June 7th, 2009

If, like myself, you have recently upgraded the cPanel control panel system on your Red Hat Enterprise Linux 5.2 server and received the error message “Error: Package system can not be repaired automatically” when upgrading Apache, then it’s probably caused by a problem with either the RedHat Package Manager (RPM) or YUM. To fix it, first ensure that no RPM or yum updates are running:
ps auxwww | grep yum
ps auxwww | grep rpm

If any are running, find out why and kill -9 them if they are zombie processes. Now you just need to rebuild the RPM database:
rm /var/lib/rpm/__db.* -rf
rpm --rebuilddb

This process may take some time (between 1 and 30 minutes depending on your server speed and the number of packages installed). Once it’s completed, you should be able to upgrade without problems.

cPanel: Simple Script To Backup Over rSync

August 20th, 2007

If you are running a reasonably recent version of cPanel (I think v11 or later), you have the ability to run WHM backups over rsync instead of just FTP. This post, if it isn’t obvious, is intended for people with root access to their cPanel server.

So how do you do this?

Simple, configure the backups as per normal in WHM to backup your secondary hard drive or a set partition on your main hard drive. Then just add a script via the shell command line as “/scripts/postcpbackup” (open PuTTY, connect to the server, login, “su” to root if necessary if you didn’t login as root, type “nano -w /scripts/postcpbackup”) and past the following script:

#!/bin/sh
rsync -vrplogDth /backup/cpbackup/* username@backupserver:/backuplocation/

Replacing “/backup/cpbackup/” with the location of your “local backups” if you changed it from the default, “username” with the username of your rSync account, “backupserver” with the hostname/IP address of the backup server and “backuplocation” of the place to store the backups. (It’s CTRL+X to exit nano by the way).

You then just need to make it executable by running “chmod a+x /scripts/postcpbackup” and you are done!

Hope it helps someone!

cPanel: cPanel 11 and WebDav

May 14th, 2007

As some of you may be aware, the new version of cPanel (version 11) now supports a technology called “WebDav” (known as “Web Disks” within cPanel).

Basically this allows you to setup your cPanel web hosting account as an additional drive on your machine – making the uploading and publishing of files a lot easier.

However, server administrators will first need to enable the TCP ports 2077 and 2078 in and outbound for this to work correctly (don’t forget to restart/reload the firewall). Once that’s done, your customers should be able to login to their cPanel control panel and either select the new fancy “Getting Started” wizard or “Web Disks->Access Web Disk” to setup a link.

Using cPanel’s handy “Auto configuration” tool is useful – but you may hit the same problem I did when I downloaded the installer .vbs file to my Windows XP machine via Firefox. Attempting to open the file came up with the error “Windows Script Host access is disabled on this machine. Contact your administrator for details”. Needless to say – I am the administrator and if I’ve disabled something like that in the past, it’s probably for a very good reason!

So – how can we manually configure cPanel’s WebDav uploading tool manually if the automatic method fails?….
» Read more: cPanel: cPanel 11 and WebDav

Techy: Dealing with .tar.gz, .gz and .zip files on a cPanel Server

May 13th, 2007

Many of you with cPanel web hosting accounts would have needed to upload files to a cPanel server which were in .tar.gz, .gz or .zip files (these are compressed archives).

And I bet many of you would like to have been able to upload the archives to the server “as is” (to save decompressing them on your machine and then having to slowly upload each and every file).

But did you know there is actually a “cheat” for this?

Just upload the files to your webspace via FTP (or via the cPanel File Manager) as per usual. Then login to your cPanel control panel and select “File Manager” (if you are running on the new x3 theme with cPanel 11, it doesn’t matter if you select “File Manager” or “Legacy File Manager”). Select the archive you uploaded, and then click “Decompress” from the top menu (on the new file manager) or “Extract from Archive” from the right hand menu (on the old file manager) and there you go.

Your files are now decompressed on the server quickly and simply!

gamy-dance
%d bloggers like this: