Skip to content

Instantly share code, notes, and snippets.

@r0lodex
Created October 2, 2023 07:50
Show Gist options
  • Save r0lodex/40a943e42eb94328bcd14bb93ca0352d to your computer and use it in GitHub Desktop.
Save r0lodex/40a943e42eb94328bcd14bb93ca0352d to your computer and use it in GitHub Desktop.
Wordpress Beanstalk

Hermo x Woocommerce

This is a port of Hermo ecommerce system to Woocommerce. This application is designed to work with AWS Elastic Beanstalk. Deployment is made via bitbucket only triggered via the branch master (see bitbucket-pipelines.yml).

For development, name your branch dev-* and you can deploy to staging environment, provided the environment is active in AWS Elastic Beanstalk.

Developing Locally

  • You'll need nginx/apache that points to this code.
  • Point your database to runa-alpha with the database name shopx_production
  • Read more below on setting up the environment variables.
  • Example nginx config with Basic Auth implemented (auth is optional):
server {
    listen 80;
    server_name shop.hermo.my;
    return 301 https://shop.hermo.my$request_uri;
}

server {
    listen 443 ssl;
    ssl_certificate /etc/nginx/ssl/shop.hermo.my/shop.hermo.my.crt;
    ssl_certificate_key /etc/nginx/ssl/shop.hermo.my/shop.hermo.my.key;

    server_name shop.hermo.my;
    root /var/www/shopx;
    index index.php;

    auth_basic "Exclusive Members";
    auth_basic_user_file /var/www/shopx/.htpasswd;

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

    location ~ \.php$ {
        try_files $uri /index.php =404;
        fastcgi_pass php-fpm:9000;
        fastcgi_index index.php;
        fastcgi_buffers 16 16k;
        fastcgi_buffer_size 32k;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        #fixes timeouts
        fastcgi_read_timeout 600;
        include fastcgi_params;
    }

    location ~ /\.ht {
        deny all;
    }
}

Structure

This is a customized wordpress designed to work with S3, Beanstalk and Cloudfront. Here's some notes:

$_SERVER['DB_NAME']          = 'x';
$_SERVER['DB_USER']          = 'x';
$_SERVER['DB_PASSWORD']      = 'x';
$_SERVER['DB_HOST']          = 'x';
$_SERVER['DB_CHARSET']       = 'utf8mb4';
$_SERVER['DB_COLLATE']       = '';
$_SERVER['AUTH_KEY']         = 'x';
$_SERVER['SECURE_AUTH_KEY']  = 'x';
$_SERVER['LOGGED_IN_KEY']    = 'x';
$_SERVER['NONCE_KEY']        = 'x';
$_SERVER['AUTH_SALT']        = 'x';
$_SERVER['SECURE_AUTH_SALT'] = 'x';
$_SERVER['LOGGED_IN_SALT']   = 'x';
$_SERVER['NONCE_SALT']       = 'x';
$_SERVER['WP_DEBUG']         = false;
$_SERVER['AWS_ACCESS_KEY']   = 'x';
$_SERVER['AWS_SECRET']       = 'x';
  • If you intend to update the environment variables, don't forget to add it in .ebextensions/options.config as well, to update Beanstalk on the additional variables.
  • Nginx configurations is managed by Beanstalk, which you can customize at .platform/nginx/
  • Please note that the configuration will only reflect in Beanstalk environment, not locally.

Setting Up Basic Auth Password

  • sh -c "echo -n 'username:' >> .htpasswd" — Replace username with your desired password
  • sh -c "openssl passwd -apr1 >> .htpasswd"
  • Copy the output of cat .htpasswd
  • Then update the password in .ebextensions/options.config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment