Zend Framework accessing controllers through URLs - zend-framework

I am starting to learn Zend Framework with book Beginning Zend Framework (Apress), I have trouble aceesing different controllers through URL. I setup the directory structure for Zend Framework and setup Apache2.2\htdocs\testproject\public as the default for localhost. If i try to access a different controller by typing localhost/new I get a 404(Not Found).
My directory structure looks like this:
htdocs
--testproject
----application
------configs
------controllers
--------IndexController.php
--------NewController.php
------models
------views
------Bootstrap.php
----docs
----library
----public
----tests
----.zfproject.xml

Make sure you have enabled apache's rewrite module.
Make sure you have AllowOverride All in your httpd.conf settings.
Can you confirm above points and restart your apache and try once again? I am sure you won't face this problem again.

Related

Zend framework deployment in Bluemix

We would like to deploy Zend framework in Bluemix. We used the recommended buildpack https://github.com/zendtech/zend-server-php-buildpack-bluemix, however it does not help. For deployment we need to change Document Root to their 'public' folder.
In practice it can be done via changing apache configs or adding htaccess file. So we are not able changing the apache configs, therefore we added htaccess file for it. The folder has been created and via htaccess the document root has been changed (it works). But when the framework has been pushed it does not work (The blank page is appeared without PHP run-time errors).
There is a environment variable that configures the document root for an application using this buildpack:
ZEND_DOCUMENT_ROOT.
Using this instead of the htaccess rewrite rules should work.

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.

Zend framework deployment on the shared hosting

I want to deploy my project made in zend framework to my shared hosting.
My project has such structure:
application
docs
library
Obsolete
public
scripts
tests
This is what I have done:
I copied Zend folder (all library files) into library folder
I copied all the structure above into public_html/projects/project
(so if I type www.mydomain.com/projects/project/public I run the project
I tried to click on some link so that it redirected me to www.mydomain.com/projects/project/public/someController/someAction
Unfortunately all i see is a white, empty page.
Locally (using Zend server CE) it worked perfectly
Here it looks like Zend doesn't recognize that it should do anything with this url and redirecto to appropriate action.
What have I missed?
Greetings!
The reason you see empty page instead of errors is that error_reporting is probably off by default on your production server.
You may change the settings concerting displaying errors and exceptions in application.ini.
The other cases the errors are not displayed is something goes wrong in the view (eg. view helpers), which must return string, not the exception.
Things to check:
paths
include_path
permissions to write for files/dirs which do require this
PHP version
.htaccess setup
stating the obvious here but I'd check your apache error log.
You should check if the server is running php as a module or CGI, in the later case it will not read the SetEnv of .htaccess and you will have to set to development mode in index.php by hand, or specify your config in php.ini

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.