Home > Backend Development > PHP Tutorial > How to Deploy Symfony Apps with Capifony

How to Deploy Symfony Apps with Capifony

William Shakespeare
Release: 2025-02-19 11:22:13
Original
522 people have browsed it

How to Deploy Symfony Apps with Capifony

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:

  • Capifony: Automates Symfony application deployments, handling tasks like dependency installation, cache clearing, and permission management.
  • Capistrano: The underlying framework for Capifony, providing the robust remote server automation capabilities.
  • Deployment Strategies: Choose between allowing your server direct SCM access or using your local machine to fetch and transfer the repository.

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:

  1. Ensure Ruby is installed.
  2. Install the Capifony gem: gem install capifony
  3. Initialize Capifony in your project: Navigate to your Symfony project directory and run 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
Copy after login

Deployment:

  1. Prepare the server: cap deploy:setup (creates releases and shared directories).
  2. Deploy: cap deploy

Troubleshooting:

  • Permission errors: Ensure your web server user has the correct permissions on the writable directories.
  • Git access issues: Verify SSH keys and consider ssh_options[:forward_agent] = true.
  • Dependency problems: Double-check your composer.json and bower.json files.
  • Verbose logging: Add logger.level = Logger::MAX_LEVEL to deploy.rb for detailed output.
  • Rollback: 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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template