generallapp

Get started with Symfony

Overview

The Symfony framework is installed in the frameworks/symfony directory in the installation directory. This directory includes an example application. Application code is in the app/ directory, application configuration files are in the conf/ directory and public files, such as HTML pages, CSS and JavaScript files, images and other media assets are stored in the web/ directory.

Activation and Testing

To enable the example application, edit the Apache configuration file at /opt/bitnami/apache2/conf/bitnami/bitnami-apps-prefix.conf and uncomment the following line

Include "/opt/bitnami/frameworks/symfony/conf/httpd-prefix.conf"

Then, restart the Apache server.

$ sudo /opt/bitnami/ctlscript.sh restart apache

The Symfony application is configured by default to only allow requests originating from localhost for security reasons. As a result, you will see a message like You are not allowed to access this file. Check app_dev.php for more information when you try to access the example application on these platform.

To allow access to the example application from hosts other than localhost, edit the file /opt/bitnami/frameworks/symfony/web/app_dev.php and within it, disable the IP address check at the top of the file by commenting out the relevant lines. After modification, the relevant section of the file should look like this:

// 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'], array('127.0.0.1', 'fe80::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.');
}
*/

You can now verify that the example application is working by visiting its URL using your browser at http://SERVER-IP/symfony/app_dev.php.

Here is an example of what you might see:

Symfony welcome page

Configuration

Before using the example application, here are a few important points to consider:

  • If your application will use a database, edit the database settings in the app/config/parameters.yml file.

    parameters:
    database_driver: pdo_mysql
    database_host: 127.0.0.1
    database_port: 3306
    database_name: database_name
    database_user: user
    database_password: pass
    

    MySQL support is already available by default. If you plan to use PostgreSQL, enable the php_pdo_pgsql extension in the /opt/bitnami/php/etc/php.ini file.

    extension=php_pdo_pgsql
    
  • To move the Symfony application such that it is available at the root URL of the server (without the /symfony URL suffix), follow these steps:

    • Edit the /opt/bitnami/frameworks/symfony/conf/httpd-prefix.conf file so that it looks like this:

      DocumentRoot "/opt/bitnami/frameworks/symfony/web/"
      #Alias /symfony/ "/opt/bitnami/frameworks/symfony/web/"
      #Alias /symfony "/opt/bitnami/frameworks/symfony/web"
      Include "/opt/bitnami/frameworks/symfony/conf/httpd-app.conf"
      
    • Edit the /opt/bitnami/frameworks/symfony/conf/httpd-app.conf file and replace the AllowOverride None directive with the AllowOverride All directive:

      AllowOverride All
      
    • Restart the Apache server:

      $ sudo /opt/bitnami/ctlscript.sh restart apache
      

    You should now be able to access the example application at the root URL of your server.

Upgrading Symfony 2.x

NOTE: The steps below assume that you have already activated the Symfony example application.

  • Log in to your server console.

  • Update the framework by executing the following commands:

    $ cd /opt/bitnami/frameworks/symfony
    $ sudo composer self-update
    $ sudo composer update
    
  • Change the permissions of the app/cache directory so that it is writable by the Web server:

    $ cd /opt/bitnami/frameworks/symfony/app
    $ sudo chown -R bitnami:daemon cache
    $ sudo chmod -R 775 cache
    

You should now be able to access the example application and verify that it is using the latest version of Symfony, as shown below:

Smarty welcome page

More Information

Learn more about developing applications with Symfony at http://symfony.com/doc/current/.

Last modification May 9, 2019