The documentation does not cover this. How do you remove cakephp from webroot (server webroot, not talking about cakephp webroot), having only the public files under webroot. By webroot I mean, lets us laravel as example and what is done
Here is sample folder structure +++++= a subfolder
apache2
++++++laravel51
htdocs
++++++larpubfolder
in other words htdocs/larpubfolder
so laravel51 is main files out of webroot (htdocs is webroot in apache), directly under apache2
And in larpubfolder is the .htaccess and index.php file
Now how to do this for cakephp 3.4 and what files need modified?
As unbelievable as it sounds, there is nothing on the web about properly moving cakephp (not old version) out of webroot.
this is a method iâve been using since cakePHP 1.2 daze - of course YMMV:
[NOTES]
these are my NTS (Notes To Self), as such they are changing over time and you MUST intelligently scan and make changes to suit your own local folder/file structure
i have not looked at this in about a year, so i cannot speak to changes since then that may break it
pay attention to [xxx NEED CONFIRM xxx] *** [/xxx NEED CONFIRM xxx] tags where i have not followed thru with full testing of an idea.
most of the time i will include variable parts inside square brackets, i.e., [ver] for multiple versions of cake
step 3) is my trace of sorting out paths and the like, i present it this way (rather than simply spelling out changes) to show HOW i sorted things out - THESE ARE EXAMPLES, change to suit your environment. that said, i do list required changes made by listing the error, commenting out the original line and adding the modified line
some error logs may be in different places as stated in your php.ini and httpd.conf files
install cakePHP in alternate directory structure to allow separation of cakebase and application and webroot.
assuming all server apps - including composer - working
/www/pub is apache doc root and the ONLY public access point
/www/pub is where each application webroot will go as /www/pub/app[ver]
/www/apps is where each application core will go as /www/apps/app[ver]
/www/tmp/logs is where server logs will go - ONLY AFTER you have changed your php.ini and httpd.conf to make it so
/www/serv/cake/cake[ver] is where cakePHP core will live and be the central project in the composer sense
this way you can simulutaneously work on dev AND stable branches of BOTH toolset(s) and application(s) [or homepage(s), or project(s), or . . .]
comfortable with my old setup, easier for me to get head around multiple projects with more than one dependant on each [ver] of cakePHP
allow me to work behind restricted corporate environment
can still use composer to update all focused on cake[ver] â OFF SITE if have to, with ALL plugins and vendors slave to the cakePHP, then
[xxx NEED CONFIRM xxx]
ALL of /www/serv/cake/cake[ver]/plugins and vendors can be entirely overwritten or built in a new cake[ver] with minor diffs on select config, apps/app[ver] and pub/app[ver] files only
[/xxx NEED CONFIRM xxx]
i know, i know, i know, i know - six of one half dozen of other
learning MUCH about cakePHP 3.0 and composer and git and . . .
â 1) copy composer download into tree
initial composer.json created in /www/serv/cake/cake[ver]/ with all cakePHP dependencies i chose
run composer in /www/serv/cake/cake[ver]/
move /www/serv/cake/cake[ver]/vendor/cakephp/app/* to /www/apps/app[ver]/
folder can be left behind - will be used for upgrades anyway
move /www/serv/cake/cake[ver]/vendor/cakephp/cakephp/* to /www/serv/cake/cake[ver]/
EXCEPT composer.json, rename to composer-cakePHP.json then move with rest
folder can be left behind - will be used for upgrades anyway
move /www/apps/app[ver]/webroot/* to /www/pub/app[ver]/
delete /www/apps/app[ver]/webroot/ folder
create /www/pub/index.php containing only â<?php phpinfo();â
â 2) start php server in public access folder
cd /d /www/pub
php -S localhost:8000
â 3) open browser, begin debugging [AS EXAMPLES ONLY --> find your logs]
open browser at localhost:8000 --> should see output of phpinfo() from pub/index.php
open browser at localhost:8000/app000/ --> begin debugging output:
read /www/tmp/errors_php.log
PHP Fatal error: require(): failed opening required âD:/www/pub/config/bootstrap.phpâ (include_path=â.;C:/php/pearâ) in D:/www/pub/app000/index.php on line 27
PHP Fatal error: require(): Failed opening required âD:/www/apps/app000/vendor/autoload.phpâ (include_path=â.;C:/php/pearâ) in D:/www/apps/app000/config/bootstrap.php on line 23
Fatal error: require(): Failed opening required âD:/www/serv/cake/cake000/vendor/cakephp/cakephp/src/Core/functions.phpâ (include_path=âD:/www/serv/cake/cake000/vendor/phpunit/php-text-template;. . .;.;C:/php/pearâ) in D:/www/serv/cake/cake000/vendor/composer/autoload_real.php on line 58
Could not load configuration file: D:/www/apps/app000/config/app.php
copy app000/config/app.default.php to app.php
read /www/tmp/errors_php.log
read browser output
Error: The application is trying to load a file from the Migrations plugin. Make sure your plugin Migrations is in the D:/www/apps/app000/plugins/ directory and was loaded.
start task manager > processes, enable âShow processes from all usersâ, right-click âmysqld.exeâ, âEnd Process Treeâ
delete /www/data/mysql/ib_logfile*
â 5) NOW, updates can be accomplished with normal composer methods on /www/serv/cake/cake000
+ ONLY FILES to be careful with so far are:
serv/cake/cake000/composer.json
pub/app000/index.php
apps/app000/index.php
apps/app000/config/app.php
apps/app000/config/bootstrap.php
apps/app000/config/paths.php
serv/cake/cake000/vendor/composer/autoload_files.php
serv/cake/cake000/vendor/composer/autoload_psr4.php
[xxx NEED CONFIRM xxx]
- except for these files and apps/app[ver]/src, ALL of cake000, apps/app000 and pub/app000 may be overwritten with updates
[/xxx NEED CONFIRM xxx]
- if unsure, diff all folders/files and select changes desired â WITHOUT compromising eight listed files.
â 5) keep apps/app000 and pub/app000 clean and dont modify further,
+ use as base template to copy to other âappsâ, and bake against actual database in new locations.
i.e. copy apps/app000 and pub/app000 to apps/app1 and pub/app1, apps/app2 and pub/app2, etc.,
+ when copy/pasting from cookbook pdf watch out for back-quotes -â-, ALL MUST be replaced with single quote -â-.
â 6) copy apps/app000 and pub/app000 to apps/bmk and pub/bmk and bake bookmarker tutorial
files modified pt1:
config/app.php
src/Model/Entity/User.php
config/routes.php
src/Controller/BookmarksController.php
src/Model/Table/BookmarksTable.php
src/Template/Bookmarks/tags.ctp
files modified pt2:
src/Controller/AppController.php
src/Controller/UsersController.php
src/Template/Users/login.ctp
src/Model/Table/BookmarksTable.php
src/Controller/BookmarksController.php
src/Template/Layouts/default.ctp
src/Template/Bookmarks/add.ctp
src/Model/Entity/Bookmark.php
??? duplicate tut changes on rest of controllers ???
[note]DJT: always use / directory separator, not \ because php handles both well --> no need for DS declaration â i think even windoze 7+ does correctly until you touch some limited tool in process chain
[note]
But the later versions donât have such a call: here is the index.php
<?php
if (php_sapi_name() === 'cli-server') {
$_SERVER['PHP_SELF'] = '/' . basename(__FILE__);
$url = parse_url(urldecode($_SERVER['REQUEST_URI']));
$file = __DIR__ . $url['path'];
if (strpos($url['path'], '..') === false && strpos($url['path'], '.') !== false && is_file($file)) {
return false;
}
}
require dirname(__DIR__) . '/../../cake34up/vendor/autoload.php';
use App\Application; ///////////These 2 lines mess things up as main cakephp is in higher folder
use Cake\Http\Server;
// Bind your application to the server.
$server = new Server(new Application(dirname(__DIR__) . '/../../cake34up/config'));
// Run the request/response through the application
// and emit the response.
$server->emit($server->run());
As you can see I tryed to repoint to the vendor and config folder, get nothing but a 500 error.
I will go through your answer and try again, thanks.
I wish cakephp had a simple index.php thay you could just point to main install with
That is a very very bad idea and will do nothing but cause issues in the future. You want a separate vendor directory for each application, otherwise youâll always struggle with upgrading dependencies. Storage space is cheap
No itâs one application, I just want to move main files out of htdocs. Like a laravel install for security.
The folder structure from docs shows
/cake_install/
bin/
config/
logs/
plugins/
src/
tests/
tmp/
vendor/
webroot/ //////Only folder I want under htdocs all other above htdocs.
.gitignore
.htaccess
.travis.yml
composer.json
index.php
phpunit.xml.dist
README.md
Main cake is under htdocs, it looks like.
I want webroot (the cake one) under htdocs and main cake files out of htdocs one folder higher âevenâ with apache folder. Seems there would be good instructions on this somewhere.
Why canât you change DocumentRoot to webroot as written in the documentation and remembered by dakota?
In production, with Apache, the best solution is already described in The Cookbook but if you must (?) mantain DocumentRoot to htdocs⊠install cake out htdocs and use Alias directive to map webroot.