Deployment is one of those topics that everybody has a different approach to and whatever works for you is fine. Before going into details, we would suggest that you read the Deploying Applications in the symfony documentation. The approach described in this post is based on this section.
1) Login to the Control Panel and add the domain for your website. You will be asked for a FTP username and password under the Web Hosting Settings section of the domain. Click “Next” when you are done.
2) Next you will need to enable shell access by selecting /bin/bash (chrooted) under the shell option so you can use the project:deploy command that the symfony CLI provides. Click “Finish” when you are done.
3) Since you are in the control panel, we also recommend that you create your MySQL database and username if you will be using one. Go to the Databases section to do this. Take note of the DB name, username and password and add them to your config/databases.yml file
4) Your config/databases.yml should look something like this if you use doctrine:
prod: doctrine: param: dsn: mysql:dbname=mydb;host=localhost username: login password: passwd attributes: quote_identifier: false use_native_enum: false validate: all idxname_format: %s_idx seqname_format: %s_seq tblname_format: %s
We recommend that you use localhost as the DB server name so PHP uses the Unix socket to connect which provides the best performance.
5) symfony:deploy reads the configuration from config/properties.ini This file should look something like this:
[production] host=sg111.servergrove.com port=22123 user=youruser dir=/symfony_projects/example
Replace the values with your assigned server name, user and dir.
Also, it is very important to check the path to the symfony library in config/ProjectConfiguration.inc.php. If you are including the library in lib/vendor then make sure the path is relative to this directory. It is important that you do not include an absolute path that you use in your local development box as it may not exist in the server.
If you decide to use the library included in our servers, your configuration file should look like this:
require_once '/usr/local/php/symfony14/lib/autoload/sfCoreAutoload.class.php'; sfCoreAutoload::register();
6) If you run
./symfony project:deploy production
now you will be able to deploy your application but you will be asked to enter the server password every time you run this command. If you want to avoid this, you need to generate a SSH public key and copy it to the server. Here is how:
(local) # ssh-keygen -t dsa
copy the content of ~/.ssh/id_dsa.pub and paste it in the server in a file named /.ssh/authorized_keys
Make sure to add the –go option to actually perform the deployment. Without it, it will just run a test.
7) Once all is done, if this is the first time, we recommend that you use Maestro to setup the web server, clear the cache and set project permissions.
Deploying database changes is a major topic on itself. We will try to expand on it in a future post.
If you have a different approach to deployment and you want to share it with us, please do so, we would love to hear it from you.