Skip to content

Instantly share code, notes, and snippets.

@lelledaniele
Last active February 21, 2018 09:37
Embed
What would you like to do?
cloud9 symfony apache config server

Symfony on Cloud9

Install Symfony

Configuration

  • DB Host: 0.0.0.0 or '' empty string. Result of function getenv('IP')
  • DB Password: YOUR_PASSWORD
  • DB Name: c9
  • DB User: YOUR_USERNAME
  • Generate secret parameter

Setup Apache

Edit the Virtual Host config file

sudo vi /etc/apache2/sites-enabled/001-cloud9.conf

Replace the content with these lines


<VirtualHost *:8080>
    DocumentRoot /home/ubuntu/workspace/web
    ServerName https://${C9_HOSTNAME}:443

    LogLevel info

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /home/ubuntu/workspace/web>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
        DirectoryIndex app_dev.php
    </Directory>
</VirtualHost>

ServerName https://${C9_HOSTNAME}
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Allow Cloud9 to run dev environment

Replace these lines

// This check prevents access to debug front controllers that are deployed by accident to production servers.
// Feel free to remove this, extend it, or make something more sophisticated.
if (isset($_SERVER['HTTP_CLIENT_IP'])
  || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
  || !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1']) || php_sapi_name() === 'cli-server')
) {
  header('HTTP/1.0 403 Forbidden');
  exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}

with these lines

// Allow Cloud9 IDE to run the dev environment
if(getenv('C9_USER') !== 'YOUR_USERNAME') {

  // This check prevents access to debug front controllers that are deployed by accident to production servers.
  // Feel free to remove this, extend it, or make something more sophisticated.
  if (isset($_SERVER['HTTP_CLIENT_IP'])
    || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
    || !(in_array(@$_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1']) || php_sapi_name() === 'cli-server')
  ) {
    header('HTTP/1.0 403 Forbidden');
    exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
  }

}

Restart Apache

Change .htaccess

Take a backup of .htaccess

cp web/.htaccess web/.htaccess-live.

  • Exclude the .htaccess from your GIT repository
  • Remember to rename .htaccess-live to .htaccess on production

Allow app_dev.php as default enviroment


# Change line 6
# DirectoryIndex app.php
DirectoryIndex app_dev.php

# Change line 57
# RewriteRule ^ %{ENV:BASE}/app.php
RewriteRule ^ %{ENV:BASE}/app_dev.php


Lelle - License

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment