More of Using PHP for Server Info

Posted by Nessa | Posted in uncategorized | Posted on 17-12-2007

1

I’ll eventually get the whole thing up here, but I’ve been working on a simple server info script to help me and the other members of the system admin team keep up with the gazillion servers we have and all their different configurations. One of the reasons it’s taking so long (aside from my recent alcohol binges) is that it has to be portable to every server without the need for specific modifications, regardless of their setup. This eventually calls for using a simple if statement and empty() function to decide what info to output. Really, it’s so easy that I don’t even know why I’m posting it, but it kinda supplements this and this.

I’ll take the Ruby example I used earlier to find out what version of Ruby is installed:

$rubyver = exec("ruby -v |awk {'print $2'}"); ?>

Most of our servers don’t have Ruby installed, so I instead of getting an ugly ass error or nothing at all, I’d rather the script gracefully output its absence:

if (empty($rubyver)) {
echo "<font color='red'>Ruby is not installed on this server</font>";
} else {
echo "Ruby Version $rubyver";
}

This code fragment will check the output of the $rubyver variable, so if Ruby is not installed then the variable will return no value. Since the variable is then considered empty, the first echo statement is executing telling the viewer that Ruby is not installed on the server. If Ruby is installed on the server, then the second echo statement will run.

Interactive RoR Tutorial

Posted by Nessa | Posted in uncategorized | Posted on 05-12-2007

2

So it’s official, I’ve started my Ruby programming classes in school and I’ll finally be able to see what it can do.  We started offering Ruby on some of our servers here and we’re all learning a little bit about it before we start offering it on our mainstream hosting…because you have to have at least one person who knows the feature well enough to help other people.  From what I’ve played with so far it seems to be the same logic as PHP and perl, so let’s just see how it goes.  For those of you wanting to try out some Ruby, there’s a nifty little Ruby emulator and mini-tutorial at http://tryruby.hobix.com/

Which Programming Language is For You?

Posted by Nessa | Posted in Uncategorized | Posted on 30-10-2007

9

Working with a webhosting company I get asked all the time — which programming language is better? It’s obvious that I’m more bias towards PHP, but there are other great languages out there that may be more suitable for certain people creating certain sites. I’ve decided to write a nutshell comparison on the most common languages, so you can decide for yourself.

PHP

My preferred language, PHP, is the most popular and widely-used dynamic programming language on the Internet. As a result, it’s increasingly become easy to learn (I have 4 brain cells and even I could do it) and can be run on virtually any operating system. It’s popularity has resulted in the availability of thundreds of contributions, modules, and addons for PHP to increase its functionality and integration with other software. It’s also free to download and easy to install (for most people), and is the most common in CMS’s and prebundled website software.

The major downside to PHP is that it’s so popular that security holes are being found all the time. Its very nature requires some configuration changes and restrictions in order to boost security.

Perl

Perl is one of the oldest and most successful languages to date. With thousands of modules that can be added, it can pretty much do anything. While it’s currently not as popular as PHP, it’s more efficient for server management in its double use as a shell scripting language. It’s also open-source and compatible for most all OS’s. The only real downside is that it’s not as quick and easy to learn, and even the simplest tasks can take more programming and lines of code to accomplish. Also, the camel logo is fugly.

ASP/VBScript

I’ll try to be nice about this one. Really, I’m not an ASP fan mainly because it’s proprietary to Windows and IIS. That being said, I’m sure you can figure how secure and reliable it is. It’s not as actively maintained by its developers (Microsoft) so major bugs have been known to linger for months — unacceptable for busy webmasters trying to manage professional websites. While ASP, .net, and VBScript (aka the ASP family) are all “free”, if you want any of the fancy addons or modules for them you’ll be owing Microsoft a nice little licensing fee. On a positive note, Chilisoft has made is possible to port ASP over to Linux, so it’s no longer 100% platform dependent.

JSP

Java Server Pages (developed by Sun) is more similar to the ASP framework, but targeted towards Java fanatics. Out of all the programming languages I’ve studied in school, JSP is probably my least favorite. Not only is it hard to learn, but there’s no such thing as simplicity with it. However, it’s very powerful software and is platform-independent, as long as you have a Java Environment for it to run in. Tomcat (an Apache Project) is the most common servlet container for JSP. But, Java takes up a lot of memory and JSP servers are very difficult to maintain and administer for non-experts.

