Deploying a PHP symfony 1.4.x application onto DotCloud

A friend suggested me to test Dotcloud Application Plattaform, which runs under Amazon Cloud.

As I develop using PHP symfony framework, there is some problems to resolv. Well, after some resarch and studies, that’s my steps to make it happen.

Create your account

Go to Dotcloud and do it.

to make basic install of dotcloud stuff.

Create namespace and applications

First the namespace:

dotcloud create myprojectname

After the application:

dotcloud deploy --type php myprojectname.www

And a database application (in case, MySQL)

dotcloud deploy --type mysql myprojectname.db

Gets the MySQL user and password with dotcloud info command:

dotcloud info myprojectname.db

The output:

cluster: wolverine
mysql_password: xyxyxyxyxyxyxyxyxxyx
mysql_serverid: -1
created_at: 1306702905.039634
name: myprojectname.db
namespace: myprojectname
-   name: ssh
url: ssh://
-   name: mysql
url: mysql://
state: running
type: mysql

So you can do the following command in the symfony directory to configure the database:

./symfony configure:database 'mysql://' root xyxyxyxyxyxyxyxyxxyx

Or optionally edit directly your /PATH_TO_SYMFONY_APP/config/database.yml:

    class: sfDoctrineDatabase
      dsn: 'mysql://;dbname=mydatabase'
      username: 'root'
      password: 'xyxyxyxyxyxyxyxyxxyx'

Of course if you use Propel adjust as you need.

Preparing your code

Dotcloud uses Nginx instead Apache (don’t worry, you are still in good hands, Nginx is excelent). So .htaccess doesn’t work to set rewrite rules. But the change is simple.

The only adjust is to include the nginx.conf under web directory in the symfony project (so it will be: /PATH_TO_SYMFONY_APP/web/nginx.conf:

# If you want to active expires header, that's the place
location ~* \.(ico|css|js|gif|jpe?g|png)(\?[0-9]+)?$ {
  expires 7d;

# Production handler
location / {
  try_files $uri $uri/ /index.php;

# Dev handler - do not let this on production server
location ^~ /frontend_dev.php/ {
  try_files $uri /frontend_dev.php;

# Note: if you have others applications and handlers, used this samples above

# If don't have a symbolic link to symfony/data/web/sf/,
# you can make an alias (pay atention to your symfony directory)
#location ^~ /sf/ {
#  alias /home/dotcloud/code/lib/vendor/symfony/data/web/sf/;

Deploy your application

Don't forget to empty cache before to push.

./symfony cc
dotcloud push myprojectname.www .

Something more?

No, it's done!

Thanks to Jérôme Petazzoni from the Dotcloud Support, that patiently answered my stupid newbie questions about Nginx.