Harry Winser

CakePHP – Working with Linux, Windows, and Netbeans

This website was made using CakePHP, which is a nice MVC PHP framework. It takes a lot of the development time out of doing some of the more basic stuff. It also helps with code reuse and structure. Netbeans has an add-on that allows you to develop CakePHP apps with everything already set up; very useful! This was of course on Windows.

So, after a couple of hours of development I was ready to put this site onto my server and release it into the wild. Unfortunately, it wasn't that simple. Yay issues...

I did a straight copy and paste from Windows to Linux using FileZilla, and found that it just didn't work at all. Not good. So after some faffing about, I got well and truly stumped. So I created this thread on StackOverflow. This yielded some response, and one useful piece of information; folder naming. Linux cares about the case of the Folder names, whereas Windows apparently doesn't. So the straight transfer caused issues. It took me a good number of hours to find this: "app/config/core.php". In Windows, "config" defaults to lower case, whereas Linux requires it with a capital - "app/Config/core.php". This does imply that the Netbeans add-on is a little broken, so watch out for that!

My advice is that if you can't see this mistake, take a break from working for a few hours and come back. It really helps with noticing these silly errors.

"Yes! It's displaying something... Oh wait hang on... Wha... Ah crap" - Me, several hours ago. My next issue was that "/var/www/lib/Cake/Cache/CacheEngine.php" time zone wasn't set. As a result, it was causing a wonderful error to appear on the index page. Adding this "using date_default_timezone_set('Europe/London');" to the file worked wonders. Problem solved! Just add it to the area where you're getting the error. Oh and change the time zone as appropriate (Check the list of timezones here).

I then went on to switch the database over from my local copy to my development machine. Simple config change right? Yep. Errors? Yep. The application wasn't connecting to the database; I needed "mysqlpdo", which is a database driver. More information can be found here.

You can check if it's working by creating a small PHP page in your index of your website that displays all information about stuff using this function: "phpinfo();". On this page, it states if this module is online and working - look for "pdo". This should have driver information. If nothing is there, you'll need to add it to PHP.ini file. Using that page and those instructions, as well as StackOverflow, I finally got the darn thing working.

But that's not quite the end unfortunately. All the error messages were gone, but it wouldn't view any of the other pages, only the index. I'm using a pretty standard Apache2 webserver, so after messing around with the .htaccess files, I found that what I actually needed to do was modify the apache2 configuration file to allow for "AllowOverride All" within the section that outlined where my application was stored. For most this will be /var/www/.

At last, success! I'm not going to lie, I exclaimed very loudly when it finally worked - housemate was a little confused when I went running into his room and demanded a High-five.

I know this isn't the most in-depth guide or anything, but hopefully it might point someone in the right direct in the future/remind me of how I got it set up. Enjoy!