.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is turned on, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Jifty::Manual::Deploying 3pm" .TH Jifty::Manual::Deploying 3pm "2011-02-09" "perl v5.14.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Jifty::Manual::Deploying \- Deploying your application for production use .SH "DESCRIPTION" .IX Header "DESCRIPTION" This document is intended to answer two questions: .IP "\(bu" 4 Now that you've developed your Jifty application, how do you deploy it on the production server? .IP "\(bu" 4 Once deployed, what's the process for performing upgrades to the production server? .PP Developers and administrators may wish to use this document as a checklist to make sure they hit everything when deploying. This document should be updated according to the best practices of Jifty deployment to aid this end. .SH "HOW TO" .IX Header "HOW TO" .SS "Installing on a Production Server" .IX Subsection "Installing on a Production Server" Once you've finished developing your Jifty application and you want to deploy it for use on a production server you'll need to follow these steps: .IP "1." 4 Install Jifty on your production server. .IP "2." 4 Copy your application onto the production server. .IP "3." 4 Adjust the configuration to suit your production environment. .IP "4." 4 Deploy your production database. .IP "5." 4 Configure your web server. .IP "6." 4 Start using your production service. .PP \fIInstall Jifty\fR .IX Subsection "Install Jifty" .PP Jifty installation proceeds just as it did on your development machine (or machines). If you installed from \s-1CPAN\s0, you may do the same for your production server. .PP .Vb 1 \& perl \-MCPAN \-e \*(Aqinstall Jifty\*(Aq .Ve .PP or download Jifty and run: .PP .Vb 6 \& tar zxf Jifty\-VERSION.tar.gz \& cd Jifty\-VERSION \& perl Makefile.PL \& make \& make test \& sudo make install .Ve .PP You may also have installed it via the package manager available for your Linux distribution. .PP Finally, you may want to use bleeding-edge features available only in the Jifty Subversion repository. This has a slightly higher risk, but this is what the Best Practical team does for their Jifty applications. When doing this, you will probably want to be sure to check out the exact same version as you are using on your development machines. .PP Be sure to run the tests when installing Jifty to make sure there aren't any problems on your production server that you need to fix before deploying your application. .PP \fICopy the Application\fR .IX Subsection "Copy the Application" .PP After you've gotten Jifty deployed, you need to copy your application onto the server. This can be done in whatever way suits your project. You can run your Jifty application straight out of the development directory just as you have on testing. Just place the directory into an appropriate location on your server. .PP It may be advisable to consider using a version control system, such as \s-1SVK\s0 or Subversion, to aid you in this process. For example, with either \s-1SVK\s0 or Subversion, any production customizations can be handled as branches of your application to help you keep those changes sorted out clearly. This can also help you if you make any tweaks to the code on the production server that need to be put back into your development. .PP Here is an example of how to create the branch in Subversion or. This example is built upon in the \*(L"Upgrading the Production Server\*(R" section below. .PP All these commands are assumed to be running on the production server in this example, but you could do much of these from anywhere. .PP .Vb 6 \& svn mkdir http://svn.example.com/myapp/branches \& svn copy http://svn.example.com/myapp/trunk \e \& http://svn.example.com/myapp/branches/production \& svn checkout http://svn.example.com/myapp/branches/production \e \& myapp \& cd myapp .Ve .PP Make sure to remember (possibly by recording it in the log messages) which revision your trunk was at when you ran the copy command. This will be important later. If you're using \s-1SVK\s0 rather than Subversion, you don't have to worry about this. .PP In \s-1SVK:\s0 .PP .Vb 4 \& svk mkdir //myapp/branches \& svk copy //myapp/trunk //myapp/branches/production \& svk checkout //myapp/branches/production myapp \& cd myapp .Ve .PP You will now have a copy of the latest version of your project in the directory named \fImyapp\fR. You can then make any of the modifications you need to to get your application configured for the production environment (read the following sections for details). .PP When you're finished, commit those changes to the branch: .PP .Vb 1 \& svn commit .Ve .PP or in \s-1SVK:\s0 .PP .Vb 1 \& svk commit .Ve .PP All of these changes will be made only to the production branch. In the upgrade section, it will be clearer how this will help you. .PP \fITweak the Configuration\fR .IX Subsection "Tweak the Configuration" .PP After you've copied your application onto the server, change into that directory and make any changes to your configuration required for production. .PP Put all your site-specific changes in \fIetc/site_config.yml\fR and never edit \fIetc/config.yml\fR, as it will be overwritten with the next application update. .PP Here are some things you'll want to consider changing: .IP "AdminMode" 4 .IX Item "AdminMode" While developing, you'll probably want to try running your application with this turned off. This turns on the administrative functions for managing models, data, and actions. .Sp Set this to 0 to turn it off. .IP "Database" 4 .IX Item "Database" These settings will be covered in more detail in \*(L"Deploy the Database\*(R". .IP "DevelMode" 4 .IX Item "DevelMode" This turns off certain checks that slow down a production system but are vital to fast development. For example, with ever request to a server with \f(CW\*(C`DevelMode\*(C'\fR turned on, the server checks to see if any of the library or template files have changed and reloads them, if this is turned on. .Sp By switching this setting off, you also enable extra caching and speed-up features including the use of CSS::Squish, which helps your application load \s-1CSS\s0 files more quickly. .IP "LogConfig" 4 .IX Item "LogConfig" You may wish to add this option to specify a custom logger configuration. See Jifty::Logger. .IP "LogLevel" 4 .IX Item "LogLevel" Depending on your environment, you may want to adjust the default log level or you may want to customize the log configuration by introducing an \fIetc/log4perl.conf\fR configuration file. .Sp You can set the LogLevel to: \s-1DEBUG\s0, \s-1INFO\s0, \s-1WARN\s0, \s-1ERROR\s0, or \s-1FATAL\s0 to specify the level. If you want a custom log configuration for your server (allowing you to have per-module log settings among other features), you need to set \*(L"LogConfig\*(R" and possibly \*(L"LogReload\*(R". See Jifty::Logger .Sp This configuration setting is overridden by the \s-1JIFTY_LOG_LEVEL\s0 environment variable (if set). .IP "LogReload" 4 .IX Item "LogReload" This allows you specify a custom reload period for your log configuration, if you use \*(L"LogConfig\*(R". See Jifty::Logger. .IP "Mailer" 4 .IX Item "Mailer" In some cases you will want to adjust the mailer configuration used by Jifty. The mail configuration is used whenever Jifty::Notification messages are sent, which may or may not be used by your application. .Sp If you change the \f(CW\*(C`Mailer\*(C'\fR setting, be sure to also change \f(CW\*(C`MailerArgs\*(C'\fR to match. .Sp See Jifty::Notification and Email::Send. .IP "MailerArgs" 4 .IX Item "MailerArgs" You may want to adjust the configuration of the mailer you are using. See Jifty::Notification and Email::Send. .IP "Plugins" 4 .IX Item "Plugins" You may want to disable plugins you've been using in your development that you don't need in production. In general, if these plugins are well-behaved this isn't necessary, but you can provide yourself with extra insurance in case they are not. .Sp You can disable them without removing them from the file by commenting them out using the Perl-style \*(L"#\*(R" comment mark. .IP "Web" 4 .IX Item "Web" .RS 4 .PD 0 .IP "BaseURL" 4 .IX Item "BaseURL" .PD You will want to change the \f(CW\*(C`BaseURL\*(C'\fR setting under \f(CW\*(C`Web\*(C'\fR to make sure it shows the name of your production server's base \s-1URL\s0. .IP "ServeStaticFiles" 4 .IX Item "ServeStaticFiles" If you want to improve the performance of your server, you may want your main web server to serve static files rather than having Jifty do it. You will need to manually flatten the static file structure yourself for this to work, but it can be done. .RE .RS 4 .RE .IP "etc." 4 .IX Item "etc." Your application configuration may have additional changes that need to be made for your application to operate properly in a production environment. .Sp Make sure to check over all the settings to make sure they will work in your production environment to save yourself headaches later. .PP \fIDeploy the Database\fR .IX Subsection "Deploy the Database" .PP If you've been developing your server using the default SQLite configuration, you will likely want to change this for your production server. SQLite might work for production environment, but chances are it will not. .PP For your production system, you will probably want to modify the \f(CW\*(C`Driver\*(C'\fR to suit your production environment. For example, if you were going to change to use a MySQL server, you might change your \f(CW\*(C`Database\*(C'\fR configuration in \fIetc/site_config.yml\fR to something like this: .PP .Vb 8 \& Database: \& Database: myapp \& Driver: mysql \& Host: mysql.example.com \& Password: \*(Aqsecret\*(Aq \& RecordBaseClass: Jifty::DBI::Record::Cachable \& User: myapp_user \& Version: 0.0.1 .Ve .PP In this example, the server is running the MySQL driver, connecting to the host at \*(L"mysql.example.com\*(R" with the username \*(L"myapp_user\*(R" and password \*(L"secret\*(R". .PP You will need to create the database and grant access to the users according to your \s-1RDBMS\s0 administrator documentation. In MySQL, this could be done to match the example above by running these commands: .PP .Vb 2 \& mysqladmin \-uadmin \-psecret create myapp \& mysql \-uadmin \-psecret \-e "grant all on myapp.\e* to myapp_user\*(Aq@\*(Aqmyapp.example.com identified by \*(Aqsecret\*(Aq" .Ve .PP Please refer to your \s-1RDBMS\s0 documentation for full details on how to configure your database. .PP \fIConfigure the Web Server\fR .IX Subsection "Configure the Web Server" .PP There are several ways to configure your web server. You can use FastCGI or mod_perl or you can use a proxy to the Jifty simple server. The first two options are what you will most likely want to do, but the proxy configuration is presented for completeness. .PP Configuring FastCGI .IX Subsection "Configuring FastCGI" .PP Several configurations are explained by the \*(L"fastcgi\*(R" in Jifty::Script::FastCGI script that comes with Jifty. It is recommended that you take one of those and modify the configuration to suit your needs. .PP It may take a few tries to get the configuration exactly right. Be sure to check the server logs for your web server when looking for problems. .PP Configuring mod_perl .IX Subsection "Configuring mod_perl" .PP Support for mod_perl version 2.0 is provided by Jifty::Script::ModPerl2. Remember that you need to completely stop and start the Apache server after the Perl modules in your application are changed. .PP Configuring a Proxy .IX Subsection "Configuring a Proxy" .PP You can use a proxy with the built-in server. This can be done with the following configuration in Apache: .PP .Vb 4 \& \& ProxyPass / http://localhost:8888/ \& ProxyPassReverse / http://localhost:8888/ \& .Ve .PP Place that declaration in your main configuration or virtual host configuration file and then whenever you run: .PP .Vb 1 \& bin/jifty server .Ve .PP Apache will proxy your server on port 80 for you. This may not work exactly as expected because the built-in server is intended for testing, not for a production environment. As such, it is not well-tested as a production server. .PP \fIConfigure File Permissions\fR .IX Subsection "Configure File Permissions" .PP The subdirectory in your application should be writable by the server process. If it runs as non-root \s-1UID\s0 (for example, FastCGI and Apache processes are usually running under the user named \fIapache\fR or \fIwww\fR or something alike), you need to change the group or user permissions for this directory. .PP For example, assume your application will run under user \fIapache\fR and group \fIapache\fR. Then the following commands should do the job: .PP .Vb 2 \& chgrp \-R apache var \& chmod \-R g+w var .Ve .PP A more flexible way would be to create a new group \fImyapp\fR and add \fIapache\fR user in it. This allows you to maintain the application from non-root login and use \f(CW\*(C`sudo\*(C'\fR for restarting Apache. .PP \fIAll Systems Go\fR .IX Subsection "All Systems Go" .PP Once you have done all of the above, your application should be ready to use at the production address you have configured. .SS "Updating the Production Server" .IX Subsection "Updating the Production Server" After you've made some collection of updates to your Jifty application, you'll then need to install those changes onto your server and prepare your application to use the changes. .PP This documentation assumes a \*(L"cold\*(R" upgrade with the application offline during the duration of the process. A future version of this document might also include instructions for performing a \*(L"hot\*(R" upgrade without taking the server offline. .PP You can do this with the following steps: .IP "1." 4 Shutdown the application. .IP "2." 4 Update the Jifty installation. .IP "3." 4 Update your Jifty application. .IP "4." 4 Merge in configuration changes. .IP "5." 4 Clean up any temporary and cached files. .IP "6." 4 Upgrade your database. .IP "7." 4 Start using the updated application. .PP \fIShutdown the Application\fR .IX Subsection "Shutdown the Application" .PP This process cannot be performed on a live server. If it is, bad things may happen. You may choose to shutdown the application in one of two ways: turn off your web server or reconfigure your web server into an offline mode. .PP Remember, shutdown all Jifty application processes before continuing, or bad things may happen! .PP Shutting Down the Server .IX Subsection "Shutting Down the Server" .PP This will involve a two step process. First, you will want to shutdown your web server. The second is to shutdown the Jifty server. If you are using the built-in Jifty server, you may do this by running: .PP .Vb 1 \& bin/jifty server \-\-stop .Ve .PP If you are using FastCGI, you will need to locate your server's process IDs and then kill all the processes. If this is the only FastCGI and Perl script running on your system, you may be able to just run: .PP .Vb 1 \& killall perl .Ve .PP However, that might stop too many processes in many environments, so you'll just have to find the processes and clean them up as suits your server. .PP Offline Mode .IX Subsection "Offline Mode" .PP If you want to provide you site visitors with some feedback letting them know that the web site is down, you might want to provide an alternative configuration for your application. You still need to stop all your Jifty application processes when you engage the offline configuration. .PP For example, you could have the following configuration on an Apache server to run an offline mode: .PP .Vb 4 \& \& RewriteEngine on \& RewriteRule ^.*$ /offline.html \& .Ve .PP Then create a file named \*(L"offline.html\*(R" in your server root containing the message you wish to give your visitors. .PP You can make this configuration change and then restart your web server to give it effect. Then, stop all the Jifty application processes. .PP \fIUpdate Jifty\fR .IX Subsection "Update Jifty" .PP This is exactly the same as \*(L"Install Jifty\*(R" above. Again, you'll probably want to install the same version as you are using to developing with. If you have not made any changes to the Jifty version you are using, you may skip this step. .PP \fIUpdate the Application\fR .IX Subsection "Update the Application" .PP This is again similar to what you've done above. You just need to update all the files that have changed. However, you should be careful not to clobber any configuration changes that you need to remember. .PP If you've used the suggestion of using a branch described above, you can automatically update your production server to use the latest code without risk of clobbering your changes on the production server. .PP In Subversion, you will first need to recall the revision of either the initial copy or of the last merge you performed. If you stored this information in the log message, you can retrieve it by running: .PP .Vb 1 \& svn log http://svn.example.com/myapp/branches/production .Ve .PP When you have the revision number, you can then merge in all the latest changes in your production server copy. Here, I assume that the revision number is \*(L"1234\*(R". .PP .Vb 2 \& cd myapp \& svn merge \-r 1234:HEAD http://svn.example.com/myapp/trunk . .Ve .PP If you're using \s-1SVK\s0, you can just run the following: .PP .Vb 2 \& cd myapp \& svk smerge //myapp/trunk . .Ve .PP \&\s-1SVK\s0 automatically remembers the revision number for you so you don't have to worry about it. .PP Next, watch for any conflicts that might have occurred and be sure to correct them. Check over all the changed files and make sure they look alright and you should also run your tests again to be sure everything is working. Once you're sure everything is correct, you can accept the changes with: .PP .Vb 1 \& svn commit .Ve .PP or: .PP .Vb 1 \& svk commit .Ve .PP Your code should now be ready. .PP \fIConfiguration Changes\fR .IX Subsection "Configuration Changes" .PP Again, you need to look for any configuration updates that need to adjusted. This is no different from the process during the initial installation. .PP \fIClear Temporary/Cached Files\fR .IX Subsection "Clear Temporary/Cached Files" .PP This step is important to prevent strange issues from occurring. You remove all files from the following directories: .IP "\(bu" 4 \&\fIvar/mason/cache\fR .IP "\(bu" 4 \&\fIvar/mason/obj\fR .PP You can run the following command (\fB\s-1BE\s0 \s-1CAREFUL\s0 \s-1TO\s0 \s-1TYPE\s0 \s-1THIS\s0 \s-1CORRECTLY\s0 \s-1OR\s0 \s-1PAY\s0 \s-1THE\s0 \s-1CONSEQUENCES\s0\fR): .PP .Vb 1 \& rm \-rf var/mason/{cache,obj}/* .Ve .PP This means that your application will have to rebuild these cached files, which will slow your application down slightly at first. .PP However, if these files are left in place, the Mason server may continue using cached versions of files that don't match your latest updates. This will lead to very strange problems. .PP \fIUpgrade the Database\fR .IX Subsection "Upgrade the Database" .PP If you've made any changes to the database schema or to the structure of your data that requires an upgrade, you will need to run: .PP .Vb 1 \& bin/jifty schema \-\-setup .Ve .PP See Jifty::Manual::Upgrading. .PP \fIAll Systems Go\fR .IX Subsection "All Systems Go" .PP Now that all these changes have been made, you are ready to start your web server or reconfigure your web server for production mode and restart. .SH "SEE ALSO" .IX Header "SEE ALSO" Jifty::Manual::Tutorial, Jifty::Manual::Upgrading