CakePHP vs Rails – Comparing Development Environments
Author: Jay Brodie | Filed under: Ruby on RailsIn my previous (and very popular) post titled PHP vs Ruby on Rails, I wrote about the differences and similarities between the two languages. As I said in that article however, the comparison isn’t fair since PHP is a language, and Ruby on Rails is a framework.
For a proper comparison of PHP and Ruby on Rails, we need to look at comparing CakePHP and Rails, both MVC Architectures for Rapid Application Development (RAD). These tools allow developers to be able to generate baseline code and to be able to develop quickly within their architectures.
There are many benefits to using MVC, including:
- clean separation of logic from views
- REST friendly URLS
- maintains a stateless nature
- ease of control over rendered HTML
- use of Test Driven Development (TDD)
Compared to my previous post, this is an apples-to-apples comparison between CakePHP and Rails environments.
Development
Development between CakePHP and Rails is similar yet very different. Both are MVC architectures which in itself make development simpler. Both have generators to allow for fast code development. There are however some key differences between these two architectures.
Scaffolding is supported by both architectures and they both have a specific look that can be customized.
The local development support for Rails is ASTOUNDINGLY better than CakePHP.
For CakePHP to run on your local environment for development, you need to have some sort of web server (Apache, IIS) running locally with PHP installed as well as a rewrite module running. Once this is in place and you have your code base up and running within the host, you can then start your development. Rails, on the other hand, requires only a simple command line to fire up a local server and get working. This is without a doubt one of the BEST things about Rails development.
Another big win with Rails is migrations. These allow you to be able to interact with your database and make structure / data changes through scripts with ease. The mechanism makes sure you are up to date and can sync your database with a couple of keystrokes. This is greatly beneficial when you are promoting code to a production environment as you can simply run your migrations and update the database on a remote host to be versioned to the same as your local database.
Testing
CakePHP and Rails both have testing environments. There are several for Rails but the preferred testing environment for Rails is rSpec. PHP also supports testing; although I have not spent a ton of time working through it, I do still prefer rSpec and Guard.
Deployments
Capistrano is a deployment tool that is primarily used for Rails deployments. It has been adapted and extended to be used for deploying other projects including CakePHP. There are many different 3rd party extensions for use with Capistrano that will work with a gambit of different languages.
Documentation
PHP in general has a massive community that outweighs the Ruby side. However, when comparing the community and documentation between the two frameworks, Rails has MUCH better documentation than CakePHP. There are a large variety of sites out there with Rails documentation that contain up to date, and in-depth answers. CakePHP’s documentation on the other hand, is scarce and vague.
End Decision
Without a doubt, the winner of the MVC framework conversation is Rails. It is sleek and clean, functional and productive. There are many points in Rails that CakePHP would benefit from adopting to continue its growth in the market share.
The PHP vs Ruby on Rails argument isn’t a simple one, and judging by the popularity of my previous post on it, the argument is a hot topic. The biggest thing with selecting a development language is to factor in everything. You need to be able to look at the raw development costs of your developers, your hard costs of hardware or hosting for your applications, and of course the cost of maintenance for your application throughout its life cycle.
PHP programmers are easier to find than Ruby on Rails programmers, hosting will be cheaper due to the fact that PHP as a language is more supported on hosting providers.
The cost of maintaining either system is pretty much a wash, as either system will have some sort of long term maintenance.
A definitive call on which system is right for the job is probably best summed up like this:
Use the right tool for the job.
If you are working in a larger scale corporate environment and you have the option to host and maintain your own server, then I would by all means recommend using Rails (Ruby on Rails) for your solutions.
If you are a home-based business, or a weekend programming warrior doing odd jobs, then the solution for you would be CakePHP due to the easy availability and lower costs of PHP hosting.
[...] Be sure to read my follow up post comparing development environments between CakePHP and Rails! It can be found here http://itblog.infotech.com/general/cakephp-vs-rails-comparing-development-environments/ [...]
Good article and points, however, PHP has a built in server as of 5.4 (I can confirm 5.4.9 at least). Executing ‘php -S localhost:8000′ will get you up and running. I do agree about the ease of launching a full developer environment using Rails, it’s a great setup. Also, check out some of the better PHP MVC frameworks (in my opinion anyway) such as Laravel (great syntax, highly digestible being someone coming from using Rails myself) and Yii, they both allow for migrations, and Laravel provides a nice command line tool artisan that can provide much of the generating functionality Rails users enjoy. CakePHP isn’t exactly viewed as the greatest to begin with even though it’s popular.
Different MVC Frameworks are always an option, but keep in mind if you start working with less supported frameworks, you end up with a lot less community support. Depending on what you are trying to do and how advanced the project is this may ultimately be a very costly decision.
There are more then a half a dozen MVC frameworks out there for PHP that are great working models so there are plenty of options when making a selection. Keep in mind the community support along side of the other options. If you end up getting stuck or not being able to make sense of an issue you’re having, without a community you have a very costly issue to resolve.
This is really great i am also looking for web site development but i am confused which framework is best for web development.
Hey Jake,
Thanks for the heads up on the PHP version update to 5.4.
I have recently taken a look at it and wow, they have made some good changes. It is ver nice being able to test on the fly on a local machine without a ton of setup work and restrictions. I haven’t had a chance to play with it much yet as I have just really gotten it installed but I would be curious to see how it works with additional module requirements. I am sure it would just be the default config for it but as I said, I have just got it installed and running.
Since they don’t have it in the apt options yet there is a post here with some information on an easy set-up and install for it.
Hosting on heroku is dead simple and… Ummm… Free… For the weekend warrior type apps. Rails by a long shot here.
I fail to see why having to set up your own server is such a big negative. I can add an RPM package for nginx and php-fpm, install and have it configured and tuned for cake within 30 minutes. I can’t imagine it would be wise for any ‘large scale corporation’ to unfold a generic, ready-to-use, preconfigured web server and PHP configuration to save 30 minutes and call that an advantage. In fact I would say RoR, in that respect, is a better option for a weekend warrior.
I have to disagree with you on that. I mentioned that the built in server is a nice aspect, so nice that PHP has now also gone this route with their most recent version. Being able to fire up this server from any folder I am working in allows me to work on several projects on the same machine without having to deal with a ton of configuration or moving of files around. Also being able to fire that server up for Rails locally and have control allows for line by line debugging, something that I have missed for along time in PHP.
Hi Jay. Absolutely, I agree with what you just said… the second sentence. If you were a large corporation though, do you really want a built-in server for the convenience of the developer, or would you want to pick and choose one that fits your needs in an extra 30 minutes? I have to disagree about ‘ton of configuration or moving of files around’ – if you’re using RHEL, let’s say, it’s a simple yum install nginx and yum install php-fpm. Then editing 2 configuration files exactly as you’d like, and choose which modules are installed.
In a development environment, I agree with you, absolutely. Especially if you don’t have old config code you could rely on (I have lots). But when put into the context of a ‘large corporation’, I would say it’s making a mistake. So I’d partially agree that it’s great to have the convenience, during development… but in deployment, I definitely wouldn’t.