by Joan Ging / twitter: @mindfulbreath


This article describes how to deploy Symfony2 on Zend's phpcloud.com development environment. At the time of writing this, I have not a) done anything more with the Symfony2 installation than confirm the demo site operates, nor b) attempted to integrate the phpcloud database instance with the Symfony2 install. I intend to do both in the near future and will update this article at that time. Also, there are probably a million ways to do what this article covers. By the way, I am in no way affiliated with Symfony or Zend and am doing this purely as an example of what worked for me. I hope that it works for you!

What I Assume

I assume that you have already created an account, a container, and an empty application within your container on phpcloud.com. I also assume that you have set up your SSH key pair in your account on phpcloud.com.

What This Won't Cover

I am not going to cover how to work with Zend Studio or phpcloud or git at this time, though they all work quite nicely together, along with Symfony2. There are several excellent tutorials online for this already, and I will link them in the Additional Resources section at the end of this article.

What You Will Need

  • Symfony Standard Edition (version 2.0.4 at the time of writing) - be sure to download the version that includes vendors
  • File editor - I used Zend Studio 9 Beta, but text editors will work fine, too.
  • SFTP Client - I used FileZilla , but any FTP client capable of the SFTP protocol via SSH key will work.


Installing Symfony2 on phpcloud.com

Step 1 - Prepare Symfony2


  • Unpack the Symfony2 archive. You should wind up with:

    Symfony
        |-- /app
        |-- /bin
        |-- /src
        |-- /vendor
        |-- /web
        |-- deps
        |-- deps.lock
        |-- LICENSE
        |-- README.md


  • In the file editor of your choice, open the file:

    Symfony/web/config.php

  • REPLACE the following lines of code:

    if (!in_array(@$_SERVER['REMOTE_ADDR'], array(
        '127.0.0.1',
        '::1',
    ))) {
        header('HTTP/1.0 403 Forbidden');
        exit('This script is only accessible from localhost.');
    }


    with:

    /* DISABLED FOR PHPCLOUD
    if (!in_array(@$_SERVER['REMOTE_ADDR'], array(
        '127.0.0.1',
        '::1',
    ))) {
        header('HTTP/1.0 403 Forbidden');
        exit('This script is only accessible from localhost.');
    }
    */


    Disabling this section of code will allow you to run the config script on a remote host. Note: for maximum security you should remove the comment tags to enable this section again once you have finished your configuration.

  • REPLACE the following lines of code:

    if (!(!(function_exists('apc_store') && ini_get('apc.enabled')) || version_compare(phpversion('apc'), '3.0.17', '>='))) {
        $majorProblems[] = 'Upgrade your APC extension (3.0.17+)';
    }


    with:

    /* DISABLED FOR PHPCLOUD
    if (!(!(function_exists('apc_store') && ini_get('apc.enabled')) || version_compare(phpversion('apc'), '3.0.17', '>='))) {
        $majorProblems[] = 'Upgrade your APC extension (3.0.17+)';
    }
    */


    Phpcloud has APC installed, and has the correct functions available. For some reason, the phpcloud instance does not seem to have a version number to compare against and thus fails this test. Preliminary testing seems to indicate the phpcloud instance APC version is adequate, so disabling this check will allow us to move forward with configuration.

  • Save and close Symfony/web/config.php

  • Open the parameters.ini file found here:

    Symfony/app/parameters.ini

    Modify the file as shown below, replacing ‹container› with your phpcloud container name, ‹username› with your phpcloud login username, and ‹password› with your phpcloud login password. You should also put something much more random for the secret string.


    When finished, save and close the file.

  • CREATE an .htaccess file here:

    Symfony/.htaccess

    Open the new file, and put this line at the top:

    php_flag short_open_tag off

    By default the phpcloud instance has the short_open_tag php.ini setting turned on, but Symfony2 would like it to be off. Be aware that this will make it impossible for you to use ‹?=$item?› to print the value of $item. You must use ‹?php echo $item; ?›.

Step 2 - Set Up SFTP

The following instructions are for FileZilla FTP Client , which is available for a variety of platforms.

  • In FileZilla, IMPORT your private SSH key that you created when you created your container on phpcloud.com by going to the Edit > Settings... menu on the toolbar.


    Under Connection on the left, select SFTP. Click Add keyfile... button and locate the private SSH key you downloaded from phpcloud. Note: go ahead and convert the key to a new format if you are prompted to do so. Click "OK" when the key shows in the list.

  • Open the Site Manager:

    File > Site Manager

  • Click "New Site" to create a new connection.


    Complete all of the highlighted fields in the screenshot above, replacing jging.my.phpcloud.com with your phpcloud container URL and using your own phpcloud username. A password will not be required because you are using the keypair to authenticate yourself. Click OK to save the settings and connect.

  • Locate your public web directory. When you connect to your site, you should see something similar to this:


    The public site directory should be located here:

    /
        |-- /.apps
            |-- /http
                |-- /__default__
                    |-- /0
                        |-- /‹ApplicationName›
                            |-- /‹version›
                                |-- /public    <--PUBLIC WEB DIRECTORY
        |-- /.ssh
        |-- /applications
        |-- /www


    Upload the entire Symfony folder to your public web directory. It may take a while.

  • Set write permissions on the cache and logs directories on the server. While still in your public web directory in your phpcloud application, locate the two highlighted folders:


    To change permissions (chmod), right-click on the folder and select File permissions....


    The numeric value should be set to 777 as shown above. Again, you'll need to do this on both the cache and logs directory.

Step 3 - Complete Symfony2 Configuration



Congratulations!

Hopefully you now have a successful implementation of Symfony2 on Zend's phpcloud.com development cloud.

Please Provide Feedback

I hope you will take a moment to provide feedback about how it went for you, good or bad. Feel free to ask questions as well, and I will do my best to respond quickly.

Additional Resources

While I only covered a small portion of working with Symfony2 and phpcloud.com, there are several other tutorials online I have found useful in working with these technologies:

Symfony2 - The Book
phpcloud.com Help (requires phpcloud.com login)
Test Drive Zend Developer Cloud with Zend Studio 9
Zend Studio + GitHub

Embed


Title & Content     Content


Copy and paste the the embed code above.