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.

Wednesday, May 13, 2015

Handy RabbitMQ commands

Running rabbitmq in background:

rabbitmq-server -detached

Checking status:

rabbitmqctl status

Stopping:

rabbitmqctl stop

Show queues:

rabbitmqctl list_queues

Show queues with message status

rabbitmqctl list_queues name messages_ready messages_unacknowledged

Installing pip and supervisor on mac

Start by getting installing pip from the following link:

https://pip.pypa.io/en/stable/installing.html

Insall supervisor (there's no stable release of supervisor at the time of this writing, use the --pre flag):

> pip install supervisor --pre

Supervisor should be running already.

Copy the config to /etc

> echo_supervisord_conf > /etc/supervisord.conf

If supervisord is not already started, run supervisord in the directory your desired config is located. If you don't want to use the /etc/supervisord.conf and you have it somewhere else, run it there.

Start supervisord

> supervisord

Restart all supervisor processes.

> sudo supervisorctl restart all

If you want to start a program, you need to use :*, as supervisord names each program along with it's process name. Assume you defined your program as [program:hello]:

> supervisorctl
> start hello:*

Stop supervisor:

> ps -ef | grep supervisord

This should show the process id running supervisord. Terminate it by issuing a kill command.

501 95787     1   0 Fri07pm ??         0:02.92 /usr/bin/python /usr/local/bin/supervisord

> kill -s SIGTERM 95787

For a sample supervisord config, check here.

Thursday, April 9, 2015

phpstorm xdebug php.ini settings

Put the following into your php.ini

[xdebug]
zend_extension="/Applications/MAMP/bin/php/php5.5.22/lib/php/extensions/no-debug-non-zts-20121212/xdebug.so"
xdebug.profiler_enable=1
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000
xdebug.idekey=PHPSTORM

Friday, March 13, 2015

Bee run failed for Golang and Beego

If you are using beego and bee in your Golang project, you may run into an issue that says "Run failed" when you started "bee run"

Assuming you cd into your folder and the error still persists, try running "bee version".

bee   :1.2.4
beego :1.4.3

exec: "go": executable file not found in $PATH

If you see the above message, you may find that the newest Golang SDK from google is naming "go" command as "goapp".

What you need to do is to rename "go_appengine/goapp" to "go_appengine/go".

And rename "go_appengine/goroot/goapp" to "go_appengine/goroot/go".



Thursday, June 5, 2014

Setting up Wordpress on Elastic Beanstalk

ElasticBeanStalk is a service that automates scaling, load-balancing, and deploying applications so you can concentrate on only software development. In a way, it is very similar to Google App Engline.

In this article, we will visit how we can set up Wordpress on Elastic Beanstalk.


Configuration the Elastic Beanstalk Environment

First log into your ElasticBeansTalk and click on Create a New Application.

Enter the Application Name and Description and click Next.

Click on "Create one now" to create a new environment.

Environment tier: Web Server 1.0
Predefined configuration: PHP
Environment type: Load balancing, autoscaling

Note for Environment tier, Web Server handles web requests (HTTP/S) while workers handle background processes.

Choose sample application for now

You will then be prompted to input an Environment Name. Label it whatever, as we will use CNAME later.

For Additional Resources, check create an RDS DB instance with this environment.

In Configuration Details, select your EC2 key pair and leave the other details as it is. You can always change these later.

For RDS configuration, put 5GB for allocated storage. Input the username and password. Select Create snapshot and single availability zone.

Click Launch.

Once it's launched, click Configuration on the left sidebar, then Software Configuration. In PARAM1, set to production, staging or something else.


Installing Wordpress

We need to have different wp-config files for local development and Elastic BeanStalk. Let's define the local config as local-config.php.

Set up wordpress in your local computer. 

In wp-config, replace the database configs with the following: 

if ( file_exists( dirname( __FILE__ ) . '/local-config.php' ) ) {
    define( 'WP_LOCAL_DEV', true );
    include( dirname( __FILE__ ) . '/local-config.php' );
} else {
    define( 'WP_LOCAL_DEV', false );
    define('WP_HOME','');
    define('WP_SITEURL','');
    define('DB_NAME', 'database');
    define('DB_USER', 'username');
    define('DB_PASSWORD', 'password');
    define('DB_HOST', 'localhost');
}

Fill in the above db_name, db_user, db_password, db_host with the appropriate settings.

Create a file called local-config.php at the same directory as wp-config.php

Put in the following with your local database information.

<?php
    define('WP_HOME','');
    define('WP_SITEURL','');
    define('DB_NAME', '');
    define('DB_USER', '');
    define('DB_PASSWORD', 'root');
    define('DB_HOST', '');


Install AWS ElasticBeanstalk Tools and AWSDevTools

Download  from http://aws.amazon.com/code/6752709412171743

Read this: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/GettingStarted.GetSetup-devtools.html

Check to make sure eb is running properly:

eb --version

Configure your ElasticBeanstalk Git settings:

git aws.config

Reading Credentials from C:\Users\Kenneth\.elasticbeanstalk\aws_credential_file.

The file does not exist.  You can supply credentials by creating the file or editing .elasticbeanstalk/config to reference a different file.
The credential file should have the following format:

AWSAccessKeyId=your key
AWSSecretKey=your secret

AWS Access Key:
AWS Secret Key:
AWS Region [default to us-east-1]: (Check this in your Elastic Beanstalk console)
AWS Elastic Beanstalk Application: <put in the application name you created above>
AWS Elastic Beanstalk Environment: <put in the environment name you created above>

Check if Elastic Beanstalk can detect your app:

eb status --verbose

Now deploy your application:

git aws.push

Remember to use Route53 to map to Elastic Beanstalk.

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customdomains.html

After you point the domain to the Elastic Load Balancer. If the site does not load up in the browser, do not panic. Give it 15 mins. It will be back up.