Ruby

Ruby is one of the newer programming language to hit the web developer market, and it’s actually quite close in concept to PHP except that it’s 100% object-oriented, and very clean because you don’t need as much punctuation. It’s also very beginner-friendly, and is growing in popularity. The main disadvantage to Ruby is that it’s difficult to troubleshoot runtime errors because its reluctance to declare variables before their use. And being that it’s a newer language, there are definitely less resources available and not as many applications currently employing Ruby as a framework. However, it is cross-platform compatible, easy to install, and even easier to learn.

Python

I really don’t know a whole lot about Python other than that expert programmers claim that it’s such a strong language. I personally think it’s crap…my one shot at Python and I find out that it’s very whitespace/tab sensitive, so one extra space can ruin your program. Coming from PHP I don’t find that very appealing…I personally think it’s a mistake, and that its developers just call it a ‘programming guideline’ since they can’t figure out how to fix it. Really, there’s no huge benefit in using Python other than for your Google sitemaps, so all I’m going to say is steer clear.

HTML

I put this at the bottom of the list because I don’t really consider it a programming language, but it is the more predominate and widely used language that all the others revolve around. I do think it’s important that every programmer become an expert in HTML before going dynamic with their coding. While other languages rely on HTML for output, it’s very common for sites to be purely HTML and nothing else. However, HTML is a static language with no dynamic capabilities in itself whatsoever, so it’s somewhat boring on its own

Client-side

In a category all its own, there are several client-side languages that augment the others. Client side languages no require any server-side software to be installed, just a browser capable of interpreting them. CSS (Cascading Style Sheets) is a language primarily used in formatting and creating a uniform and repetitive style for use across multiple pages. JavaScript is a mini-java language used to create mild effects for a website, like popup windows and form validation. I also consider it to be very insecure, so it should be used sparingly. AJAX is a newer JavaScript framework that is more appealing to the eye and lets you create those special effects that you see on many web 2.0 sites…things like refresh-less page loading.

Using PHP to Display Version Info

Posted by Nessa | Posted in Uncategorized | Posted on 15-10-2007

3

I’ve been working on this application for work that does some simple server reporting, part of which involves displaying the versions of major software running on the machines. The importance of this to me personally is that since we have over 30 shared servers hosting multiple customers, we are continually moving websites between servers. Some of our older generation servers are still running MySQL 4.0 and PHP 4.3, so I need to be aware of this to make sure that customers are being moved to servers with compatible versions. It’s also good in tracking and planning upgrades.

I find it best to use the exec() function since it’s not blocked by most hosts. However, if you are on a shared host it’s very likely that certain PHP functions are disallowed in the php.ini. In that case you may be able to subsitute exec with system, passthru, escapeshellcmd, or shell_exec…unless those are blocked too. Then I guess you’re out of luck.

Start by creating some variables to store ordinary shell commands. If you wanted to find the php version from command line, you would usually type:

php -v

This will give a huge chunk of crap that you really don’t need if you’re making a simple version display script. In this case, you can use grep, awk, sed, and cut to trim down the output into a one-liner:

php -v |grep built |awk {‘print $2′}

The awk command prints out columns, so in the above example I’m printing out the second column of the line that contains the word ‘built’. Once the desired output is figured out, you simply assign it to a variable passed through exec() or a similar function:


$phpver = exec("php -v |grep built |awk {'print $2'}");

Then you can call the variable $phpver anywhere in your script:

echo "PHP Version: $phpver";

You can probably go through and figure out the commands to show other software versions on your server. In my script I’m showing the perl, php, mysql, apache, python, cpanel, and ruby versions. Here are the commands I used:

<?php

$perlver = exec("perl -v |grep linux |awk {'print $4'}|sed -e 's/v//'");
$phpver = exec("php -v |grep built |awk {'print $2'}");
$mysqlver = exec("mysql -V |awk {'print $5'} | sed -e 's/,//'");
$apachever = exec("apachectl -v |grep version |awk {'print $3 $4'}|sed -e 's/Apache\///'");
$pythonver = exec("python -V 2>&1 | sed -e 's/Python //'");
$cpanelver = exec("cat /usr/local/cpanel/version");
$rubyver = exec("ruby -v |awk {'print $2'}"); ?>

