1

Currently working on a project and completed. Works fine in local. But when uploaded to server. It Doesnt work as it should be. CSS and JS and images are not linked. I checked all the .htaccess files in project folder and they seem fine. These are the codes in .htaccess files

in root

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
</IfModule>

in app

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    ^$    webroot/    [L]
    RewriteRule    (.*) webroot/$1    [L]
</IfModule>

in webroot

<IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>

These files were still same since uploaded to server. I also went through some articles and questions to make sure that am not messing with .htaccess files. Then i found this issue.

in local when i tried to open /localhost/project/app/Controller/UsersController.php in local it returns error as it should be

But when i tried the same in server The page actually seems accessed. Since its controller no output is found but i can be sure the Controller is accessed directly. I cant figure out what kind of issue am going through. Am quite new to this. Any help will be appreciated.

Karthik Nk
  • 377
  • 1
  • 8
  • 25
  • Check apache error logs. If your app is deployed in a subdirectory check http://stackoverflow.com/a/17273643/1023432 – Ananth Feb 13 '15 at 09:11
  • Does your remote server supports `mod_rewrite`? – SaidbakR Feb 13 '15 at 09:13
  • Also set debug options to 2 in the config to get any extra error messages. – SaidbakR Feb 13 '15 at 09:14
  • @sємsєм debug options is currently 2 cuz before setting to production i just want to make sure it works as it should be – Karthik Nk Feb 13 '15 at 09:16
  • is it possible to access controller directly like now it is? am still trying to figure out whether remote supports mod_rewrite. – Karthik Nk Feb 13 '15 at 09:17
  • Ok, edit your question and supply some of the output of HTML source of a page of your project's header (where css and js links supposed to be). also tell us where are you placed your project relatively to your server document root. – SaidbakR Feb 13 '15 at 09:21
  • @Ananth tried the link you mentioned. Still not working Currently the root folder of server has come html pages and next is the project folder. So its accessed like www.xxx.com/projectfolder/ . – Karthik Nk Feb 13 '15 at 09:23
  • @sємsєм about the project folder in server i mentioned in last comment – Karthik Nk Feb 13 '15 at 09:25
  • @sємsєм current output when i navigate to the project in server is a login screen which i set in routes without css and js and images. – Karthik Nk Feb 13 '15 at 09:30
  • Is it same php version are you using in local and your server ? – Alimon Karim Feb 13 '15 at 13:21

4 Answers4

0

Cake creates tmp files under tmp folder. You must need to give permission read/write to this folder. After making your code live please make 777 permission to your tmp folder and try to delete all those files under sub folders. It may work and please share your results. You will find tmp folder under app folder.

Vineet
  • 4,525
  • 3
  • 23
  • 42
  • i already did sent chmod 777 permission to project folder and all subfolders with in. Once i uploaded i found the error not writeable so did the 777 permission – Karthik Nk Feb 13 '15 at 09:28
  • Please don't give permission to complete your project folder. It is not a good practice. Please give 777 permission to tmp folder and its sub folder. – Vineet Feb 13 '15 at 09:29
  • and please turn your debug mode on after doing above and refresh the page. – Vineet Feb 13 '15 at 09:33
  • debug mode is on.. As i mentioned in previous comments the real problem am facing right now is how controller can be accessed directly? – Karthik Nk Feb 13 '15 at 09:37
  • You must have set a route URL for particular controller action. You can access controller's action directly if you have not set any route for it. – Vineet Feb 13 '15 at 09:41
  • when i tried the same to access controller in local it returned page not found as it should be. Why can be accessible on server? – Karthik Nk Feb 13 '15 at 09:47
  • sorry i cant do that... but one more test i recently did. Which is .htaccess file is required for cake to located its contents right? when i deleted the htaccess file in my local it returned page not found error.. when i did same in server.. page still displays with same error. i think htaccess rewrite is not working – Karthik Nk Feb 13 '15 at 09:56
0

Your problem is in the in root .htaccess it should be like:

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ projectfolder/app/webroot/    [L]
   RewriteRule    (.*) projectfolder/app/webroot/$1 [L]
</IfModule>
SaidbakR
  • 13,303
  • 20
  • 101
  • 195
  • changed the htaccess file in project root as you said.. But still same issue exists – Karthik Nk Feb 13 '15 at 09:36
  • I mean by `root` the server's document root. i.e something like `public_html` @KarthikNk – SaidbakR Feb 13 '15 at 09:39
  • there was no .htaccess file in server root. So created one and pasted your code. Still no output – Karthik Nk Feb 13 '15 at 09:45
  • now i doubt whether server supports rewrite in htaccess file.. how to check it ? any suggestions? – Karthik Nk Feb 13 '15 at 09:48
  • Check this question: http://stackoverflow.com/questions/9021425/how-to-check-if-mod-rewrite-is-enabled-in-php Also if you are on a shared hosting try to contact the support. – SaidbakR Feb 13 '15 at 09:53
  • thnx for the link.. by trying phpinfo() found out that mod_rewrite is not available in loaded modules. So am pretty clear that mod_rewrite is not permitted in server. Looking for options to enable it.. Tried locating in etc/apache2/ folder but couldnt find.. Server is currently running Ubuntu os.. any suggestions? – Karthik Nk Feb 13 '15 at 10:16
  • Checkout this question on AskUbuntu that may help: http://askubuntu.com/questions/48362/how-to-enable-mod-rewrite-in-apache – SaidbakR Feb 13 '15 at 12:04
0

The project works now(Have to contact support for enabling the mod_rewrite). I enabled

Configure::write('App.baseUrl', env('SCRIPT_NAME'));

in config/core.php The problem is didnt have the mod_rewrite enabled in server. So enabling that in core supported the project to work without mod rewrite.

Thanks to http://wwdj.wijndaele.com/getting-started-with-cakephp-without-mod_rewrite/

Karthik Nk
  • 377
  • 1
  • 8
  • 25
0

I had same problem, it was working on localhost but not on server, it was throwing 404 error. It is because I had uploaded my website in subdirectory of sever root. I did many things to make it work but as I am using htaccess in root folder I found no solution on root level.

Finally I found a solution, edited existing htaccess of cakephp root folder and added "RewriteBase" after RewriteEngine on.

Full code:

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteBase /name_of_the_subFolder
 RewriteRule ^$ app/webroot/    [L]
 RewriteRule (.*) app/webroot/$1 [L]
</IfModule>

Like if my project appear in 'xyz.com/one/two/cake/' then RewriteBase would be Rewritebase /one/two/cake/.

It worked for me.