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: May 30th, 2010 by Famous Phil

As per a suggestion from John, I should take up local development.  For all of you who are lost, I mean development of websites on my own computer without any interaction with the outside world.  For years, I have developed on the actual server that will be hosting the website.  There are several pros / cons to both methods so I thought I’d outline a few of them in a blog post (it has been coming, I have been very busy as of late).  I also thought I’d outline a few problems with local development and solutions for them.

For years, Remote development has been my choice for every job I’ve been contracted to do.  My reasoning is simple, if I have a solid connection to the remote environment, I can develop on it and it is guaranteed to work once I’m finished.  After all, it is on the remote system where the site will eventually be permanently settled.  Unfortunately, with remote development, I usually have to be careful about not removing stuff that relates to the current system in place.  This is very true of website development, I wouldn’t want to remove the website that is currently in place and working.

For my last major project, retreadproducts.com (it has yet to be released), I chose to try local development.  Since I’ve recently adopted Ubuntu Linux as my operating system of choice (that is another blog post eventually), it would be very simple to mimic the remote server environment to minimize compatibility.  I must admit that local development was much faster and easier to do than remote development ever was.  It is because instead of a lag of a couple seconds (for remote development) to do any kind of update (plus upload time for the updated portions), I’ve discovered that I waste about half the project time just keeping a good connection to the Internet and waiting for files to go back and forth to the remote server.  This is a huge loss of time and in my humble opinion, I don’t think that it is worth developing on the remote system as my main development method.  I also found that mimicking the remote environment almost exactly made compatibility 100%.

Getting a local development environment setup is a task in itself, but with Ubuntu, it is simple as opening up a command line, typing in sudo tasksel, then selecting the webserver role.  Everything is setup for you practically, except for the configuration files… but then again, even those have a default configuration to make development easy.  For me, I had to tweak my configuration files a little bit to mimic the remote environment as much as possible.

During my tweaking I ran into a few issues, that for me weren’t a huge deal, being a big time CentOS administrator.  My first issue was very easy to fix… Ubuntu uses apache2 as its apache webserver service.  This kept throwing me for a loop since CentOS / RedHat both use httpd as the webserver service (or daemon for the Linux geeks out there).  Getting over this hump left one other major problem that I needed to solve… and that was the .htaccess files weren’t being used by the apache webserver.

In Linux webserver talk, .htaccess files are hidden files that provide advanced functionality for any website that they are in the same directory with.  I use .htaccess files mostly for rewriting a page like: http://famousphil.com/blog/index.php into http://famousphil.com/blog .  This is very powerful since without the .php extension, hackers don’t know what technology is serving your website.  Of course they can figure it out via other means, but .htaccess is very powerful at deterring script kiddies.  Naturally, I just gave out how this website is powered :P   It has been a while since I’ve configured a Windows IIS server, but I believe they have something similar for ASP pages.

It turns out that Ubuntu disables .htaccess by default.  Turning it on is very simple.  First off… you need to allow it in your apache configuration.

Step 1, view all the configuration files under /etc/apache2… especially apache2.conf… Make sure that AllowOverride is allowed, so as an example:

        Options FollowSymLinks
        AllowOverride all

Step 2:Enable the correct module in the Apache configuration:
Type in sudo
a2enmod rewrite to a command line
then type in sudo /etc/init.d/apache2 restart


This will solve your issues with .htaccess not working, especially if you’re developing locally for wordpress like I was.

Tags: , , ,
Posted in Hosting / Server Administration, Programming
|| 1 Comment »