Categories
Python

Running django on Site5

It took me an entire day, yes it did! I went here : http://wiki.site5.com/Python/Django/Django_installer. Browsed the forums. No help! Then I started on my own. I noticed that virtual python is loading the modules from the main python lib (/usr/lib/python2.4) instead of the local copy. I imported sys and read the sys.modules list. It pretty much made sense. If python doesn’t run locally (inside the virtual environment), it will try to install easy_install into the server wide path. You can’t achieve that unless you’re the root.

While looking for an alternative, I found virtualenv. It not only worked, it also shipped with a built in easy_install.

Later, when I set things up, I noticed that my app was breaking because Python wasn’t elegant enough to let use codes like this:

Huh! I had to browse the django svn and try all the versions before I got it working. It was a tiring process, but I learned a lot of things! Here’s a quick tutorial for fellow Site5 users:

1) Get Virtualenv from here: http://pypi.python.org/pypi/virtualenv

2) Run this command:

3) The above command will create a virtual python environment for you in “~/bin”. You can now run Python and easy_install by typing:

4) Now get MySQL bindings for Python and the flup package for the FCGI dark spells 😉

5) Now we are ready to rock and roll with Django! Remember, Site5 has Python 2.4. The latest builds of Django might break. Please use the one I used in the following script:

6) Create some Symlinks:

7) Create a dedicated directory for django projects:

8 ) Lets create a project and an app:

9) Create django.fcgi with the following content:

10) Lets finish with a .htaccess to finish it off, should we? 🙂

Categories
PHP

Running Zend Framework in Shared Hosting

Since you have come to visit this post, I’d assume that you have the basics of ZF. We know that the index.php inside the “public” directory is the entry point for ZF apps. ZF also needs to find the Zend library in PHP’s include path. If we want to run our applications from the root directory, we somehow need to manage an index.php which will call the index.php inside “public” directory. We also need to upload the Zend library and put it into include_path.

1) Upload the “library” directory of Zend Framework somewhere on your hosting. Note the full path of the directory.
2) Create a project on your local machine (if you haven’t done already.)
3) Upload the project files on to your web root (www or public_html).
4) Copy the .htaccess file from the “public” directory to your web root.
5) Create a index.php and put these codes:

Replace ‘/home/masnunco/library’ with the full path to the Zend library you uploaded earlier.

Visit your website and check if it works 🙂 In most cases it would work. Have fun!

Categories
PHP

Ubuntu, Zend Framework and Netbeans: Setting Up VirtualHost and Code Auto Completion

If you follow the Zend Framework tutorial here: http://framework.zend.com/manual/en/learning.quickstart.create-project.html, you would probably do the same thing they did – creating a ServerName and then editing the “/etc/hosts” file. Thats the way, you should do in the production server. But in your local development environment, you can skip messing up with the “/etc/hosts” file by running the Zend virtualhost in a different port.

Here’s my VirtualHost for Zend Framework that runs on port 8080:

Restart your apache :

Visit : http://localhost:8080 😀

Now, we can configure Netbeans to open this URL whenever we click the green play button (Run Project) or hit F6.

Go to: File > Project Properties > Run Configuration
Put the URL http://localhost:8080/ in the Project URL field.
NB: Don’t miss the trailing slash or it won’t work 🙂

Ok, now that we have Zend Framework up and running, lets add code completion to Netbeans. Even if you add the Zend tools in Netbeans (as described in my last post), it won’t add the Zend Library into it’s inspection scope. So, it will fail to offer you any code completion. We can add the Zend Framework library to the project include path to enable code completion.

Go to: File > Project Properties > PHP Include Path
Click “Add Folder” and put the path to your Zend Library 🙂
In my setup the path is: /usr/share/php/libzend-framework-php
It would be the same for you if you also installed ZF from Ubuntu repository 🙂

Restart the IDE and have fun!