Archive for the ‘Tips & Tricks’ Category

CPANEL/WHM: How to bulk add DNS zones on the command line

Thursday, November 4th, 2010

I had about 30 domains I need to create basic zone files for and did not want to do it by hand. I found that you could do the following via the command line:


for i in `cat /root/domainlist`; do /scripts/adddns --domain $i --ip xxx.xxx.xxx.xxx; done;

/root/domainlist is a file that contains a domain on each line without the www. and of course replace xxx.xxx.xxx.xxx with the real ip address:

domain1.com
domain2.com
domain3.com

NGINX: How to forward multiple domains to a primary domain

Thursday, November 4th, 2010

I looked all over the interwebs for this and all I could find were articles on redirecting www to non-www or vice versa. Which is essentially the same thing.. but I figured the web deserves an article dedicated to just this.

The first server block sets up the redirects and the second block is what you are redirecting to. Pretty straight forward. Just make sure to /usr/local/nginx/sbin/nginx -t (or where ever the nginx binary is) before you try to restart as you may accidentally enter some funky characters.


server {
    listen 80;
    server_name secondarydomain.com tertiarydomain.com www.secondarydomain.com www.tertiarydomain.com;
    rewrite ^(.*) http://www.primarydomain.com$1 permanent;
}

server {
    listen 80;
    server_name www.primarydomain.com;
    # config for primary domain here
}

Subversion shortcuts

Tuesday, March 2nd, 2010

Here are some shortcuts I use on an almost daily basis that I constantly forget and then go re-read the blog post. I have taken them from an old post but added a new one:

Bulk add:

svn st | grep ^? | sed 's/? //' | xargs svn add

Bulk remove:

svn st | grep ^! | sed 's/! //' | xargs svn rm

Strip all .svn directories from project:

find . -name .svn -exec rm -rf {} \;

Edit the ignore file pattern list for the current directory with the specified command line editor (don’t forget the last dot!):

svn propedit --editor-cmd vi svn:ignore .

Check in (commit) local changes to repository with the supplied message:

svn ci -m 'the commit message you want to use'

Subversion bulk add or remove

Friday, December 11th, 2009

A couple of one liners to easily bulk add or remove files in subversion:


svn st | grep ^? | sed 's/?    //' | xargs svn add

svn st | grep ^! | sed 's/?    //' | xargs svn rm

svn st | grep ^! | sed 's/!    //' | xargs svn rm

They can even handle files with spaces.

nginx and non document root phpmyadmin

Friday, November 6th, 2009

Recently we have been playing around with nginx for a couple of projects we have been working on and I think I have fallen in love with a web server. After using apache for so many years, I did not think that this could be possible, but it is!! For what we are using it for, it is superior in almost every aspect: installation, configuration, speed, memory usage, etc. Not to mention the fact that most of our apache deployments are often tainted by the beast that is cPanel/WHM… The reason I am writing this article is to hopefully alleviate the pain of trying to figure out how to setup phpmyadmin or other such applications in a non-document root setup when you are just learning the ins-and-outs of nginx configuration.

Just a quick tip because it is probably the main stumbling block when learning nginx configuration vs apache configuration; the root directive works differently in nginx. In nginx it will append the directory from the matching location block to the request. Taken from the docs: “so that a request for “/i/top.gif” will not look in “/spool/w3/top.gif” [but in /spool/w3/i/top.gif] like might happen in an Apache-like alias configuration where the location match itself is dropped. Use the alias directive to achieve the Apache-like functionality.” But I digress.

Most of the online documentation and tutorials explain how to get php running globally or how to get phpmyadmin to work from document root, but I had to dig deep to get it to work like www.domain.com/phpmyadmin/ . I didn’t want every .php script to be run as php and I did not want phpmyadmin installed at document root. Here is what I found:


location /phpmyadmin {
    root           /usr/local/nginx/html;
    index          index.php;
}

 location ~ ^/phpmyadmin.+.php$ {
    root          /usr/local/nginx/html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

(more…)

Nifty Twitter Tip (Twip?)

Monday, September 28th, 2009

It turns out you can easily provide a link for your users to post something to their twitter account; say a link to an interesting blog post or some other such thing.

http://twitter.com/home?status=Check+Out+This+Blog+Post:+http://cli.gs/3ZeD5X