Deploying your Symfony application shouldn't be a manual chore. This guide shows you how to streamline the process using Capifony, a powerful deployment tool built upon Capistrano (familiar to Ruby developers). We'll cover installation, configuration, and troubleshooting.
Key Concepts:
How Capifony Works:
Capifony executes a series of commands during deployment. Crucially, it utilizes a structured directory layout:
releases
: Each deployment creates a new directory here, containing a fresh copy of your application.shared
: Stores files and directories (e.g., uploads, logs, vendor) that persist across deployments.current
: A symbolic link pointing to the latest successful release, ensuring your web server always serves the correct version. Your web server should point to this symlink.Installation:
gem install capifony
capifony .
. This generates Capfile
and deploy.rb
. Choose a deployment strategy (server-side SCM access is detailed here).Project Configuration (deploy.rb
):
The deploy.rb
file needs customization. Here's a sample configuration, explaining key settings:
set :application, "YourAppName" set :domain, "yourdomain.com" set :deploy_to, "/var/www/yourdomain.com" set :app_path, "app" # Adjust if your app directory is different set :repository, "git@yourgitrepo.com:yourusername/YourAppName.git" # Your Git repository URL set :scm, :git set :model_manager, "doctrine" # Or "propel" role :web, domain role :app, domain, :primary => true set :keep_releases, 3 set :dump_assetic_assets, true set :use_composer, true set :shared_files, ["app/config/parameters.yml"] set :shared_children, [app_path + "/logs", web_path + "/uploads", "vendor", app_path + "/sessions"] # Adjust paths as needed # Server Configuration (adjust user and paths as necessary) set :use_sudo, false set :user, "yourusername" set :writable_dirs, ["app/cache", "app/logs", "app/sessions"] set :webserver_user, "www-data" # Your web server user set :permission_method, :acl set :use_set_permissions, true ssh_options[:forward_agent] = true # Often needed for Git access default_run_options[:pty] = true # Helpful for troubleshooting # Example: Add a task to run Bower before Assetic before 'symfony:assetic:dump', 'bower:install' namespace :bower do task :install do run "cd #{latest_release} && bower install" end end
Deployment:
cap deploy:setup
(creates releases
and shared
directories).cap deploy
Troubleshooting:
ssh_options[:forward_agent] = true
.composer.json
and bower.json
files.logger.level = Logger::MAX_LEVEL
to deploy.rb
for detailed output.cap deploy:rollback
Frequently Asked Questions (FAQs):
The original article's FAQ section provides comprehensive answers to common Capifony deployment questions, covering topics like dependency updates, cache clearing, and rollback procedures. Refer to that section for detailed troubleshooting and best practices.
This revised response provides a more concise and organized explanation of Capifony deployment, while retaining the essential information and addressing potential issues. Remember to adapt the configuration to your specific project and server environment.
The above is the detailed content of How to Deploy Symfony Apps with Capifony. For more information, please follow other related articles on the PHP Chinese website!