One CakePHP library for multiple apps - cakephp-2.0

I have developed several small websites in CakePHP and one medium news site. However, the situation I am in right now is different and require some toughful analysis before proceeding, which brings me to the CakePHP community.
I am working for a company which currently uses straight PHP code to handle several websites (5 - 10) and all of them use one global includes folder which has things like Db connection, etc. The problem with all this, is that we want to upgrade everything to the latest version of PHP (Currently using 5.1) and in the process, I am thinking about upgrading our whole backend using CakePHP.
First of all is this a good idea? I get excited when working on CakePHP projects and have never had any issues.
Secondly, I have read from Cake experts that we should not add anything to the core side of Cake. However, if I am to create files that need to be accessed by all the sites, where could those go?
Currently, all the sites are OOP, but Cake is MVC. Should the global OOP classes(used by all sites) be converted to controllers/models or Vendor classes and placed in the Cake Core?
In general, what is the best approach?

You can do that
The layout of a standard cakephp install is:
root
/app
..
/Plugin
/Vendor
/webroot
/lib
/Cake
/plugins
/vendors
Everything inside the app directory is specific to one application. The root lib, plugins and vendors directors apply to all applications in the install. I.e. without modifying anything you can do this:
$ cd root
$ cp -r app newapp
resulting in:
root
/app
..
/Plugin
/Vendor
/webroot
/newapp
..
/Plugin
/Vendor
/webroot
/lib
/Cake
/plugins
/vendors
Any plugin or vendor that is in the plugins or vendors can be loaded, without doing anything out of the ordinary, in both applications e.g. with the following:
root
/app
..
/Plugin
/Vendor
/webroot
/newapp
..
/Plugin
/Vendor
/webroot
/lib
/Cake
/plugins
/DebugKit
/vendors
Both applications have the option to load and use debug kit.
You can also simply follow the instructions in the book which does the same thing but separating the location of common code from the applications themselves.
Be aware of the limitations of sharing dependencies
The problem with managing multiple applications like that is that all applications are tied to the same version of cake, and the same version of all shared plugins/vendors. CakePHP is not an idle project, it is in constant development - as are, likely most plugins/vendors you choose to use. For plugins and vendors that's easy to solve, the application Plugin/Vendor folder is checked before the install-wide folders.
However, rather than have one core and n apps - it's a more robust idea to have n complete installs for n applications:
/root
/myapp
/app
/Plugin
/Vendor
/webroot
/lib
/Cake
/plugins
/vendors
/app2
/app
/Plugin
/Vendor
/webroot
/lib
/Cake
/plugins
/vendors
etc.
That way a new application can for example use the current version of Cake, without affecting any existing applications at all.

Related

cakephp - apache - turn off directory browing of tmp folder

It seems cake's tmp folder is browse-able (if you go to localhost/tmp it shows all the files I put there), how can I turn this off without breaking anything?
I tried adding .hacccess file to that folder with - Options -Indexes - didn't work
I tried adding index.html - didn't work.
I am afraid to mess with the apache config files because it was a nightmare to get cake & php and everything working properly....
Why would cake have this on by default, isnt it a security issue? (at least the scan tool my client ran flagged it).
thanks
Joel
Something is definitely wrong with your setup that has nothing to do with CakePHP. Your webroot (localhost) should be at this location: app/webroot and the tmp should be at app/tmp. In order for you do access http://localhost/tmp, tmp would have to be at app/webroot/tmp or you are redirecting it, which is not how CakePHP is designed to be setup.

Using bake on shared hosting Cakephp

I'm trying to get bake working on my subdomain which is under shared hosting.
Is there a way we can get this working? I know how to connect to server via ssh shell but then what do I do after that?
First cd to the directory where the cake script is. On a Linux webserver, this would probably be something like ~/cake/console/, if you've put the CakePHP libs outside your web-accessible directories. If you've put everything into your web directory you'll probably have to go somewhere like ~/www/cake/console/.
Then simply type ./cake bake and take it from there.
You shouldn't have to do anything with environment variables. This is only necessary if you want to be able to run the cake console from any directory. I find it less of a hassle to just cd into the cake console's directory and run it using ./cake.
same as local machine cd <path_to_console> cake
if you do not know path_to_console ask for host support,
also path_to_console may be in environment path then just use cake in all dirs

