Deployment documentation¶
Capifony (Developer side)¶
> gem install capifony
Database (server)¶
> mongo > use bota > db.createCollection("User") > db.createCollection("Database") > quit()
Capifony (local)¶
app/config.deploy.rb example
# Needed for Symfony2 only set :stage_dir, 'app/config/deploy' # Path to php executable set :php, "/opt/php/bin/php" set :php_bin, "/opt/php/bin/php" # Config set :application, "publishv2" set :domain, "foo.server.com" # ! dev ! set :deploy_to, "/opt/www/org.bar/dev" # ! prod ! #set :deploy_to, "/opt/www/org.bar/prod" set :user, "username" set :use_sudo, false set :app_path, "app" # Role role :web, domain # Your HTTP server, Apache/etc role :app, domain # This may be the same as your `Web` server role :db, domain, :primary => true # This is where Symfony2 migrations will run # Keep the app_*.php files set :clear_controllers, false # Repository set :scm, :git # Or: `accurev`, `bzr`, `cvs`, `darcs`, `subversion`, `mercurial`, `perforce`, or `none` set :repository, "http://user:pass@amap-dev.cirad.fr/git/plantnet-publishv2.git" #Model manager set :model_manager, "doctrine" # Realeases set :keep_releases, 5 # Shared files set :copy_exclude, [".git"] set :shared_files, ["app/config/parameters.yml", "app/config/parameters.yml.dist", "web/.htaccess", "web/.htpasswd"] set :shared_children, [app_path + "/logs", web_path + "/uploads", web_path + "/banners", web_path + "/media", "vendor", "src/Plantnet/DataBundle/Resources/uploads"] # Permissions set :writable_dirs, [app_path + "/cache", app_path + "/logs", web_path + "/uploads", web_path + "/banners", web_path + "/media", "src/Plantnet/DataBundle/Resources/uploads"] set :webserver_user, "www" set :permission_method, :chown set :use_set_permissions, true # Assetic set :dump_assetic_assets, true set :assets_symlinks, true # Run composer set :use_composer, true set :update_vendors, false ssh_options[:forward_agent] = true default_run_options[:pty] = true # Be more verbose by uncommenting the following line logger.level = Logger::MAX_LEVEL # Automatically upload custom server files before "deploy", "upload_customs" task :upload_customs do #parameters # ! dev ! origin_file = "app/config/deploy/parameters.yml" # ! prod ! #origin_file = "app/config/deploy-prod/parameters.yml" destination_file = shared_path + "/app/config/parameters.yml" try_sudo "mkdir -p #{File.dirname(destination_file)}" top.upload(origin_file, destination_file) #parameters dist # ! dev ! origin_file = "app/config/deploy/parameters.yml.dist" # ! prod ! #origin_file = "app/config/deploy-prod/parameters.yml.dist" destination_file = shared_path + "/app/config/parameters.yml.dist" try_sudo "mkdir -p #{File.dirname(destination_file)}" top.upload(origin_file, destination_file) #htaccess # ! dev ! origin_file = "app/config/deploy/x.htaccess" # ! prod ! #origin_file = "app/config/deploy-prod/x.htaccess" destination_file = shared_path + "/web/.htaccess" try_sudo "mkdir -p #{File.dirname(destination_file)}" top.upload(origin_file, destination_file) #htpasswd # ! dev ! origin_file = "app/config/deploy/x.htpasswd" # ! prod ! #origin_file = "app/config/deploy-prod/x.htpasswd" destination_file = shared_path + "/web/.htpasswd" try_sudo "mkdir -p #{File.dirname(destination_file)}" top.upload(origin_file, destination_file) end # Automatically change owners after "deploy", "chown_customs" task :chown_customs do run "chown -R username:www #{current_path}/app/cache" run "chown -R username:www #{shared_path}/app/logs" run "chown -R username:www #{shared_path}/web/media" run "chown -R username:www #{shared_path}/web/uploads" run "chown -R username:www #{shared_path}/web/banners" run "chown -R username:www #{shared_path}/src/Plantnet/DataBundle/Resources/uploads" #chown -R try_sudo "chown -R username:www #{current_path}/app/cache" try_sudo "chown -R username:www #{shared_path}/app/logs" try_sudo "chown -R username:www #{shared_path}/web/media" try_sudo "chown -R username:www #{shared_path}/web/uploads" try_sudo "chown -R username:www #{shared_path}/web/banners" try_sudo "chown -R username:www #{shared_path}/src/Plantnet/DataBundle/Resources/uploads" end # Clean up old releases #after "deploy:update", "deploy:cleanup"
app/config/deploy/parameters.yml example
parameters: database_driver: pdo_mysql database_host: 127.0.0.1 database_port: ~ database_name: symfony database_user: root database_password: ~ mailer_transport: smtp mailer_host: 127.0.0.1 mailer_user: ~ mailer_password: ~ locale: en #locales: [en, fr, es] secret: ThisTokenIsNotSoSecretChangeIt mdb_base: dev_test php_bin: /opt/php/bin/php node: /opt/nodejs/bin/node node_paths: [/opt/nodejs/bin/node_modules] from_email_adress: support@foo-bar.org from_email_sender_name: foo-bar.org
app/config/deploy/parameters.yml.dist example
parameters: database_driver: pdo_mysql database_host: 127.0.0.1 database_port: ~ database_name: symfony database_user: root database_password: ~ mailer_transport: smtp mailer_host: 127.0.0.1 mailer_user: ~ mailer_password: ~ locale: en #locales: [en, fr, es] secret: ThisTokenIsNotSoSecretChangeIt mdb_base: dev_test php_bin: /opt/php/bin/php node: /opt/nodejs/bin/node node_paths: [/opt/nodejs/bin/node_modules] from_email_adress: support@foo-bar.org from_email_sender_name: foo-bar.org
app/config/deploy/x.htaccess example
AuthName "Restricted" AuthType Basic AuthUserFile "/opt/www/org.bar/dev/current/web/.htpasswd" Require valid-user php_flag magic_quotes_gpc off php_value short_open_tag Off php_value date.timezone Europe/Paris php_value memory_limit 256M php_value post_max_size 2000M php_value upload_max_filesize 2000M php_value max_file_uploads 20 <IfModule mod_rewrite.c> RewriteEngine On #<IfModule mod_vhost_alias.c> # RewriteBase / #</IfModule> RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ app.php [QSA,L] </IfModule> <IfModule mod_expires.c> ExpiresActive on # cache control 20 days <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> Header set Cache-Control "max-age=1728000, public, must-revalidate" </FilesMatch> </IfModule> # supprime les ETags FileETag none # enable gzip compression AddOutputFilterByType DEFLATE text/javascript application/javascript text/css application/xhtml+xml text/html text/plain application/json text/xml
app/config/deploy/x.htpasswd example
user:$dfgdfgdfgdfgdfgdfgdfgdfgrfgdfg
app/config/deploy-prod/parameters.yml example
parameters: database_driver: pdo_mysql database_host: 127.0.0.1 database_port: ~ database_name: symfony database_user: root database_password: ~ mailer_transport: smtp mailer_host: 127.0.0.1 mailer_user: ~ mailer_password: ~ locale: en #locales: [en, fr, es] secret: ThisTokenIsNotSoSecretChangeIt mdb_base: publish_prod php_bin: /opt/php/bin/php node: /opt/nodejs/bin/node node_paths: [/opt/nodejs/bin/node_modules] from_email_adress: support@foo-bar.org from_email_sender_name: foo-bar.org
app/config/deploy-prod/parameters.yml.dist example
parameters: database_driver: pdo_mysql database_host: 127.0.0.1 database_port: ~ database_name: symfony database_user: root database_password: ~ mailer_transport: smtp mailer_host: 127.0.0.1 mailer_user: ~ mailer_password: ~ locale: en #locales: [en, fr, es] secret: ThisTokenIsNotSoSecretChangeIt mdb_base: publish_prod php_bin: /opt/php/bin/php node: /opt/nodejs/bin/node node_paths: [/opt/nodejs/bin/node_modules] from_email_adress: support@foo-bar.org from_email_sender_name: foo-bar.org
app/config/deploy-prod/x.htaccess example
#AuthName "Restricted" #AuthType Basic #AuthUserFile "/opt/www/org.bar/prod/current/web/.htpasswd" #Require valid-user php_flag magic_quotes_gpc off php_value short_open_tag Off php_value date.timezone Europe/Paris php_value memory_limit 256M php_value post_max_size 2000M php_value upload_max_filesize 2000M php_value max_file_uploads 20 <IfModule mod_rewrite.c> RewriteEngine On #<IfModule mod_vhost_alias.c> # RewriteBase / #</IfModule> RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ app.php [QSA,L] </IfModule> <IfModule mod_expires.c> ExpiresActive on # cache control 20 days <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$"> Header set Cache-Control "max-age=1728000, public, must-revalidate" </FilesMatch> </IfModule> # supprime les ETags FileETag none # enable gzip compression AddOutputFilterByType DEFLATE text/javascript application/javascript text/css application/xhtml+xml text/html text/plain application/json text/xml
app/config/deploy-prod/x.htpasswd example
user:$dfgdfgdfgdfgdfgdfgdfgdfgrfgdfg
> cd {project_path} > cap deploy:setup > cap deploy
If permission errors (server):
>chown -R {user}:www {dir} {dir} = shared/app/logs {dir} = shared/web/medias {dir} = shared/web/uploads {dir} = shared/web/banners {dir} = shared/src/Plantnet/DataBundle/Resources/uploads {dir} = current/app/cache
Create first user (super admin) on server¶
> cd {project_path} > ./app/console fos:user:create > ./app/console fos:user:promote {first_user} ROLE_SUPER_ADMIN