Then I just echoed out all the variables to display my version numbers:

See here .

Ruby Isn’t Too Bad

Posted by Nessa | Posted in Uncategorized | Posted on 02-05-2007

4

I haven’t really had a whole time to play around with Ruby, but I managed to write a little script that I call boobs.rb.  It was my attempt to take advantage of Ruby’s ability to define your own functions. Maybe if I’m lucky I would be able to actually define my own bra size too.

#!/usr/bin/ruby


def sayBoobs(name)
result = "Hey, " + name + " wears a size DD. \n "
return result
end


puts sayBoobs("Nessa")

This puts out something that looks like this:

How to Make a Sexy Tag Cloud with PHP and MySQL

Posted by Nessa | Posted in Uncategorized | Posted on 12-02-2007

33

Tag CloudWell it seems that everyone has one, and I’d have to admit that a tag cloud is a good way to spice up your site a little bit. I first thought of this when setting up a friend’s site… he wasn’t using a CMS like WordPress or anything that I could find a quick tag cloud plugin for, so I figured I could probably just make my own. Well, I did and now I shall share it.

This tutorial will show you how to set up a simple tag cloud using PHP and MySQL, with a little bit of Ajax effects
Before we get started, take a quick look at the sample cloud.

Radiant CMS is Gorgeous

Posted by Nessa | Posted in Uncategorized | Posted on 15-01-2007

0

Radiant CMSIf you haven’t heard the news, Radiant CMS is finally making its presence on the internet. Of course, you wouldn’t have heard the news unless you’re a dork like me. Anyways, I thought it would be worth mentioning as this is probably one of the sexiest content management systems I’ve seen yet. But really, I just like the color. And the logo’s nice too.

Check out Chris and Luke’s sites, which are currently running Radiant with Ruby on Rails.

Installing Ruby on cPanel

Posted by Nessa | Posted in Uncategorized | Posted on 15-01-2007

12

Here’s how to install Ruby on Rails on a cPanel system:

Update: These instructions were modified for Ruby 1.8.6, since 1.8.5 is no longer available!

First install Ruby:

wget ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6.tar.gz
tar -xvzf ruby-1.8.6.tar.gz
cd ruby-1.8.6
./configure
make
make install

Now, install the Gems and Rails:

wget http://rubyforge.org/frs/download.php/11289/rubygems-0.9.0.tgz
tar -xvzf rubygems-0.9.0.tgz
cd rubygems-0.9.0
ruby setup.rb
gem install rails

Install Fast CGI

wget fastcgi.com/dist/fcgi-2.4.0.tar.gz
tar -xvzf fcgi-2.4.0.tar.gz
cd fcgi-2.4.0
./configure
make
make install

wget fastcgi.com/dist/mod_fastcgi-2.4.2.tar.gz
tar -xvzf mod_fastcgi-2.4.2.tar.gz
cd mod_fastcgi-2.4.2
/usr/local/apache/bin/apxs -o mod_fastcgi.so -c *.c
/usr/local/apache/bin/apxs -i -a -n fastcgi mod_fastcgi.so
gem install fcgi

Edit the Apache config file and add the fcgi module:

pico /usr/local/apache/conf/httpd.conf

LoadModule fastcgi_module libexec/mod_fastcgi.so
FastCgiIpcDir /tmp/fcgi_ipc/
AddHandler fastcgi-script .fcgi
< /IfModule>

Then restart Apache

Install RMagick and GetText:

wget http://umn.dl.sourceforge.net/sourceforge/graphicsmagick/GraphicsMagick-1.1.7.tar.gz
tar -xvzf GraphicsMagick-1.1.7.tar.gz
cd GraphicsMagick-1.1.7
./configure
make
make install

Install MySQL for Ruby:

gem install mysql

Now make the test Installation. To do this, log in as your user (not root)

su user
cd ~
rails test
cd public_html
ln -s ../test/public/ rails
cd ../test/
chmod -Rf 777 tmp/
cd public
chmod 755 dispatch.fcgi
pico .htaccess

Now, find the line in the .htaccess that looks something like this:

RewriteRule ^(.*)$ dispatch.cgi [QSA,L]

And change “dispatch.cgi” to “dispatch.fcgi”

To see if you’ve installed everything properly, just browse to the Rails folder:

http://yourdomain.com/rails/