Directus deployment on Elastic Beanstalk

724 Views Asked by At

I cloned Directus 8 from github. I run it in my local server. It worked fine without any problems.

Then I uploaded code to AWS Elastic Beanstalk (PHP, apache). but it showed 500 Internal Server Error.

error log: /var/www/html/directus/public/.htaccess: <IfModule not allowed here

I added .ebextensions/setup.config file to my root folder, like this.

files:          
  "/etc/httpd/conf.d/enable_mod_rewrite.conf": 
     mode: "644"
     owner: root
     group: root
     content: |
       AllowOverride All

but my Beanstalk said Unsuccessful command execution on instance id(s) 'i-0f6...'. Aborting the operation. and went to degrading state.

How to fix this?

1

There are 1 best solutions below

0
On BEST ANSWER

This answer is for Directus 8 (PHP)

Tried almost all ways of apache settings using .ebextensions and .platform nothing worked.

Then tried NGINX with custom .platform configs. It worked. Answering the steps which I did, may be helpful to someone else, who has the same problem


  1. Directus docs has some configs for NGINEX, go through it

  2. create nginex.conf file under .platform/nginx folder

platform/nginx

  1. we are going to replace existing nginex.conf inside the beanstalk. copy existing nginex.conf using ssh to ec2 instance and add the custom configs mentioned in the docs and paste it to our newly created .platform/nginx/nginex.conf

below is my custom .platform/nginx/nginex.conf

user                    nginx;
error_log               /var/log/nginx/error.log warn;
pid                     /var/run/nginx.pid;
worker_processes        auto;
worker_rlimit_nofile    32136;    
events {
    worker_connections  1024;
}    
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    include       conf.d/*.conf;

    map $http_upgrade $connection_upgrade {
        default     "upgrade";
    }

    server {
        listen 80 default_server;

        location / {
            try_files $uri $uri/ /index.php?$args;
        }

        location /admin {
            try_files $uri $uri/ /admin/index.html?$args;
        }

        location /thumbnail {
            try_files $uri $uri/ /thumbnail/index.php?$args;
        }

        # Deny direct access to php files in extensions
        location /extensions/.+\.php$ {
            deny all;
        }
        
        # All uploads files (originals) cached for a year
        location ~* /uploads/([^/]+)/originals/(.*) {
            add_header Cache-Control "max-age=31536000";
        }

        # Serve php, html and cgi files as text file
        location ~* /uploads/.*\.(php|phps|php5|htm|shtml|xhtml|cgi.+)?$ {
            add_header Content-Type text/plain;
        }

        # Deny access to any file starting with .ht,
        # including .htaccess and .htpasswd
        location ~ /\.ht {
            deny all;
        }

        # pass PHP scripts to FastCGI server
        location ~ \.php$ {
            fastcgi_pass unix:/var/run/php-fpm/www.sock;
            fastcgi_index  index.php;
            include /etc/nginx/fastcgi.conf;                
        }        

        access_log    /var/log/nginx/access.log main;

        # Include the Elastic Beanstalk generated locations
        include conf.d/elasticbeanstalk/*.conf;
    }
}
  1. done, when we uploading it, beanstalk will automatically replace our custom nginex.conf with existing nginex.conf. (note: we can add the changes only instead of replacing, but it didn't work at the time I tried)