vmware-marketplacenginx

Get started with Symfony

The Symfony framework is not installed by default in Bitnami installations. However, it can be easily enabled via the Symfony CLI tool. In this guide, you will learn how to install and configure a Symfony project.

Installation and Testing

NOTE: This section assumes that the application project directory will be located at /opt/bitnami/projects/APPNAME. Remember to replace the APPNAME placeholder with the application name, such as myapp.

  • First, install the Symfony CLI tool and make it available in your PATH. Run the following commands:

      $ wget https://get.symfony.com/cli/installer -O - | bash
      $ sudo mv /home/bitnami/.symfony/bin/symfony /usr/local/bin/symfony
    
  • Create a project directory where to store your application. Run the following commands:

      $ sudo mkdir -p /opt/bitnami/projects/APPNAME
      $ sudo chown $USER /opt/bitnami/projects/APPNAME
    
  • Create the Symfony project:

      $ symfony new --full --no-git /opt/bitnami/projects/APPNAME
    
  • Create the NGINX configuration for your application. Follow these steps:

    • Create the /opt/bitnami/nginx/conf/server_blocks/APPNAME-server-block.conf file containing the application’s HTTP server block configuration with the configuration block shown below:

        server {
            # Port to listen on, can also be set in IP:PORT format
            listen 80 default_server;
            root /opt/bitnami/myapp/public;
            # Catch-all server block
            # See: https://nginx.org/en/docs/http/server_names.html#miscellaneous_names
            server_name _;
            include  "/opt/bitnami/nginx/conf/bitnami/*.conf";
        }
      
    • Create the /opt/bitnami/nginx/conf/server_blocks/APPNAME-https-server-block.conf file containing the application HTTPS server block configuration with the configuration block shown below:

        server {
            # Port to listen on, can also be set in IP:PORT format
            listen 443 ssl default_server;
            root /opt/bitnami/myapp/public;
            # Catch-all server block
            # See: https://nginx.org/en/docs/http/server_names.html#miscellaneous_names
            server_name _;
            ssl_certificate      bitnami/certs/server.crt;
            ssl_certificate_key  bitnami/certs/server.key;
            include  "/opt/bitnami/nginx/conf/bitnami/*.conf";
        }
      
  • Finally, restart the NGINX server:

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

You can now verify that the example application is working by visiting its URL using your browser at http://SERVER-IP/. 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:

  • To secure your application, modify the encryption keys in the .env file. Ideally, use a key that’s 32 characters or longer in length and not guessable.

      APP_SECRET="cf05b596287d41e11a9ca958ad289e00"
    

    On Linux, you can use a command like pwgen 32 to generate a 32-character random key. On Windows, you can use a tool like PWGen.

  • If your application will use a database, edit the database settings in the .env file.

      DATABASE_URL="mysql://db_user:db_password@127.0.0.1:3306/db_name"
    

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

      extension=pdo_pgsql
    

More Information

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

Last modification February 9, 2023