Skip to content

Instantly share code, notes, and snippets.

@thinhhung
Last active February 12, 2018 04:37
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinhhung/916d9aca787b96ecb10b3baaaa3c1ce5 to your computer and use it in GitHub Desktop.
Save thinhhung/916d9aca787b96ecb10b3baaaa3c1ce5 to your computer and use it in GitHub Desktop.
Amazon Linux Nginx PHP 7 - RDS

Install linux update

sudo yum update -y

Install PHP 7

sudo rpm -Uvh https://mirror.webtatic.com/yum/el6/latest.rpm

sudo yum install --enablerepo=webtatic-testing php70w php70w-devel php70w-fpm php70w-mysqlnd php70w-mbstring php70w-pdo php70w-mcrypt php70w-xml

Note: use php70w-mysqlnd instead php70w-mysql

Install Mysql

sudo yum -y install mysql-server sudo service mysqld start

Install Nginx

sudo yum install nginx

Install Git

sudo yum install git

Install Composer

curl -sS https://getcomposer.org/installer | php

chmod +x composer.phar

mv composer.phar /usr/local/bin/composer

Config Configuration

sudo vi /etc/nginx/nginx.conf

PHP-FPM Configuration

sudo vi /etc/php-fpm.d/www.conf

Start Nginx, PHP-FPM

sudo /etc/init.d/nginx start

sudo /etc/init.d/php-fpm start

Autostart Nginx, PHP-FPM, MySQLD

sudo chkconfig nginx on

sudo chkconfig php-fpm on

sudo chkconfig mysqld on

Generate SSH key

ssh-keygen -t rsa -C "your_email@example.com"

pbcopy < ~/.ssh/id_rsa.pub

Add ssh key to authorized_keys

ssh -T git@bitbucket.org

PHP configuration

sudo vi /etc/php.ini

...
...
index index.html index.htm index.php;
...
...
root /var/www/site/current/public;
sendfile off;
client_max_body_size 16G;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
try_files $uri = 404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 3000;
}
...
...
user = ec2-user
group = ec2-user
...
...
'connections' => [
'production' => [
'host' => 'ec2-xxx.xxx.xxx.xxx.ap-northeast-1.compute.amazonaws.com',
'username' => 'user_name',
'password' => '',
'key' => '.rocketeer/id_rsa',
'keyphrase' => '',
'agent' => '',
'db_role' => true,
],
],
// The root directory where your applications will be deployed
// This path *needs* to start at the root, ie. start with a /
'root_directory' => '/var/www/',
// The folder the application will be cloned in
// Leave empty to use `application_name` as your folder name
'app_directory' => 'app_name',
// The SCM used (supported: "git", "svn")
'scm' => 'git',
// The SSH/HTTPS address to your repository
// Example: https://github.com/vendor/website.git
'repository' => 'git@github.com:user/project.git',
// The repository credentials : you can leave those empty
// if you're using SSH or if your repository is public
// In other cases you can leave this empty too, and you will
// be prompted for the credentials on deploy. If you don't want
// to be prompted (public repo, etc) set the values to null
'username' => 'user@mail.com',
'password' => 'password',
#!/bin/sh
set -ex
export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
export AWS_DEFAULT_REGION="ap-northeast-1"
export APP_ROOT=""
MYSECURITYGROUP="sg-828d31e7"
MYIP=`curl -s ifconfig.me`
aws ec2 authorize-security-group-ingress --group-id $MYSECURITYGROUP --protocol tcp --port 22 --cidr $MYIP/32
cd $APP_ROOT
rocketeer deploy
aws ec2 revoke-security-group-ingress --group-id $MYSECURITYGROUP --protocol tcp --port 22 --cidr $MYIP/32
// Tasks to execute after the core Rocketeer Tasks
'after' => [
'setup' => [],
'deploy' => [
'cp .env.production .env',
],
'cleanup' => [],
],
memory_limit = 50G
upload_max_filesize = 1G
post_max_size = 4G
max_execution_time = 259200
max_input_time = 259200
@riccardotreagles
Copy link

I follow your steps, but I obtain "Error 502 Bad gateway"
What are the possible causes?
How I can figure it out?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment