FamousPhil.com -- Home My Calendar Youtube LinkedIn Facebook MySpace Twitter RSS Blog Feed

Blog Navigation

Blog Home



Partners

Latest Activity

MySQL Singleton Classes in PHP and Python

Phil gives the source code for implementing a MySQL singleton class in both PHP and Python.



Posted on: June 18th, 2011 by Famous Phil

This is a topic that I should have blogged about a long time ago (when I actually did it), but I was busy at the time and stuff gets pushed onto a back burner (or even the freezer) when I don’t have the time.  Oh well, this article is better late than never.  I will also provide a script that powers https://www.matthouse.us/status.php.

Nagios is a server monitoring solution that can monitor entire systems and services running on those systems.  For Matthouse, Nagios runs on a reliable virtual private server that has a SLA to be up all of the time, the provider I choose has complete redundancy so that this VPS will not go down due to localized hardware, network, or power failures.  Nagios also runs on a system that is completely off-site from all of my other servers, so it can see if a datacenter goes down and notify me properly.  If you’re going to host Nagios yourself, I’d strongly suggest getting a similar setup since you don’t want your monitoring system to fail with everything else!

So let’s get into the actual installation of Nagios. (THIS WAS UPDATED 6/23/11) Read the rest of this entry »

Tags: , , , ,
Posted in Hosting / Server Administration, Technology
|| 2 Comments »

Posted on: June 11th, 2011 by Famous Phil

Here is a relatively short blog for a change!  A client came to me today to have PDFLib installed onto the Matthouse CPanel server.  PDFLib allows you to create PDF files programatically (in this case, PHP), so I can see a lot of uses for this extension.  As expected, CPanel wasn’t able to install this extension through PECL without a little help, so below is the procedure that I used.

#get latest pdflib lite 7 from http://www.pdflib.com/download/
#http://www.pdflib.com/download/pdflib-family/pdflib-lite-7/

cd ~
wget http://www.pdflib.com/binaries/PDFlib/705/PDFlib-Lite-7.0.5.tar.gz
tar xzf PDFlib-Lite-7.0.5.tar.gz
cd PDFlib-Lite-7.0.5
#java isn't installed on the server, compile without java
./configure --prefix=/usr/local/pdflib --without-java
make
make install
pecl install pdflib 
#when asked for a path, enter "/usr/local/pdflib" then hit <enter>

I opted to install the lite version of PDFLib since its free and my client didn’t need all of the features that the program includes.  I installed pdflib to its own directory that isn’t included in path since I don’t anticipate anyone actually using this via other languages on the server (besides PHP).  Once PDFLib is installed, we will need to use the command line (as root) to install the pecl extension and tell it where to find the compiled version of pdflib.  Note that CPanel’s PECL installer will not be able to install this extension since there is no way to enter the path (and I’d prefer to not add this to the global PATH variable on my server).  The extension is now installed, in order to test the extension, make a PHP file for the below code and execute it in a web browser, you should see “Hello World” as a PDF document.

<?php

try {
$p = new PDFlib();

/*  open new PDF file; insert a file name to create the PDF on disk */
if ($p->begin_document("", "") == 0) {
die("Error: " . $p->get_errmsg());
}

$p->set_info("Creator", "hello.php");
$p->set_info("Author", "AUTHOR");
$p->set_info("Title", "Hello world (PHP)!");

$p->begin_page_ext(595, 842, "");

$font = $p->load_font("Helvetica-Bold", "winansi", "");

$p->setfont($font, 24.0);
$p->set_text_pos(50, 700);
$p->show("Hello world!");
//$p->continue_text("continue text");
$p->end_page_ext("");

$p->end_document("");

$buf = $p->get_buffer();
$len = strlen($buf);

header("Content-type: application/pdf");
header("Content-Length: $len");
header("Content-Disposition: inline; filename=hello.pdf");
print $buf;
}
catch (PDFlibException $e) {
die("PDFlib exception occurred in hello sample:n". $e->get_errnum() ." " . $e->get_apiname() . " : " .$e->get_errmsg() . "nn");
}
catch (Exception $e) {
die($e);
}
$p = 0;
?>

Source: I used the guide at http://www.supportfacility.com/blog/cpanel/install-pdflib-php-on-cpanel-dedicated-server/ to write an updated version for my blog.  I’d like to thank them for blogging about this topic!

Tags: , , , ,
Posted in Hosting / Server Administration, Programming
|| 2 Comments »

Posted on: February 26th, 2011 by Famous Phil

It has been a while since I’ve done any sort of real coding for my website and I’ve been meaning to go back and post some of my old projects that work really well and show what is really good code.  Today I’ve decided to bring attention to my RMI chat client and server that I wrote for a class about 2 years ago now.  I recently had to refer to myself when implementing RMI code in another project and was hard pressed to find my old project.  Since my site is an archive of my work for the future, I thought that it might be appropriate to post this code now.

First, to compile Java code, you need to get the Java development kit (JDK) from Oracle’s Java Download Page.  Then you need to run the command “javac” on all the .java files to get the .class files.  Finally to invoke the code, you need to make use of the Java command.  I’ve tested this project on both Windows and Linux and both work fine, both locally and over a remote network link.  Although I’m not going to guarantee support for this code, you may feel free to email me (contact page) if you’d like some help beyond what the readme file says.

You may get the code from here: http://famousphil.com/wp-content/uploads/2011/02/RMIChatServer.zip

Tags: , , , , ,
Posted in Programming
|| 1 Comment »

Posted on: January 11th, 2011 by Famous Phil

There is a new blog with additional information on this topic at http://famousphil.com/blog/2011/07/revisiting-exchange-2010-sp1-pst-backups-improved-script/

About a week ago, I finally got around to reviewing and upgrading my existing backup routine for my exchange server.  My previous backup scheme involved pushing a full server backup image to a remote server on a weekly basis.  If the server failed during a backup, I would have no viable way of recovering from a complete disaster.  Obviously, this required some changes.

With the release of SP1 for Exchange 2010, a few new power shell commandlets came out that provide functionality to back up Exchange accounts directly on the server (no needing second computer with outlook and exchange management tools anymore!).  This meant that I decided to utilize some backup scripts that backup each mailbox nightly.  I also modified the weekly system backup.

There are scripts attached to this post.  With any kind of solution that I provide, I always provide it on an as is basis with no warranty provided that it will work for your situation, although I try my best to cover as many scenarios as I can.

So what was decided upon? Read the rest of this entry »

Tags: , , , , , ,
Posted in Hosting / Server Administration
|| 3 Comments »

Posted on: March 24th, 2009 by Famous Phil

About 3 weeks ago when I was building a new server, I put 2 identical SATA drives in the server (500GB each), each capable of 60MB/s transfer when clocked.  I had a fair amount of data (250GB) to share on these 2 drives.  I normally would opt for a raid mirror (hardware based mirror), however I have this data backed up else where, so I decided that I would combine the disks using a span to make a 1TB partition.

I transferred the data to the partition in 2 days and really thought nothing of it because I was busy with other stuff.  However when I got back to college with this server, I found that most of my local file operations would take 10 times longer than they should take.

Therefore, I decided to ditch the span.  To copy all of the data off the span took 4 days to an external hard drive (capable of 20MB/s).  To copy from the external to a simple dynamic volume took a little under 2 hours.  This proves to me that spans just plain suck.  I’m now using just 1 disk and use the other as a weekly backup disk.

I did discover after a little research that Windows treats spanned and stripped volumes differently although they both combine physical disks to make bigger partitions.  Windows NTFS (NT File System) has a 2TB physical limit that it can handle, and NTFS starts becomming inefficient after 500GB to 1TB.  Since a span treats 2 physical disks as 1 physical disk, this explains the slow down.

However, I did learn that a stripped volume will treat each disk as a separate disk and combine the storage into 1 logical partition.  I have yet to try this with another disk and I may comment on this if I ever try using a stripped volume.

The bottom line is, you will have a major performance problem under server 2003 x64 bit if you opt for a spanned dynamic disk, not to mention 20 to 30 server crashes while getting your data off to undo it.

Tags: , , , , , ,
Posted in Hosting / Server Administration
|| No Comments »

Posted on: February 10th, 2009 by Famous Phil

Over the past week or so, I’ve been getting extremely busy with my normal college workload that is a fact of any Computer Science Major’s college career.  Over the past week, I’ve learned 5 new languages in a project for my programming languages class.  Those languages are ML, Lisp, Erlang, Prolog, and Ruby.  I’ve done limited Ruby in the past, however I have never done any string parsing operations until this project.  I’m confident I’ve finished this project fully and I intend on posting it somewhere on my homework section after I receive my grade for this project.

In addition to my programming class, I’m taking French, Algorithms, and Probability.  Of the three, French takes about 3 hours of my week for homework, probability takes about 4 hours of my week reading the book so I know whats going on, and I put about an hour a week into my Algorithms course so I know something when the test comes later this month.

Now that you have an idea of what I’m doing for college, lets move onto AdminReference.  In my free time, I’ve been looking at numerous design ideas for the site.  I’ve pretty much made up my mind that it will contain a main site and a forum.  The main site will simply be an introduction to what the site is about, while the forum will be where community members will be able to interact with each other.  The service will be free unlike experts exchange because I want an easy reference thats freely available to anyone who needs it.  Initially the site will be ad free, however if traffic grows so much that I need to put a lot of funds into the site, I may insert an ad or two although I am not a fan of advertisements on websites (I feel they slow the site down and hurt its appearence).  Eventually after some content is added to the site, I may work on making a wiki-like interface where tutorials on the forum (or whatever guides are posted) will automatically be tied into a dynamic electronic reference manual that is easily searchable.

