I'm new to cakephp and I'm having some problems with setting up a local development server. I have my cake install located at http://localhost/dropbox/my_site/. However, when I try to visit that url, it tells me the dropbox controller isn't set up. How do I tell CakePHP to start in my_site rather than /localhost/?
I've tried adding connect(/localhost/dropbox/*) to the routes, but it seems like it still looks for models in the wrong location.
I tried editing index.php in app/webroot but all the examples show how to write the directory in linux format rather than windows, so I'm not sure how to structure 'ROOT'
CakePHP will work happily in a subdirectory - I have several Cake sites running at http://localhost/{appname} on my dev machine.
Cake defines its ROOT directory in the root index.php file. If you look inside you'll see the following lines:
define('ROOT', dirname(__FILE__));
define('WEBROOT_DIR', 'webroot');
define('WWW_ROOT', ROOT . DS . APP_DIR . DS . WEBROOT_DIR . DS);
Since it's taking ROOT from dirname(__FILE__), it will always point to that file's location.
I suspect you have problems in your routing file. Did you create any custom routing rules to account for being located in a subdirectory? If you did, your cake install may be trying to access http://localhost/dropbox/my_site/dropbox/... and that's why you're getting that error.
This likely doesn't have so much to do with CakePHP as it does with your web server.
If dropbox is your document root, it should be mapped accordingly in your web server configuration. For example using DocumentRoot in Apache.
Related
I'm using a new server host and $_SERVER["DOCUMENT_ROOT"] is not working because returns a different path than the real one.
Example, I added includes/inc.php to the public_html folder on the server and used this code:
include_once($_SERVER["DOCUMENT_ROOT"] . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'inc.php');
This is the result:
Warning: include_once(/var/www/html/includes/inc.php): failed to open stream: No such file or directory in /home/tom_server/public_html/index.php on line 4
$_SERVER["DOCUMENT_ROOT"] is returning something unexpected. If I use dirname(__FILE__) it returns the right path:
/home/tom_server/public_html/includes/inc.php
But dirname(__FILE__) is not a useful solution as I need main root folder for relative paths. Is this a server configuration issue?
/home/<username>/public_html is the default user's web content directory used by apache if this feature is enabled.
When activated, the usual intended use of such personal directories is to store some static pages (cv, personal page in the company/institution...) and small dev/tests for easy access without having to configure anything. I used them a lot for students when I worked in a university a very long while ago so they could store and share their assignments.
When this feature is enabled, the pages in personal directories are served by the default webserver/virtual host, for which the document root is configured to /var/www/html by default on most linux distributions.
If you want to have a document root starting at the root of your php application, you can:
Fast and easy but ugly: move your application files to /var/www/html
Single user/app solution: modify the default webserver to point to your app (in place or in a new folder).
Prefered: use a dedicated folder for your app and configure a new Virtual Host in apache
If you do not have access to your server configuration and can only publish your files in your current user web directory, well... I have a bad news: you will not be able to use DOCUMENT_ROOT anymore in this context.
Details for configuring apache are beyond the scope of your question and probably belong to an other stackexchange site.
I'm working on small project, and will host it on normal Godaddy host plan, the problem is: all file system will be accessible through internet.
so, how can I prevent access to any folder or file except /public
CONTRIBUTING.md
app/
artisan
bootstrap/
composer.json
composer.lock
phpunit.xml
public/
server.php
vendor/
thanks,
Why not split the project up? Upload the contents of public to your document root and the rest somewhere else (like your home directory). Then just modify the two paths in the public/index.php file to point to the right locations, eg
$path = __DIR__ . '/../my-app';
require $path . '/bootstrap/autoload.php';
$app = require_once $path . '/bootstrap/start.php';
If you point your apache site document root to /public, there is no way people can access any other file in your application outside your public. Even if they try to do things like:
http://yoursite.com/../
EDIT:
This is not something you should rely on a framework to do, securing directories on your site is the web server job, so you need to find a solution on your server: virtual host, document root, web root, domain directory or even .htaccess configuration.
In some shared hosting companies you can do that easily, some have cPanel or Plesk, but other, like Hostgator, will give you just enough configuration so you can change your directory root to /public. Looks like GoDaddy doesn't help much if you don't have a cPanel account, but, still, there are tricks to help you doing it the way you should be doing: http://support.godaddy.com/help/article/4067/setting-up-a-non-web-accessible-root-folder. Probably there are others around.
This seems like a basic question, but it's stumping me. I have CodeIgniter installed, and I've got a model that manipulates and saves XMLs. My problem is when trying to save it to "/" I get a "Permission denied" PHP error. I need to save them to a separate directory relatively, but I'm not sure where exactly "/" is located on the server. Is it in the "/www" of Apache, or root of the whole server? Once I know this I should be able to navigate to the correct directory
/ is the root directory. The starting point of your directory structure. This is where the Linux system begins. Every other file and directory on your system is under the root directory. Usually the root directory contains only sub-directories, so it's a bad idea to store single files directly under root.
Try specifying the complete path in your application.
Example: /home/user/public_html/yourApplicationFolder/
Or specify a relative path:
Example: ../somePath/.
This article could be helpful.
To get the filesystem path to the document root just use $_SERVER["DOCUMENT_ROOT"];
I want to refer to my website root, or more exactly, to the directory above my script's one.
Let's say my website is example.com/test. I made a installation site which writes a config file. But it shouldn't write it to example.com/test/install/config.php, but to example.com/test/config.php. And the biggest pain in the ** is that I run on Windows (my development PC).
How do I do it?
If you want to get the web-site document root, you can use:
$_SERVER['DOCUMENT_ROOT']
That should work regardless of the operating system and gives you a path on the local file system (so no www.etcetc.).
If you want to get the fully-qualified path of your site root, from that file it is:
$root = realpath(dirname(__FILE__) . '/../../..');
The double-dots work their way up the directory structure, then realpath() is used to turn it into a proper path. So if you want to traverse one less folder up, use two sets of dots rather than three.
I have a little problem: I began a project as a subdirectory in a larger web project. Thus the web file path is something like /../myProject. But things have progressed and I've realized that this should be its own project. However, I'd like to be able to keep it where it (as a sub-directory) also make it a sub-domain wherein myProject becomes the root. (There is also the possibility that my project will be mirrored at a library site, where it will once be in a sub-directory).
The problem I having with all this is that in some cases I have html_partial files, (for instance for the header or footer). But the relative path of these partials differs depending on where you are in the file tree. I originally solved this by always going back to the root.
But now, you see, depending on where my project lives, the root will be different. What I'd like to do is declare myProject as the "application root" and then be able to use relative paths based on this application root rather the than the web root'. This way, all of the relative paths within 'myProject' will work no matter wheremyProject` lives in the web path.
Does PHP have a way to declare something like an Application Root if so, can you explain it me or direct me to its documentation. Thanks!
You could simply have a PHP file in your application root directory which would define the directory it is in as the application root. The file could be as simple as this:
<?php
define('APPLICATION_ROOT', __DIR__);
?>
You could then include this file as needed and base all of your file paths off of APPLICATION_ROOT. Note that APPLICATION_ROOT would not have a trailing slash as defined here (unless your file happened to be on in the machines root directory, which is unlikely).
I usually do something lile this in the front controller:
define('APPLICATION_PATH', realpath(__DIR__));
Then you can do things like:
set_include_path(APPLICATION_PATH . '/include');
Or:
$fp = fopen(APPLICATION_PATH . '/path/to/some/file', 'r');
If your app doesn't make use of a front controller, you could define an environment variable in your vhost config or .htaccess:
SetEnv APPLICATION_PATH /full/path/to/my/app
And then use:
getenv('APPLICATION_PATH')