A common feedback from developers using Web Apps on
Zend Developer Cloud is the ability to
chmod() directories for deployed applications. For example in
Joan Ging's
post you can notice that one needs to use external tools (like WinSCP or Zend Studio) to chmod the
logs and
cache directories that are used by Symfony2, otherwise these directories are write-protected and the application fails to launch.
There are two methods to chmod application directories after the deployment stage and before launching.
So let's review the two alternatives, both of them result in the same state:
- Using Deployment Scripts (during deployment phases).
- Using Zend Studio (after the application is deployed)
Using Deployment Scripts
One of the new features in phpCloud is the ability to
deliver hook scripts alongside the application. There are several types of scripts for each phase in the deployment process (i.e, Staging, Activation).
In the following example, chmod is executed on both logs and cache directories immediately after being executed on their parents.
First we define the "scripts" directory to contain all deployment triggers. This is done as part of
the deployment descriptor file (named
deployment.xml):
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<package xmlns="http://www.zend.com/server/deployment-descriptor/1.0" version="1.0">
<name>Symfony2Cloud</name>
<version>
<release>1.0.0</release>
</version>
<appdir>data</appdir>
<docroot>data/web</docroot>
<scriptsdir>scripts</scriptsdir>
</package>
Then we create a post_stage.php file under this directory with this content:
<?php
/* @var string holds the application (absolute) path */
$appLocation = getenv('ZS_APPLICATION_BASE_DIR');
/* chmod cache and logs */
chmod ( $appLocation, 0775 );
chmod ( $appLocation . '/app/',0775 );
chmod $appLocation . '/app/cache/', 0775 );
chmod ( $appLocation . '/app/logs/', 0775 );
The complete source code for this application is available in the
Synfony2Cloud project on Github.
Using Zend Studio 9.0
Once you deploy your application in Zend Studio, a connection to your container is created under the hood. You can view this connection and modify the directories permissions in the
Remote System view.
1. Start by showing (or "unhiding") hidden files. This allows you to browse the ".app" directory which holds all deployed applications.
Go to Preferences > Remote Systems > Files and make sure "Show hidden files" is marked.
2. Browse to the application you want to chmod() by expanding the file tree in the
Remote Systems view
3. Right click on the directory and select
Properties.
4. Select the
Permissions node, alter the permissions you want to allow and click
Apply.
Although Alternative #2 is more flexible, I highly recommend Alternative #1 which streamlines the deployment phase and lets you adjust the code and create an automate deployment process.