I'm trying to deploy an PHP application which is written with Zend Framework to a shared cPanel server.
There are not many tutorials available on this area online, however, I followed several of them. It is successful to run the test page which proves the zend framework is installed correctly.
However, since cPanel server has a default root directory called public_html/, it is impossible to simply rename it to the Zend Server's default public/.
As a result, I had two options in mind: (Say the project name is AAA)
1) upload my projects under the /public_html/ directory, then the project will be like /public_html/AAA/public, and etc.
However, this one simply fails to work.
My thought would be something wrong here with the baseUrl setting, however, no matter I comment ( which is to remove the baseUrl) or set to the root page, ( in this case /public_html/AAA) both failed.
2) I tried to follow the way listed in this article: http://blog.motane.lu/2009/11/24/zend-framework-and-web-hosting-services/. Still failed.
Can anyone suggest how to do it?
Really appreciate your help!
Just symlink it:
ln -s public public_html
then this structure will work:
htdocs/
myvhost.com/
public/
application/
library/
public_html # this is actually a symlink pointing to public
Whatever you do, dont just throw everything in the publicly accessible area... its just bad form :-)
I don't think ZF cares what you name your "public" directory. It's just the convention that's typically used.
I can't think of any ZF component or common use case where anything explicitly points at "public/...".
A project structure like this should work:
myproject/
application/
library/
public_html/ # this used to be public until you renamed it.
Related
Is there any way to change the default folder structure of zend framework 2?
My specific need is to remove/rename public folder.
Also, I would like to remove public from URL also.
I tried many things using htaccess but nothing works for zend 2.
The default folder structure is just a convention, there's nothing particular that relies on it. However, it is a sensible convention, and instead of trying to change it you should probably try and fix the real problem instead.
If public/ is appearing in the URL, either your VirtualHost is not setup correctly or you're using shared hosting and can't change the VirtualHost. The installation instructions have example vhosts for Apache - the key thing is having your document root pointing at the public folder, not the application root.
I completed the quickstart tutorial, but I feel really unclear on a few things. I started the guide initially expecting everything to be on my remote server, but it actually seems to be a guide for a local setup. I have everything on my server, and I have the hosts file on my local computer routing to the server, for ex. this is the entry in my hosts file server-ip quickstart.local.
1) Currently, I have everything beneath public_html. Where should I put all the Zend files (bin, demos, incubator, etc..)? www/public_html/[zend-files],www/public_html/quickstart/
2) Where do I put the quickstart (project) folder? Am I supposed to create an index.php that routes to the public folder in the project folder? At the moment, it is at public_html/quickstart/.
I feel silly and embarrassed for asking, because I feel like this is something really obvious.
Actually, you'll need only the Zend folder, which is the library itself.
On the public_html you need to put only the files located in the public folder of your project.
Folders like application and library should stay out of public_html.
For example
/home/my_project/public_html (public folder from zend)
/home/my_project/private (the other files, like application and library)
Instead of put the Zend library inside your project library folder, you can put it on the php include_path.
The second option, maybe the best, is to configure your virtual hosts and set the public folder (application public folder) as the root folder for your domain quickstart-local
So, you will end up with /home/my_project/public as your root folder and /home/my_project/application as your private folder.
You'll need to setup your index.php and application.ini with the appropriated paths.
As soon as you work with more than one framework version at a time, using symlinks becomes a good option. It is also much better for development than using the include path because you automatically have code assist for ZF code. We organize our projects as follows:
/application
/httpdocs
/library
/Project
/Zend (->symlink to the Zend folder of the needed version)
/ZendX (->dito)
/tests
And now, if you're about to say that 'symlinks' don't work on Windows, don't say it. It's utter rubish. It works perfectly well.
On my local setup I have a load of different CakePHP websites. I'm using a Mac so the folder structure is something like ~/Users/cameron/Sites/sample-website and then within each of these websites I will have the typical Cake folder and App folder.
What I would like to do is have just a core cake folder and then have ALL the sites pull from that one cake core so I don't have the same stuff several times over. I have been reading some tutorials on the web: http://rickguyer.com/cakephp-one-core-many-apps/
So I have my cake folder here: ~/Users/cameron/Sites/cake-1.3/ and then my site here: ~/Users/cameron/Sites/sample-site/ and in this folder I have the usual app folder and htaccess to tell it where to find webroot etc.
Now I have edited the index.php file inside webroot like the tutorial BUT have only changed one line because I haven't moved my files OUTSIDE of the App folder like he does. So the only like I have changed is as follows:
if (!defined('CAKE_CORE_INCLUDE_PATH'))
{
define('CAKE_CORE_INCLUDE_PATH', '..'.DS.'..'.DS.'cake-1.3');
}
As far as I can tell that is correctly looking two directories up and finding a folder called cake-1.3 however it just gives a error 500?
Any ideas what the problem is? Thanks
EDIT:
Even doing this doesn't work???
Which If I echo: echo CAKE_CORE_INCLUDE_PATH; gives /Users/cameron/Sites/cake-1.3 and if I paste that in the address bar it loads up the cake folder so it's definitely the correct folder structure JUST it doesn't like looking at cake outside of the main url?
if (!defined('CAKE_CORE_INCLUDE_PATH'))
{
define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3'); echo CAKE_CORE_INCLUDE_PATH;
}
You are right on the money with:
define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3');
Just make sure that Users sits in root. In other words, when you go to terminal you can get to this directory by typing: cd /Users/cameron/Sites/cake-1.3
It looks like you may be on a MAC. If so, your linking is correct. Most of the time what I find is you have done a copy paste of the app directory and it does not get the .htaccess files. I would check those first. But here is a comprehensive list of what you should verify:
Make sure the host is pointing to
the correct directory
(/Users/cameron/Sites/sample-site/)
Verify mod_rewrite is in fact on.
Verify you have copied the .htaccess
file in both the
/Users/cameron/Sites/sample-site/
and the
/Users/cameron/Sites/sample-site/webroot
directories.
Confirm that the
/Users/cameron/Sites/cake-1.3/
directory has a directory called
cake in it that contains the core.
Once all of this is confirmed, you will be good as gold!
Happy Coding!
UPDATE:
When the index.php file looks for the cake core, it will look for a directory inside the location you are pointing to for another directory called cake. So in your case:
define('CAKE_CORE_INCLUDE_PATH', DS.'Users'.DS.'cameron'.DS.'Sites'.DS.'cake-1.3');
You must have the cake directory inside /Users/cameron/Sites/cake-1.3. Your directory structure will look like:
/Users/cameron/Sites/cake-1.3/cake
/Users/cameron/Sites/cake-1.3/cake/libs
/Users/cameron/Sites/cake-1.3/cake/config
/Users/cameron/Sites/cake-1.3/cake/console
etc.
CakePHP 3.0+
In CakePHP 3.0+ this configuration is moved out of webroot/index.php to App/Config/paths.php
If you have access to your php.ini, you can add the path to Cake core there. Doing it this way means you don't have to change webroot/index.php at all. Example in php.ini:
include_path = ".:/usr/local/lib/php:/home/something/phpinc/cakephp2/lib"
According to the CakePHP 2.x docs, this is the recommended way to share the Cake core (assuming you have access to your php.ini).
You can have only one cake core but you must have one app folder (containing MVC) by site.
Is this a misunderstanding of the folder structure of CakePHP?
From the docs (CakePHP folder structure):
The app folder will be where you work your magic: it’s where your application’s files will be placed.
The cake folder is where we’ve worked our magic. Make a personal commitment not to edit files in this folder. We can’t help you if you’ve modified the core.
So the cake folder shouldn't change between all of your uses, therefore you have 1 copy. You can always change some of the functionality of the core by making your own changes in the app folder i.e. extending.
There is no need to edit index.php.
Just put an alias (or link in UNIX) to your cake folder in each of your sites folder. Works perfectly. Same goes for plugins and vendors folder.
I am a cakephp newbie and I had trouble to view the files under the view folder through browser.
I used cakephp console to bake model, controller and views. (ex: Invoices_controller.php for controller, invoice.php for model and a invoices folders under views folder). According to the tutorial I read, I can access the invoice view by typing http://localhost/myProject/invoices
(there is no index.php inside the invoices folder..but the tutorial shows it still can display a page. no idea how they did it)
The path for my invoices is myProject/views/invoices and there add.ctp, index.ctp, edit.ctp files inside the invoices folder.
The browser showed the file is not found when I typed http://localhost/myProject/invoices
You have some lack in your knowledge about how the webserver handling a request when cakephp is installed. Assume that we use apache.
In cake's folder structure you can see .htaccess files in the root, app and webroot directories what have url rewrite rules in them. At the end a normal request to a cakephp site will be transformed to a http://site.url.root/app/webroot/index.php?url=original.url
In nutshell to understand it in your point of view:
That index.php call the required php files and at least a cakephp app object is built up in the memory with the required models and methods. Then the app object let say start and calls its methods (model, controller and view methods) and at the end it gives back a result to apache what serves it to you.
Therefore the original url path is a "non existent" virtual url.
If you enter http://localhost/myProject/ do you get a cake intro page? If so does it highlight any problems?
It sounds to me as if you do not have Apache set up properly. I don't know what OS you're using, but it might be worth checking this link, written for Ubuntu, to make sure all is well: http://leoponton.blogspot.com/2010/05/getting-cakephp-up-and-running-on.html
I fixed the same problem.
if you are using windows 7 os, wamp server, cakephp 2.2.3. then
goto apache -> http.conf -> open -> search for mod_rewrite -> uncomment the line LoadModule rewrite_module modules/mod_rewrite.so
Now restart your server, now it should work fine.
Jerry, I think the issue is this. You have put the CakePHP folder in the root of localhost. I would propose that you create a virtual host pointing the myProject so the url becomes:
http://myProject/accounting
This may solve your problem. Be sure rewrite module is on. Also, when you point the virtual host to myProject, it should be the APP folder of the cakephp. If you want to run multiple projects off the same core, you can set them up like so:
/var/www/cake
/var/www/html/myProject
/var/www/html/myProject2
The /var/www/cake directory is where you drop the cake core. Under this directory you will have cake, app, plugins, vendors, etc. the myProject(2) directories will be the contents of the app directory.
Now, to get this to work, you need to go to /var/www/html/myProject/webroot/index.php and edit it to point to the cake directory in /var/www/cake. This will then load the core when rewrite points to index.php in webroot. You should be good to go!
I've just started learning cakephp and have gotten the Blog example working except for the routing, I'm still not quite sure how it works after reading many, many documents on routing (including the ones in the official cookbook).
My problem is with the '/' root routing, I want it to go to the index() function of the PostsController so I use:
Router::connect ('/', array('controller'=>'posts', 'action'=>'index'));
But this doesn't work if I go to the url: localhost/
This is probably (most definetely) because I don't know where to put the cake_1_3 folder/installation, currently my directory tree for localhost (in htdocs) looks as follows:
-htdocs>posts>cake_1_3
This means that when I navigate to: localhost/ I get nothing and when I navigate to: localhost/posts/ I get nothing, just the directory listing for the folder "posts" which shows I have the directory "cake_1_3".
It is only when I go to the url: localhost/posts/cake_1_3/posts/ does the routing work, as in it sees the second "posts" and so runs the "index" function of "PostsController".
Obviously this isn't what I want, I want to be able to go to: localhost/posts/ and it use the index function of the PostsController.
Update: I actually tried taking all the cakephp stuff out of "cake_1_3" and just into "posts" but then I have to go to: localhost/posts/posts/ for it to use the index() function of PostsController.
Is there any way I can just navigate to localhost/posts/ and I'll get the index() function of the PostsController running?
I know this is probably a very simple problem and I'm just missing something because I'm so tired (well that's my excuse anyway), but I've been searching around for about 3 hours now and wouldn't mind a helping hand.
Thanks for your time,
InfinitiFizz
P.S. I've just realised I can dump all the cakephp installation files/folders into the root (htdocs) and then localhost/posts/ will work but I've got loads of different test websites in their own folders in htdocs/ and so I'd rather have this posts test in its own folder too, not have all the cakephp folders mixed up with all the other websites' folders.
Just to be clear what directories we're talking about, a Cake installation comes with these folders:
/
app/
webroot/
cake
You will have to hit the top / directory with your browser to get a response from Cake at all. All routes are relative to that top / directory.
Let's say you have installed Cake in your web server like so:
/
htdocs/
someotherproject/
mycakeapp/
app/
webroot/
cake/
The htdocs directory is the root of your web server. If you go to http://localhost/, your web server will respond with the contents of /htdocs/. It's not even invoking Cake, so Cake can't route anything.
You'll have to open http://localhost/mycakeapp/ to invoke Cake. From there, Cake will do its routing. The Cake route Router::connect('/', …) corresponds to the URL http://localhost/mycakeapp/. All Cake routes are relative to the app installation path. The Cake routing is app-internal routing, it does not correspond to the absolute URL.
If you want http://localhost/ to be your Cake app, Cake will need to be the only app residing in /htdocs/. You can't have multiple apps in the root and yet have any one of them be "the root app"†‡.
For local development purposes this should be perfectly fine. When uploading the app to a real server with a real domain you'll usually make it the one and only app.
† Well you could, with elaborate rewrite-rules, virtual host configurations or by placing files in Cake's /app/webroot/ folder. Usually more hassle than it's worth though, keep your projects separate.
‡ You can't have your Cake and eat it, too. zing