07 Dec 2016
I’m migrating my blog and a few other stuff I have running to Amazon infrastructure. I needed an Amazon EC2 instance with PHP support and able to connect to a MySQL.
Steps:
yum update
yum install nginx
yum install php70 php70-fpm php70-mysqlnd
Edit /etc/nginx/conf.d/virtual.conf
server {
listen 3000 ;
location / {
root /var/www/ ;
index index.php index.html index.htm ;
}
location ~ \.php$ {
root /var/www/ ;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock ;
fastcgi_index index.php ;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name ;
include fastcgi_params ;
}
}
Edit the following properties of: /etc/php-fpm-7.0.d/www.conf
user = nginx
group = nginx
listen = /var/run/php-fpm/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
Create a php file on /var/www/
<?php
phpinfo ();
?>
Access http://SERVER_IP:3000
You will need your security group for your ec2 instance to have port 3000 opened.
If you want to add them to auto start:
sudo chkconfig nginx on
sudo chkconfig php-fpm on
If you want to restart this services:
sudo service nginx restart
sudo service php-fpm restart
Matheus
Comment
03 Dec 2016
After a few good years with my blog out of date, I decided to start to write again and to migrate it to Heroku since his server was with a really old stack. I decided to use Heroku, Amazon RDS as Database service and S3 as file storage (for uploaded files)
Steps:
Disable all Wordpress’ extensions
Do a full backup (Wordpress, Database, Uploads, etc)
Really, do a backup!
Create a git repository
Add Wordpress code to your git
If you want to update your Wordpress add latest Wordpress version
Don’t add your private configs (wp-config.php)!
Don’t add uploads folder
Add your plugins
Add your theme
If you want to keep your Wordpress version, add your current blog’s code
Don’t add your private configs (wp-config.php)!
Don’t add uploads folder
Atention with your private files!!
Update your wp-config
All your private configs must use getenv, this function will be responsible to fetch the values from env vars.
<?php
define ( 'AUTH_KEY' , getenv ( 'WP_AUTH_KEY' ));
define ( 'SECURE_AUTH_KEY' , getenv ( 'WP_SECURE_AUTH_KEY' ));
define ( 'LOGGED_IN_KEY' , getenv ( 'WP_LOGGED_IN_KEY' ));
define ( 'NONCE_KEY' , getenv ( 'WP_NONCE_KEY' ));
define ( 'AUTH_SALT' , getenv ( 'WP_AUTH_SALT' ));
define ( 'SECURE_AUTH_SALT' , getenv ( 'WP_SECURE_AUTH_SALT' ));
define ( 'LOGGED_IN_SALT' , getenv ( 'WP_LOGGED_IN_SALT' ));
define ( 'NONCE_SALT' , getenv ( 'WP_NONCE_SALT' ));
define ( 'S3_UPLOADS_BUCKET' , getenv ( 'AWS_S3_BUCKET' ));
define ( 'S3_UPLOADS_KEY' , getenv ( 'AWS_S3_KEY' ));
define ( 'S3_UPLOADS_SECRET' , getenv ( 'AWS_S3_SECRET' ));
define ( 'S3_UPLOADS_REGION' , getenv ( 'AWS_S3_REGION' ));
Create a composer.json file to define requirements and packages versions
Exemple composer.json
{
"require" : {
"php" : ">=7.0.0"
},
"require-dev" : {
}
}
Execute composer update
to generate the composer.lock file
Update your .htaccess file to redirect your uploads to your S3 bucket
Update the url (at the 5th line) on the .htaccess to match your S3 and Bucket
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^wp-content/uploads/(.*)$ https://s3-us-west-2.amazonaws.com/BUCKET/uploads/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Do a commit with all this files (don’t add your secrets/keys to your git)
Amazon setup
Create a RDS Database
Import your backup into it
Send your S3 files to S3
Remember to import/change the permissions of your s3 files so guest users can access your uploaded files
Heroku setup
Add your environment vars on heroku with the correct values and names which you used on wp-config.php
, remember to use the RDS ones for database.
Update your DNS for Heroku
Send your code to Heroku using the repository you have created
Access your website
If you’re updating your Wordpress, there are chances to something go wrong or to some plugin to stop working with the new Wordpress version, so don’t forget to check and update them.
Also, if you have any other question or need more information a specific test, let me know. I can try to help.
Matheus
Comment