4

I have been using the cake command on my linux server for 2 years. but now im trying to move to a new server and some how the cake command gives back the error: No such file or directory

even if i give the entire path to the cake command file chmod 777 it stil wont work.

jurrieb
  • 248
  • 5
  • 14
  • add exactly what you're doing and exactly what happens to the question (i.e. copy and paste the console output). – AD7six Nov 06 '13 at 15:18

5 Answers5

8

I found the solution: All I had to do is use the program dos2unix the cake file for CakePHP 2.4.2 has wrong endings when you download it with Ubuntu 13.10

I used the following command:

sudo dos2unix /path/to/cake/lib/Cake/Console/cake
jurrieb
  • 248
  • 5
  • 14
  • This doesn't seem likely (and you wouldn't need to use sudo to run it) – AD7six Nov 12 '13 at 20:01
  • I spoke with some developers from cakePHP they have seen this problem before with other people. And yes you could run it without sudo I however have it installed with sudo. – jurrieb Nov 21 '13 at 12:47
  • My development environment is a Windows machine, and when I deliver the code to a Linux box, I need to dos2unix (and give execute permissions) to Console/cake. – Reuben Jun 16 '15 at 22:57
4

I also have this problem on some servers and never figured out why this happened. I suspect the so called "shebang" might not be set correctly for every Linux distribution (e.g. if the cake script stars with #!/usr/bin/env bash, but you don't use bash on your server or your distribution doesn't have the env binary in that path, it might fail on that. This is just a theory though, as I said I never really figured it out, nor did I invest much time in investigating.

Although, what I always use as a fallback is simply calling the cake.php script (from the app folder) instead, like:

php Console/cake.php -app `pwd` bake

That never lets me down. The -app pwd bit is to tell the shell that your current directory is your app directory, so the shell can find all your files.

Oldskool
  • 34,211
  • 7
  • 53
  • 66
4

The REAL solution to this is to change the End-of-Line (EOL) characters to Unix format, instead of MsDos. So I guess this error will only occur if you worked in Windows.

Anyway, teh mighty SOLUTION:

(1) Open app/Console/cake file using any text editor that allows changing of EOL characters e.g. NotePad++.

(2) In NotePad++ click: Edit -> EOL Conversion -> Convert to Unix format

(3) Save the file and upload it to the server. Now if you navigate to the CakePHP app directory using command like:

cd /usr/share/nginx/html/cakeproject/app

...you should be able to run Console/cake without any problems and see standard output (basically help commands).

Hope this helped you!

Rav
  • 1,460
  • 1
  • 21
  • 33
  • 1
    this worked like a charm. for those who are on Sublime, you can go to File -> Save with encoding -> UTF-8 – Amjo Aug 30 '16 at 10:04
  • Thank you very much, I have been working on CakePHP applications since last 2 years, but never faced this issue. I have worked on heavy CRON tasks, but it was the first time, and your solution worked perfectly. – Abhishek Mugal Dec 08 '17 at 07:20
1

I encountered the same problem as well, but the top answer reminded me of a similar problem I faced before: https://stackoverflow.com/a/5514351/1097483

Basically, instead of using dos2unix or installing it, you can open the file in vim, do

:set fileformat=unix

And save it.

Community
  • 1
  • 1
xiankai
  • 2,773
  • 3
  • 25
  • 31
-1

In some versions it's possible to install cake using sudo apt-get install cakephp-scripts.

After instalation, you coud access bake anywere simple by typing bake

Magicprog.fr
  • 4,072
  • 4
  • 26
  • 35