Two (or more) Zend Framework projects on a shared host
Tags: zend framework
Два (или более) проекта Zend Framework на общем хостинге
Два (або більше) проекти Zend Framework на спільному хостингу
| ← 10 Rare HTML Tags You Really Should Know | 80+ SEO Job Interview Questions → |
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/heel/. From now on, I am going to refer to it as. Create the following file structure under it:
Hide code highlighting
Now download, extract and upload the “Zend” directory contained in the zip or gz file into the “/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 “/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/public_html/myfirstproject/ should look like this:
Hide code highlighting
And the bootstrap file index.php under the same location, should look like this:
Hide code highlighting
That was the trick, let’s finish this creating our IndexController and its view. The first one should be placed on/myfirstproject/application/controllers/IndexController.php:
Hide code highlighting
The view should be anything you like, my bet is for:
Hide code highlighting
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.
Original: Two (or more) Zend Framework projects on a shared host
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/heel/. From now on, I am going to refer to it as
Hide code highlighting
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 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 “
Keep in mind that this example is based on the fact that the public folder on the hosting environment is “
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
Hide code highlighting
1 2 3 4 5 6 | 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:
Hide code highlighting
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | /** * <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
Hide code highlighting
1 2 3 4 5 6 7 | class IndexController extends Zend_Controller_Action { public function indexAction() { } } |
The view should be anything you like, my bet is for:
Hide code highlighting
1 2 3 4 5 6 7 8 9 | <!-- <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.
Original: Two (or more) Zend Framework projects on a shared host
Rating:




<< Please, rate this articleRelated articles:
Integrating FCKeditor with Zend_Form
Automated Testing Using Zend Framework
A caching pattern for models
Zend Framework and Translation
Memcached in PHP Made Easy With Zend Framework