My cakephp project works perfectly on localhost, but doesn’t work when I upload it to a hosted server.
This is the setup on my cPanel File Manager of hosted server:
/home/username/public_html/test
// webroot contents goes here
css/
img/
js/
index.php
/home/username/mycakeapp/
// necessary app directories go here
/config
/logs
/plugins
/src
/tmp
/vendor
I made sure to change WWW_ROOT in mycakeapp/config/paths.php on line 52:
define(‘WWW_ROOT’, ‘/home/username/public_html/test’ . DS);
I also changed index.php in public_html/test in the following 3 lines so that it correctly requires necessary files:
require '/home/username/mycakeapp/config/requirements.php';
require '/home/username/mycakeapp/vendor/autoload.php';
$server = new Server(new Application('/home/username/mycakeapp/config'));
After doing this, when i open the website.com/test, the site correctly opens the home.ctp file. However, upon going to other pages like website.com/test/users, it gives an error message like so:
The requested URL /test/users was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
My home.ctp file only has pure HTML code, so I guess it works fine. However, going to other sites which has CakePHP code, it doesn’t seem to work at all. Plz help!
2
Answers
You should try changing
App.base
parameter in./config/app.php
like so:See the documentation here.
Upload your .htaccess file.
The part that’s not working is the one that rewrites requests for “pretty” URLs like /users into requests for PHP scripts like /index.php?q=/users. The .htaccess file does that.