Having trouble getting cake bake to work

I've installed the latest version of CakePHP on a Ubuntu 10.10 machine. I was able to run through a beginner tutorial just fine so I think my configuration is close to being correct. I can't get cake bake to completely work though. Below is my session. Things that look like anomolies are in bold. I think I must have one or more small errors in my configuration that are manifesting when running the bake shell. Thanks!
ubuntu#myserver.com:~$ cd /var/www/app
ubuntu#myserver.com:/var/www/app$ ../cake/console/cake bake -app /var/www/app
Failed loading /usr/lib/php5/20090626.so: /usr/lib/php5/20090626.so: cannot open shared object
file: No such file or directory
Welcome to CakePHP v1.3.2 Console
App : app
Path: /var/www/app
Interactive Bake Shell
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[F]ixture
[T]est case
[Q]uit
What would you like to Bake? (D/M/V/C/P/F/T/Q)
P
What is the full path for this app including the app directory name?
Example:/var/www/app/myapp
[/var/www/app/myapp] > /var/www/app
Bake Project
Skel Directory: /usr/share/php/cake/console/templates/skel
Will be copied to: /var/www/app
Look okay? (y/n/q)
[y] > y
Do you want verbose output? (y/n)
[n] > y
Created: app in /var/www/app
/usr/share/php/cake/console/templates/skel/app_controller.php copied to
/var/www/app/app_controller.php
/usr/share/php/cake/console/templates/skel/app_model.php copied to
/var/www/app/app_model.php
/usr/share/php/cake/console/templates/skel/index.php copied to /var/www/app/index.php
/usr/share/php/cake/console/templates/skel/.htaccess copied to /var/www/app/.htaccess
/usr/share/php/cake/console/templates/skel/app_helper.php copied to /var/www/app/app_helper.php
Creating file /var/www/app/views/pages/home.ctp
File /var/www/app/views/pages/home.ctp exists, overwrite? (y/n/q)
[n] > y
Wrote /var/www/app/views/pages/home.ctp
Welcome page created
Random hash key created for 'Security.salt'
Random seed created for 'Security.cipherSeed'
Unable to set CAKE_CORE_INCLUDE_PATH, you should change it in /var/www/app/webroot/index.php
Could not set permissions on /var/www/app//tmp
chmod -R 0777 /var/www/app//tmp
Interactive Bake Shell
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[F]ixture
[T]est case
[Q]uit
What would you like to Bake? (D/M/V/C/P/F/T/Q)
q
ubuntu#myserver.com:/var/www/app$
Mark Murphy,
1.
Failed loading /usr/lib/php5/20090626.so: /usr/lib/php5/20090626.so: cannot open shared object
*.so files are shared libraries. I would try to tackle it be (re-) installing the PHP CLI.
2.
Could not set permissions on /var/www/app//tmp
How could the slash creep in twice? Such a folder should not exist.
Edit0:
It is a bit strange, as CakePHP should work right out of the box, but maybe you really should take a look at the specified variable in app/webroot/index.php and see if you can change the CAKE_CORE_INCLUDE_PATH so that the superfluous slash vanishes.
Edit1:
For general deployment there is nothing better than this afaik.
Edit2:
cake bake help returns:
-app Absolute/Relative path to your app folder.
Hence you should call either:
cake bake app /var/www/<your_project_name>/ <---- note the trailing slash
or
when in /var/www/ call cake bake app <just_your_project_name>
Edit3:
In a nutshell: You could download the CakePHP tar.gz and unzip it in your /var/www/, then rename the folder (having some weird cakePHP-1234... name) into the name of your application, e.g. missioncontrol. Then in your browser: http://localhost/missioncontrol , proceed as instructed.
This is a very quick method to get going, but you can develop other methods according to your build process.
After you have developed your app and intend to deploy it on a host different than your local machine, use the link provided under edit1.

How exactly does Tomcat run out of CATALINA_HOME and CATALINA_BASE

