PHP insights, tips and tricks

Two (or more) Zend Framework projects on a shared host

Shared hosting environments can be a nightmare when it comes to PHP Web Development, specially in testing stages. Yes, I know one should not be using and paying for a hosting plan if the code is still not production ready, but I have seen some cases.

I will try to show how to have the Zend Framework installed with as many projects as you want (if your server quota allows you to) in the same web space and all these projects sharing the same ZF copy.

Suppose that your home directory is /home/mauricio/. From now on, I am going to refer to it as <root>. Create the following file structure under it:

library/
  Zend/
myfirstproject/
  application/
    controllers/
    views/
      scripts/
mysecondproject/
  application/
    controllers/
    views/
      scripts/
public_html/
  myfirstproject/
  mysecondproject/

Now download, extract and upload the “Zend” directory contained in the zip or gz file into the “<root>/library” directory of the structure that you have just created. This copy of the Zend Framework will be shared by all projects. If needed, you can upgrade to a future version of ZF just by changing its content.

Keep in mind that this example is based on the fact that the public folder on the hosting environment is “<root>/public_html”. Some providers call it “www”, so… in this example our public folder will be called “public_html”, make the appropriate changes to suit your needs.

The first folders: “myfirstproject” and “mysecondproject” will contain the application files that won’t be visible to the outside world. Notice that under public_html exist another two folders under the same names, these two folder will contain the bootstrap or the entry point for the application which must be of public access and all the images, style sheets and other media that your application requires.

Your .htaccess file under <root>/public_html/myfirstproject/ should look like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

And the bootstrap file index.php under the same location, should look like this:

<?php
/**
* <root>/public_html/myfirstproject/index.php
*
*/

// The library folder contains Zend Framework files
define('LIBRARY_PATH',     realpath(dirname(__FILE__) . '/../../library/'));
define('APP_PATH',         realpath(dirname(__FILE__) . '/../../myfirstproject/application/'));
define('CONTROLLERS_PATH', APP_PATH . '/controllers/');

// library is appended to the include_path
set_include_path(get_include_path() . PATH_SEPARATOR . LIBRARY_PATH);
include_once 'Zend/Loader.php';
Zend_Loader::registerAutoload();

/**
* The most important step is to set the controllers directory pointing to
* <root>/myfirstproject/application/controllers
*/
$front = Zend_Controller_Front::getInstance();
$front->setControllerDirectory(CONTROLLERS_PATH);
$front->dispatch();

That was the trick, let’s finish this creating our IndexController and its view. The first one should be placed on <root>/myfirsproject/application/controllers/IndexController.php:

<?php

/**
* <root>/myfirstproject/application/controllers/IndexController.php
*
*/
class IndexController extends Zend_Controller_Action
{
  public function indexAction()
  {
  }
}

The view should be anything you like, my bet is for:

<!-- <root>/myfirstproject/application/views/scripts/index.phtml -->
<html>

<head><title>It works!</title></head>

<body>
<h2>It works!</h2>
</body>
</html>

That’s all, you can start building more views, controllers and helpers. To get your second project working just follow the same steps that you did for “myfirstproject” folder. The same way, you can create as many projects as you want, keep in mind that they all share the same Zend Framework library.

Tags: , ,

Gmail outage wasn’t so bad at all!

Bad news spread rapidly and everybody heard about the Gmail service disruption on February 24th. I was personally affected by the issue, fortunately I only manage my personal e-mail through Gmail, so my business communications wasn’t affected at all.

Besides the huge attention that this problem caught, I was really impressed by the open and detailed response that Google gave to all of its customers. One good thing about the Gfail issue was the creation of the new Google apps status dashboard, where –as its name says– people can see the status of the main Google services with very detailed information, like this PDF report about the past Gmail issue.

How I wish that many companies follow this lead…

Tags: ,

Yahoo Briefcase is shut down

After almost ten years of enjoying my little briefcase, Yahoo! decided to pull the plug. I think I won’t miss it

Full details on this link!

Tags: , ,

Barcelona international PHP conference wrap up

After attending Google Developer Day in Madrid, I knew it was going to be hard to impress me. But the guys from phpbcnint08 blowed me away! Not only because of the very high quality of the speakers, the comfortable and appropriate venue, the really good meal, the all you can drink or the Wii, the XBOX 360, the Acer Aspire One, the O’Reilly books and the flight tickets they gave away.

What really impressed me was the love and commitement that all of the organizers showed about PHP. Some people say that you get what you pay for… well, the event registration was only 20 euros and some of the best-known PHP community speakers were there.

There were simultaneous talks, so I couldn’t attend all of them:

Marcus Bointon started with e-mail in PHP, not only showed the benefits of PHP Mailer, he also dug into the mass mailing topic, giving some interesting facts and recommendations about handling the delivery of  huge amounts of e-mails.

The next talk was as entertaining as interesting, Arno Schneider who does a really good job designing very appealing slides, explained his disagreement with Rasmus Lerdorf about PHP frameworks, showed some real world examples and took many of us back to our early programming days when our code was a mess.

Scott MacVicar and Derick Rethans were the last ones, they talked about SQLite 3 and Xdebug respectively. A pair of interesting and mature projects, both of which I’ve had the time to test drive.

My trip to Barcelona was totally worth it. I want to give a huge thanks to the organizers and encourage them to keep up with their loyalty and hard work towards the community, creating this type of good quality events and hoping for nothing in return.

Tags: , , ,