Showing posts with label symfony. Show all posts
Showing posts with label symfony. Show all posts

Wednesday, July 1, 2015

Elastic beanstalk docker - map symfony logs to S3

In config.yml

monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: error
            buffer_size:  200
            handler:      nested
        nested:
            type:  stream
            path:  %log_dir%/moonlight_%kernel.environment%.log
            level: debug

Make log_dir in parameter.yml to be /var/log/nginx or anywhere you want. 

Create a file called Dockerrun.aws.json

{
  "AWSEBDockerrunVersion": "1",
  "Ports": [
    {
      "ContainerPort": "80"
    }
  ],
  "Logging": "/var/log/nginx"
}

The logging entry above needs to be the same as log_dir you set in parameter.log.

In Elastic Beanstalk settings, click on Configuration on the left side, then software configuration.

Check "Enable log file rotation to Amazon S3. If checked, service logs are published to S3."

If you are using a custom IAM, you will need to grant read and write permissions to S3:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "Stmt1435793320000",
            "Effect": "Allow",
            "Action": [
                "s3:GetObject",
                "s3:GetObjectVersion",
                "s3:ListBucket",
                "s3:ListBucketVersions"
            ],
            "Resource": [
                "arn:aws:s3:::elasticbeanstalk-*/resources/environments/logs/*"
            ]
        }
    ]
}

Log rotations happen about every 15 mins. You can search the s3 directory elasticbeanstalk-*/resources/environments/logs/* for logs.


Saturday, May 30, 2015

Set up MAMP with Nginx, php-fpm and symfony on MacOSX

To make this work, you will need to have MAMP installed.

The steps are as follows: install php-fpm, add your symfony config to nginx.conf, start the server.

Install php5-fpm

You can use macport or brew to install php5-fpm

After it's install, search php5-fpm by doing "which-fpm". Note that it may be called "php-fpm" in some installations.

php5-fpm requires two configurations to be set up: /etc/php-fpm.conf and /etc/php-fpm/pool.d/{whatever}.conf

Sample php-fpm.conf:

https://github.com/perusio/php-fpm-example-config/blob/tcp/fpm/php5-fpm.conf

Sample pool.d/{whatever}.conf

http://www.if-not-true-then-false.com/2011/nginx-and-php-fpm-configuration-and-optimizing-tips-and-tricks/

Start php5-fpm by

> sudo php5-fpm

In your MAMP config - /conf/nginx/nginx.conf, put in the relevant http and https server settings:

server {
listen 80;
   server_name localhost_moonlight;
   root /Users/rei999/Documents/symfony_workspace/moonlight/web;

   location / {
       try_files $uri /app_dev.php$is_args$args;
   }
   # DEV
   # This rule should only be placed on your development environment
   # In production, don't include this and don't deploy app_dev.php or config.php
   location ~ ^/(app_dev|config)\.php(/|$) {
       fastcgi_pass 127.0.0.1:9000;
       fastcgi_split_path_info ^(.+\.php)(/.*)$;
       include fastcgi_params;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       fastcgi_param HTTPS off;
       }

   error_log /Applications/MAMP/logs/nginx/moonlight_error.log;
   access_log /Applications/MAMP/logs/nginx/moonlight_access.log;
}

server {
listen 443 ssl;
   server_name localhost_moonlight;

   ssl_certificate      /Applications/MAMP/conf/ssl/server.crt;
        ssl_certificate_key  /Applications/MAMP/conf/ssl/server.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

   root /Users/rei999/Documents/symfony_workspace/moonlight/web;

   location / {
       try_files $uri /app_dev.php$is_args$args;
   }
   # DEV
   # This rule should only be placed on your development environment
   # In production, don't include this and don't deploy app_dev.php or config.php
   location ~ ^/(app_dev|config)\.php(/|$) {
       fastcgi_pass 127.0.0.1:9000;
       fastcgi_split_path_info ^(.+\.php)(/.*)$;
       include fastcgi_params;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
       fastcgi_param HTTPS off;
       }

   error_log /Applications/MAMP/logs/nginx/moonlight_error.log;
   access_log /Applications/MAMP/logs/nginx/moonlight_access.log;
}



Depending on your PHP-FPM config, the fastcgi_pass can also be fastcgi_pass 127.0.0.1:9000.

Start MAMP Nginx.

Saturday, June 15, 2013

Symfony 2 JS Error in Production Only - Assetic Compression

If your JS files work perfectly in dev but not in production, it may be a compression issue indirectly caused by the Assetic bundle.

Make sure every single javascript file ends with a semi colon. The issue is that JS allows files to not end with semi colon, but when Assetic compresses and combines all JS files, the files are appended and causing incorrect syntax error.

Friday, June 14, 2013

Symfony 2 Composer - error occurred when generating the bootstrap file


[RuntimeException]                                  
An error occurred when generating the bootstrap file.

If you see the following error during updating Symfony vendors via Composer, do the following:


php composer update --no-scripts
php vendor/sensio/distribution-bundle/Sensio/Bundle/DistributionBundle/Resources/bin/build_bootstrap.php