Thats all that I really have time to blog about for today, so stay tuned for the next blog within a week :)

Tags: , , , ,
Posted in My Site
|| No Comments »

Posted on: January 31st, 2009 by Famous Phil

As expected, I completed moving all of the websites hosted on the former mthsweb1 (Matthouse Web Server 1) server over to the new mthsweb4 server.  I haven’t heard any complaints so far about the new server so far and don’t expect to hear of any problems.  Tonight I will be doing some testing on the old matthouse web 1 server before it expires later in February.  I hope to learn some new knowledge from my testing later tonight regarding apache optimization.

Earlier today, I helped a friend in the hosting business move a massive website (http://clevelandleader.com) from his server to a virtual server that will just host that website.  This website is ranked ~76,000 on the alexa scale which means that it gets an insane amount of traffic.  My best guess would be 300 to 1500 loads per second.  The site itself has a huge mysql database that is over 2GB and the sql move alone almost crashed a dedicated server with a quadcore processor (it did have a lot of other websites on it though).  Regardless, after the move, my friend didn’t realize that a default whm (cpanel, inc) installation doesn’t optimize the server nearly enough for a large website like this.  Heck, I don’t even know if whm was made for such a large website.  I did optimize the server and compile apache correctly just to handle the needs of clevelandleader.com.  I also did a lot to prevent apache from crashing with the high load.

Traditionally, with such a large website such as cleveland leader, the web server hosting the site would only run a web server, no overhead like cpanel.  I feel that cpanel has made the hosting process much easier, but I just don’t think it was made to handle such a large website.   Also, the fact that cpanel uses the root password directly means that if there is a security vulnerability and the user obtains that root password through hacking or whatever, the server could be compromised not only from cpanel’s whm but also from the terminal through ssh (or a rare occasion of console access, meaning sitting in front of the server physically).  This could present a major problem.  Most smart hosting companies use cpanel’s wheel group to give su access to certain cpanel uesrs that can then login to the terminal via ssh and then su root with the root password to gain root.  This provides a 2 password layer and adds an additional layer of security to the server.

Another pitfall that large websites face is the need for a dedicated mysql server, that is if mysql can even handle the load.  Mysql was made for small to medium sites and it was made for maybe 100 to 200 queries per second, but much more than that and it undergoes a massive strain.  Many large websites find themselves moving to more powerful database servers such as Microsoft SQL or Oracle which are much more powerful solutions that were made for high loads.

So why am I even talking about this!  I felt that this would be the best way to introduce a new idea that I’m going to begin working on within the next couple of weeks.  I have purchased the domain (http://adminreference.com) and will begin a forum where users can share their administration experience and knowledge to the world.  I am a seasoned Windows administrator and a somewhat experienced Linux admin.  I find myself knowledgable about both server operating systems and I post tutorials on multiple websites that don’t really aim for administration concepts.  I also hope that some day this can help me when I am stuck on a massive problem.

I encourage you to stay informed as I begin this new journey.  I will likely be ready to release the site sometime in the next couple of weeks.  I am not sure how to market such a website, however I’m sure as people begin coming, someone will have knowledge about that as well.

Tags: , , , , , , , , , ,
Posted in Hosting / Server Administration
|| 6 Comments »

Posted on: January 19th, 2009 by Famous Phil

As you probably know, I host websites as a side hobby to keep myself busy.  If you didn’t know, I host websites through http://www.matthouse.us.

Over the past few years, I have hosted on the OpenVZ platform (Virtual Private Server).  I started out with lxadmin and moved my way up to cpanel accounts for my clients due to many problems with lxadmin.  After a lot of newly formed concerns about security after noticing hacking attempts, I have attempted to tighten my server, however openvz has presented many challenges while performing these tasks.   At first, I was recording 20 to 30 hack attempts per day to my main webserver (mthsweb1.matthouse.us), and this was totally unacceptable to me.  I have tightened that server down but am finding that my server is much slower than it once was and I was forced to find a better solution.  This is why I’ve decided to migrate my entire customer base to a new server running on the Virtuozzo platform which is much more stable, secure and less of a pig when it comes to memory consumption.

Within the next couple of weeks, I hope to contact everyone and migrate every website over to the new server completely.  I will personally verify each site is completely transferred with minimal to no downtime as possible.  To all of my customers, I would like to thank you for your continued support.  Your support helps me learn new techniques to managing servers and providing appropriate customer service!

One additional note, I promise that I will have a photo gallery up by next weekend!  Have a great Martin Luther King day!

Tags: , ,
Posted in My Site
|| 1 Comment »