Zend Framework - many multiple applications - zend-framework

I'm starting new project for my company and it's requiring hosting multiple applications under one domain. Each applications must be accessible by different subdomain (wildcards). One of applications will be control panel for all sub-apps. Creating one multi module application is not an option because of complexity of child applications.
All applications must share common libraries and have access to some app specific ones.
I'm still trying to design directory structure that allow store each applications outside public folder, access them dynamically via subdomain and store some files in public folder for each of them separately.
What I've figured out so far :
Host each application with default ZF dir structure in separate dir outside public. Access to public files is possible by plugin printing files to browser from app public directory (witch is outside domains public dir). Only change to default ZF application is thet there is only one index.php file in public_html that starts requested application based on subdomain.
domain_dir/
controllPanel_app/
application/
configs/
modules/
layouts/
Bootstrap.php
library/
public/
subApps/
exampleSub_app/
application/
library/
public/
anotherExampleSub_app/
application/
...
common/
library/
Zend/
Other/
public_html/
index.php
Is this good idea?

You could do it the way you suggest, but I think it'll be more trouble than it's worth. Zend Framework is designed for modules if needed, but not sub-apps. You'll probably end up with a Zend Router nightmare, or some complicated .htaccess trickery, both of which would be hard to maintain.
Why not have a totally separate Zend Framework application for each subdomain, and another separate app for your control panel? Your company (or you yourself) should be able to reconfigure your HTTP server so each subdomain can have its own Document Root. I do this for my own company, which has a similar situation. (Common control panel app with different public-facing apps for different purposes, as well as having a common library of shared code.)
You can share a common library folder in multiple ways. One is if each app adds this folder to its PHP include_path in each app's index.php or Bootstrap.php file. This is how I prefer to do it. Another way is through symbolic links within each app's library folder.

Related

Zend Framework Setup on Hostmonster?

I have created a project locally using Zend Framework 1.11. I have spent a long time learning the basics of the framework from all the online tutorials I can find, and I now feel fairly comfortable using the ZF Tool and locally working on my project on WAMP. I decided it was time to upload my project and deploy it on my shared hosting server, which happens to be Hostmonster.
After uploading my project, I have been struggling to get it to function correctly on the remote host. I have successfully uploaded my Zend Framework Library and included it in my PHP.ini, and all tests show it is seen by the server.
My directory structure, which was originally created to the standard format by the ZF Tool locally on the command line, is not pointing to the same paths on the remote server, so everything was messed up when I navigated to the Project/public folder. After much more Googling, I found several posts by various bloggers related to modifying .htaccess files, etc., which resulted in all my other sites hosted on the server being disrupted.
The closest I have been able to come to re-creating my initial local site on the Hostmonster host is by:
Taking all the directories out of my "public" ZF folder, and putting them directly in the web root of my server, (public_html), and:
Changing the 'APPLICATON_PATH' of my index.php file from the ZF public folder with the path to my ZF library (changed to reflect where it is in relation to the new location).
With this (tedious) setup, I am now seeing my index view being rendered with all CSS and Javascript, but I am unable to navigate to any of the other views, and the form I have displayed via a view script is likewise not showing up, only the index view is rendered.
My Zend Framework Library is located in a directory in the web root-- public_html, with the php.ini adding it to the include path.
This is becoming very frustrating as I like a lot of the features of ZF, but the restructuring of the site is proving impossible. If anyone has instructions or experience with this setup, I would greatly appreciate it. I am also hosting multiple other sites on this server, so I'm hoping I don't have to change from the single php.ini configuration(5.3) I'm currently using or mess around with a bunch of .htaccess files.
Thanks for any help anyone may have!
I have ZF running on HM no problem. Just place your index.php and .htaccess in your public_html dir, and what I did was created a public_html/zend/library folder and in my index.php including that library to get things working.
Also what do u mean you're running other sites off this server? Are you serving the application on the root of your domain? ie in your http://domain.com/ path? or different subdomains?

Ubuntu LAMP with Zend directory structure for web hosting