I'm having trouble finding documentation regarding this. After some googling I find that bin, conf,logs, temp, webapps, work are directories that should exist in CATALINA_BASE.
temp, logs, webapps, bin and work I don't have any trouble understanding.
bin I suppose is just another bin folder, if for some reason both CATALINA_HOME and CATALINA_BASE are in PATH, then scripts in both folders will be available for execution.
But how about conf? Will the content of CATALINA_HOME/conf be totally ignored if CATALINA_BASE is set? Suppose I only would need to customize only a few config files pr. CATALINA_BASE, would I still need to keep a complete set of config files in CATALINA_BASE/conf, or could the standard config files in CATALINA_HOME/conf be shared?
And ditto for CATALINA_BASE/lib ... would this work as a "global" lib folder pr. instance?
You can find the answer in the Tomcat documentation:
http://tomcat.apache.org/tomcat-6.0-doc/RUNNING.txt
Advanced Configuration - Multiple Tomcat Instances
In many circumstances, it is desirable to have a single copy of a
Tomcat binary distribution shared among multiple users on the same
server. To make this possible, you can set the $CATALINA_BASE
environment variable to the directory that contains the files for your
'personal' Tomcat instance.
When you use $CATALINA_BASE, Tomcat will calculate all relative
references for files in the following directories based on the value
of $CATALINA_BASE instead of $CATALINA_HOME:
bin - Only setenv.sh (*nix), setenv.bat (windows) and tomcat-juli.jar
conf - Server configuration files (including server.xml)
logs - Log and output files
webapps - Automatically loaded web applications
work - Temporary working directories for web applications
temp - Directory used by the JVM for temporary files (java.io.tmpdir)
Note that by default Tomcat will first try to load classes and JARs
from $CATALINA_BASE/lib and then $CATALINA_HOME/lib. You can place
instance specific JARs and classes (e.g. JDBC drivers) in
$CATALINA_BASE/lib whilst keeping the standard Tomcat JARs in
$CATALINA_HOME/lib.
If you do not set $CATALINA_BASE, $CATALINA_BASE will default to the
same value as $CATALINA_HOME, which means that the same directory is
used for all relative path resolutions.

cakephp baking in windows 7

I'm new to cakephp so have just been working through the cookbook and am now working through "Beginning CakePHP from Novice to Professional" by Apress. I have got to the Bake section of the book but I can't seem to get it working in windows 7.
I have added the path to my "Environment Variables" so I don't have to navigate to the location of cake.bat but I can't seem to get baking to work.
I type cake bake -app C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\testBlog\app\ and get:
Microsoft Windows [Version 6.1.7600]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users\Poncho>cake bake -app C:\Program Files (x86)\Apache Software Foundation
\Apache2.2\htdocs\testBlog\app\
♀
Welcome to CakePHP v1.3.3 Console
---------------------------------------------------------------
App : Program
Path: C:\\Program
---------------------------------------------------------------
Bake Project
Skel Directory: C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdo
cs\testBlog\cake\console\templates\skel
Will be copied to: C:\\Program\Files
---------------------------------------------------------------
Look okay? (y/n/q)
[y] >
If I type 'y' (without quotes) it runs through some stuff then asks me for the db config, I put all the info in and it finishes saving the db config info and then ends. When I try cake bake again, I just get the above screen again, everytime I try it seems to not understand I've set it up before with the Skel Directory being copied and the db info being configured.
Any idea what could be wrong?
Thanks in advance.
P.S.
My app location is at: C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\testBlog\
well thats where all the cakephp stuff is. Should I have the cakephp core seperate from each app folder? Or should each app have its own cakephp stuff?
For example, should I have my cakephp files and folders (cake, plugins, vendors, etc.) in C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\ and then each app in its own folder as in testBlog/app or is how I've done it okay?
Thanks All,
Infiniti Fizz
Judging by the output of the bake tool, spaces in the path seem to throw it off. Try moving your htdocs directory to a location without spaces, e.g. c:\htdocs and see if that helps.
To tell Apache that the location of the htdocs directory has changed, find the httpd.conf file (it should be somewhere under your Apache2.2 directory) and change the DocumentRoot and <Directory ... > to the new location. Make sure to keep the trailing slash, then restart Apache.
As for separating CakePHP files from your application, you can do it either way. I like to keep CakePHP files and the app in a single repository, so I can check out the project and get it working right away. Keeping the core files separate from your applications could save you time when updating CakePHP, especially if you have many apps. If I were starting out with CakePHP, I'd use the former method and focus on becoming familiar with the framework.
I guess, you don't need to really move your app folder. Just give the -app param in quotes. cake bake -app "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\testBlog\app\"

Resources