I have setup the basic LAMP server on Ubuntu 11.10 and had a few questions about directory structure with web hosting. My "requirements" are that I would like to host two websites (ie: www.site1.com and www.site2.com) and also that I would like to use the Zend framework.
Currently, the public folder is /var/www/. Is it common to have a "Projects" folder somewhere containing all of the web application code which generally will consist of the Zend project folders (public, tests, library, etc)?
Where do you "normally" store the Zend framework folder? I was thinking of just storing in in my ~/ directory and creating a symlink from each project's library folder to the Zend library folder. Is this recommended/frowned upon?
I'm new to this and just getting setup, but here is what I had in mind so far:
Create a projects folder in your home directory (~/). Under there, have your different web apps (~/Projects/site1 and ~/Projects/site2). Create a symlink from /var/www/site1 that points to ~/Projects/site1/Public and the same for site2. Setup the virtual hosts file with DocumentRoot set to /var/www/site1 and the same for site2.
Can anyone shed any light on the possible pitfalls of this? Would this be alright to do? Any recommendations? I know there are many versions of how you should setup directories here on SO, but couldn't find any answers that addressed these things specifically, so I apologize if this is a repeat.
Any help is appreciated.
Yes, there are lots of ways to do it, just keep in mind a few things:
The user that owns the HTML/PHP files should not be the same as the user that runs the web server process.
The ZF project files should be outside the web server's document root.
If you make a setup now that's conducive to having multiple developers, you won't have to make big changes later.
I usually do something like make a "site" user with a regular /home/site directory. This keeps the site files separate from your personal files and makes it easier to support multiple admins/devs that might need to login. You can also put this in /opt/site or /usr/local/site or wherever. I like /home because the shell skeleton files are already there and I can easily add SSH keys of the people I want to have access. I'll have something like:
/home/site/
library/
fuel/
geshi/
sencha-touch-2.0.0-gpl/
ZendFramework/
ZendFramework-1.11.10/
ZendFramework-1.11.11/
latest -> ZendFramework-1.11.11
site/
domain1.com/
application/
library/
MyApp/
Zend -> /home/site/library/ZendFramework/latest/library/Zend
public/
scripts/
domain2.com/
application/
library/
MyApp/
Zend -> /home/site/library/ZendFramework/latest/library/Zend
public/
scripts/
Then, your vhost document root settings would point to /home/site/site/domain1.com/public and /home/site/site/domain2.com/public
Directory structures aren't something that there is a right or wrong way to do, lots of people do it in different ways, here is mine with Ubuntu and some CakePHP apps
/srv
/site1/
/app
/webroot
/cache
/tmp
/site2/
/app
/webroot
/cache
/tmp
/share/
/CakePHP
/1.3/
/2.0/
The two main parts of the configuration are done in apache, I set the Document Root of the vhost to the exact location of the webroot to /srv/site1/webroot/, then I put CakePHP in the include path (you could do the same with Zend) by using the php_value include_path ".:/share/cakephp/2.0/lib" in the vhost config.
I do this because it allows me to upgrade CakePHP with maintenance releases easily to all sites, (ie ones that shouldn't break anything) and a new release will warrant a new folder (ie 2.1), and upgrading a site to use it is simply a case of editing the apache config (or .htaccess) and restarting the server.
This also keeps me from having to include any sort of include path in my app (and therefore version control) so it's as portable as possible across different dev/staging setups.
Of course as I said, there isn't one "right" way.

.htaccess file for Uploading a Zend Framework Project on 1and1

The problem I have is that I am trying to put a Zend Framework web application online and while it works perfectly on my localhost, it has a lot of errors online. I know that there are certain things required for a Zend website to work.
I need the document root to be serwano.com/staging/fbr
I need php5
I need mod rewrite on
I need the document root to be serwano.com/staging/fbr.
I have a testing website with the following folder set up:
/webroot(serwano.com)
/staging
/other test site
/other test site
/fbr
/application
/library
/public
I need help determining what the appropriate .htaccess file would be so that my Zend Web App will work.
You can figure the webroot for a domain to point to any folder insider your FTP upload directory, thus you can do
+ userhome
|- serwano.com
|-- staging
|-- test
|-- production
Then go to your 1&1 control panel and create three subdomains for serwano.com. There should be an option to point each subdomain's webroot to the appropriate folder, e.g.
staging.serwano.com // point it to the staging folder
test.serwano.com // point it to the test folder
www.serwano.com // point it to the production folder
Whether you can use .htaccess and mod_rewrite depends on how your webhosting package is configured. Contact 1&1 (prepare for pain) to find out if that is possible. If it is not possible, Google has a number of results for Zend Framework without .htaccess. You do not need mod_rewrite, nor .htaccess. This is just recommended.

Zend - How to install on WAMP

If there is an easy to follow instruction or tutorial that I can use to learn how to install Zend on my machine that has a WAMP installation?
The video listed
http://www.zendcasts.com/getting-started-with-zend-and-wamp-server/2009/06/
is hard to read what he is writing.
Thank you
Conceptually, the whole thing is:
Create virtual host pointing it to the sample app
Make sure that PHP include_path contains the path to the Zend library.
But the specifics can be tricky if you are not accustomed to it. So here is at least a little bit more color.
Create a folder for your app, something like C:\apps\myapp.
Copy a sample ZF app - like this or this - into that space so that the myapp folder has the typical subfolders like application, library, public, tests, etc.
create a virtual host within your Apache. This is a two step process:
3.1 Modify your hosts file - on my WinXP machine, it resides in the folder C:\windows\system32\drivers\etc to contain a line like
127.0.0.1 myvirtualapp
I am intentionally choosing a virtual host name myvirtualapp that is different from the app folder name myapp to demonstrate that they are conceptually different creatures. One is a name that the OS and Apache recognize as an HTTP host; the other is a local filesystem path.
3.2 Add an entry into Apache's vhost file - typically in the Apache folder hierarchy at something like conf/extra/httpd-vhosts.conf. A minimal entry there will look something like this:
<VirtualHost *:80>
DocumentRoot "C:/apps/myapp/public"
ServerName myvirtualapp
</VirtualHost>
Restart Apache.
Make sure that the Zend library is copied into your c:\apps\myapp\library folder, so that there is a subfolder named Zend with the rest of the library contained inside.
Make sure that the folder c:\apps\myapp\library is on your PHP include path. There are many ways to do this, but typically this is done in c:\apps\myapp\public\index.php. Usually, that library folder is referenced in index.php as realpath(APPLICATION_PATH . '/../library').
Browse to the url: http://myvirtualapp/
With any luck, you should see the app!
Even though Zend Core is being phased out, it might be easier for you to use this instead of WAMP. Zend Core is similar to WAMP, but includes the framework too.
The Zend Server Community Edition, which is what is replacing Zend Core might also suit your purposes.

Problems with setting the path for Zend framework, needed for Youtube API

I copied & pasted this text here. It seems the editor seems to format some parts randomly. ;)
I downloaded ZendGdata 1.9.6, extracted it & uploaded it to my site's
root folder ..., which I need for use with Youtube API to get videos onto my site.
I must say I’m new to all this, and so I would appreciate taking this into account.
The library folder is at /ZendGdata/library.
The problem I'm having is Step. 3 when I follow instructions
(http://code.google.com/intl/de-DE/apis/gdata/articles/php_client_lib.html#gdata-installation)
for setting it up for that purpose.
Download the Google Data Client Library files.
Decompress the downloaded files. Four sub-directories should be
created:
demos — Sample applications
documentation — Documentation for the client library files
library — The actual client library source files.
tests — Unit-test files for automated testing.
Add the location of the library folder to your PHP path (see the next section)
One of the suggested locations to add the path, apart from the .htaccess file is in php.ini.
My site is on shared hosting. I have no access to the main php.ini file, but I’m allow to create one if I need one. For Drupal CMS, for some functions, it suffices placing one in the root folder.
I added this line:
include_path=".:/usr/lib/php:/usr/local/lib/php:/home/habaris6/
public_html/site.root.folder/ZendGdata/library";
When I however go to mysite.com/ZendGdata/demos/Zend/Gdata/InstallationChecker.php to test the set up, like is mentioned in the
documentation on Youtube, I get the error:
PHP Extension ErrorsTested No errors found
Zend Framework Installation Errors: Tested 0
Exception thrown trying to access Zend/Loader.php using 'use_include_path' = true.
Make sure you include Zend Framework in your include_path which currently
contains: .:/usr/lib/php:/usr/local/lib/php
SSL Capabilities Errors: Not tested
YouTube API Connectivity Errors: Not tested
So my question is: Is that the correct way to “Add the location of the library folder to your PHP path” ?
I’m a bit mixed up.
Someone was saying the php.ini file is only active in the folder where it is located. If that is the case, which of the ZendGdata folders should have it?
As I said, my purpose is to have a the Zend framework properly set up to allow using Youtube API, something I also yet have to learn to do.
In Youtube API Google group, I was referred here. The documentation coming with the downloaded file & at zend.com pre-supposes, one knows much more than some beginners like me.
Another person said I try placing this
$clientLibraryPath = '/home/habaris6/public_html/site.root.folder/ZendGdata/library';
$oldPath = set_include_path(get_include_path() . PATH_SEPARATOR . $clientLibraryPath);
in mysite.com/ZendGdata/demos/Zend/Gdata/InstallationChecker.php
Whereas everything I had tried before failed, except fot the first test, when I placed the above snippet in the installation checker, I got positive tests for everything:
Ran PHP Installation Checker on 2009-12-09T21:16:08+00:00
PHP Extension ErrorsTested: No errors found
Zend Framework Installation Errors Tested No errors found
SSL Capabilities ErrorsTested No errors found
YouTube API Connectivity ErrorsTested No errors found
Does it mean if I place that snippet in install checker, all scripts needing the library can access it?
If not, please let me know what exactly to place in the self-made php.ini & in which folder(s) it should be.
Should that not work, and I were to use .htaccess files, what exactly, based on the folders mentioned above should be the content & exactly which folders should they be in? I read that the .htaccess files should be placed in each folder. Does it really mean I should place one in each of the ZendGdata folders?
I would be grateful for any guidance enabling me to finally start, after failing to sufficient get responses elsewhere.
Thanks in advance.
It's not necessary to put all the ZendGdata code under your website document root. In fact, as a rule I don't put PHP class libraries in a location that can be accessed directly by web requests, because if there's any way to do mischief by invoking the class files directly, then anyone can do it.
Instead, put libraries outside your document root and then reference them from scripts that are run directly. For example, you could create a directory phplib as a sister to your public_html directory. Then upload the ZendGdata bundle under that phplib directory.
You can set your PHP include path in a .htaccess file. You don't need to create a .htaccess file in every directory, because the directives in any .htaccess file apply to all files and directories under the directory where the .htaccess resides. See http://httpd.apache.org/docs/2.2/howto/htaccess.html for more information.
So I would recommend creating a .htaccess file at /home/habaris6/public_html/site.root.folder containing the following directives:
<IfModule mod_php5.c>
php_value include_path ".:/usr/local/lib/php:/home/habaris6/phplib/ZendGdata/library"
</IfModule>
See http://php.net/manual/en/configuration.changes.php for more info on this.
Note that this assumes your webhosting company allows you to use .htaccess files, and that they allow you to use the php_value directive in .htaccess files. Enabling these options is an Apache configuration and they could have their own policies against that for reasons of performance or security. You should contact them for this answer; no one on the internet can answer questions about your hosting provider's policies.
If you choose to use the set_include_path() PHP function to append a directory to your runtime include path, you need to do this in each file that serves as a landing point for a web request. That is, if you permit a request to be made directly to foo.php then you need to add the code to foo.php. Any files or classes subsequently included by foo.php use the include path you defined.
Note also that whatever method you use to define the include path, it has to take effect before your script tries to load any PHP class files via the include path. The .htaccess method should accomplish this, and if you use the code method you just have to put the code high enough in your PHP script.
I don't use the method of creating a custom php.ini file under each directory within your site document tree. That's a new feature of PHP 5.3.0, not supported by earlier versions of PHP. If you're using Apache you should just use .htaccess for the same effect.