Old Homepage - sosroInSpace/wordpress_wiki GitHub Wiki
Creating New Wordpress Site
- Sign in to the AWS Console
- Go to Services -> EC2.
- Click Launch Instance.
- Under Step 1 (Choose AMI), go AWS Marketplace and select WordPress Certified by Bitnami.
- Under Step 2 (Choose Instance Type), select t3.micro for the instance type.
- Under Step 3 (Configure Instance), make sure the default VPC is selected ("VPC 1"). Also Uncheck T2/T3 Unlimited.
- Under Step 6 (Configure Security Groups), select "Select an existing security group" and pick the groups WordpressPublic and DeveloperSSH.
- All other settings should be automatically filled correctly by Bitnami.
- Click Launch and select Create a new key pair, and give the key pair a name like "company-name".
- Download the key, and save it somewhere on your machine. It is suggested to save all keys to ~/.ssh/
- Secure MY_KEY.pem with
openssl rsa -aes256 -in MY_KEY.pem -out MY_KEY_ENCRYPTED.pem. - Run
chmod 400 MY_KEY_ENCRYPTED.pemto stop a SSH security warning when attempting to SSH.
Setting Up New Wordpress Site Boiler Plate
-
Once a new instance with a fresh Wordpress install has been created install OKMG's Boilerplate Theme.
-
Download "wp-content.zip" via - https://www.dropbox.com/s/g8zzs9m7cftlxdj/wp-content.zip?dl=0
-
Download "ACF-export.json" via - https://www.dropbox.com/s/fikpvn4zb5rwtbi/acf-export-2018-10-23.json?dl=0
- wp-content.zip (contains OKMG boilerplate theme and all associated plugins required to build on) - ACF-export.json (contains boilerplate importable custom fields) -
**SFTP / SSH ** into the new Wordpress instance and replace the current "wp-content" with the version downloaded through drop-box.
-
Login to your Wordpress admin area and activate Advanced Custom Fields plugin as a minimum and any others needed.
-
Once Custom Fields have been activated a widget will appear within the left Wordpress panel. Navigate to ACF > tools > import advanced custom fields > import "ACF-export.json".
-
Done! your new Wordpress Boilerplate has been created.
Notes
-
Advanced Custom Fields allows you to create custom reusable components for Wordpress. These components can be found once connected through SFTP within: wp-content > themes > OKMG > flexible_content > templates.
-
If a new component is created and you think it will be beneficial within OKMG's Boilerplate Wordpress Theme please save and update "wp-content" within the associated dropbox account.
-
Once a new component is created the corresponding stylesheet will need to be saved within "flexible_content/css" this stylesheet will need to be referenced through the boilerplates functions.php file. Each stylesheet will need to be added at the bottom of functions.php - e.g.
function enqueue_style() {
wp_enqueue_style( 'main-style', get_template_directory_uri() . '/custom-style.css', null, time() );
wp_enqueue_style( 'sub-style', get_template_directory_uri() . '/flexible_content/css/sub-style.css', null, time() );
}
add_action( 'wp_enqueue_scripts', 'enqueue_style' );
SSH Config
The following steps can be taken to make SSH-ing into the Wordpress instance easier. In the command-line:
cd ~/.ssh/nano config- Copy + Paste the following to the bottom of the file:
Host SOME_NAME
Hostname IP_ADDRESS
User bitnami
IdentityFile ~/.ssh/SSH_KEY_FILE_HERE
Ctrl + Oto save.Ctrl + Xto quit.
Now, if you type ssh SOME_NAME, it will attempt to SSH into the given IP_ADDRESS using the details above.
Install RSUB
Copy the following into the command line once you have SSH'd into the server.
- (sudo) wget -O /usr/local/bin/rsub \https://raw.github.com/aurora/rmate/master/rmate
- (sudo) chmod a+x /usr/local/bin/rsub
Bitnami Creating User
Bitnami's Wordpress comes with a default username and password (seen in the system logs for the EC2 instance), but these cannot be used anywhere. A new user should be created from scratch:
- SSH into the server with
ssh SOME_NAME. - Go to the wp-content directory with
cd ~/apps/wordpress/htdocs/wp-content/. - Start a file with
mkdir mu-plugins,cd mu-plugins,nano create-admin-user.php. - Copy in the following code, then use
Ctrl + Oto save, andCtrl + Xto quit:
<?php
add_action( 'init', function () {
$username = 'temp_user';
$password = 'testpassword123';
$email_address = '[email protected]';
if ( ! username_exists( $username ) ) {
$user_id = wp_create_user( $username, $password, $email_address );
$user = new WP_User( $user_id );
$user->set_role( 'administrator' );
}
} );
- With the command line still open, login to Wordpress with the credentials above at
http://SITE_IP/admin. - Set a new password for the existing user, "user".
- Logout of Wordpress.
- In the command line, exit the mu-plugins folder with
cd .., then delete it withrm -rf mu-plugins. This folder should only be temporary as it runs it's contents whenever the site is visited. - Login as "user" to see if it worked.
- Delete old user "temp_user".
Bitnami upload permissions with SFTP
Sometimes you may want to upload files to a theme folder, but cannot due to permissions. This is likely caused by ownership of the installed theme directory, which is set to daemon:daemon when downloaded and installed via Wordpress. With the SFTP client, the user bitnami is used, so to allow uploading:
- SSH into the server with
ssh SOME_NAME. - Go to the themes directory with
cd apps/wordpress/htdocs/wp-content/themes. - Run
sudo chown -R bitnami:daemon THEME_DIR. Uploading to this directory should now work. - Run
ls -lto check if THEME_DIR directory now hasbitnami daemon.
Bitnami sendmail fix
The Bitnami instance may not be able to send emails, or may send them very slow (~ 1 minute). The following steps will fix this issue, and were based on the information seen in:
Note that amazon limits the number of emails to 2000 per day. It is recommended that an external SMTP provider be used for emails.
- SSH into the instance with
ssh SOME_NAME. - run
sudo apt-get install sendmail - if
sudo apt-get install sendmailhangs onSSL certificatereference the documentation found within these links: https://askubuntu.com/questions/937666/ubuntu-16-04-command-line-sendmail-installation-hanged https://askubuntu.com/questions/1109982/e-could-not-get-lock-var-lib-dpkg-lock-frontend-open-11-resource-temporari - run
sudo nano /etc/hostsand insert the textlocalhost localhost.localdomainbetween the line127.0.0.1 ip-XXX-XXX-XXX-XXXto make it look like the line below. UseCtrl + Oto save, andCtrl + Xto quit.
127.0.0.1 localhost localhost.localdomain ip-XXX-XXX-XXX-XXX
- run
sudo sendmailconfigand answer 'Y' to everything. - run
nano /opt/bitnami/php/etc/php.iniand search for the word "sendmail" usingCtrl + O. - Uncomment the line
sendmail_path = "env -i /usr/sbin/sendmail -t -i"by removing the;at the start (or add the line if it doesn't exist). - Use
Ctrl + Oto save, andCtrl + Xto quit. - Restart bitnami service by running
sudo service bitnami restart. This may take around 30 seconds.
The emails should be fixed now.
Bitnami remove corner banner
The corner banner can be removed with the following steps, based on:
- SSH into the instance with
ssh SOME_NAME. - run
sudo /opt/bitnami/apps/wordpress/bnconfig --disable_banner 1 - run
sudo /opt/bitnami/ctlscript.sh restart apache
The corner banner that appears on first visit should be gone now.
Bitnami allow HTTPS (once domain name is owned).
NOTE: This guide may need to be updated, as lego has changed a bit.
The following steps can be taken to allow HTTPS through getting an SSL certificate from LetsEncrypt.
- SSH into the instance with
ssh SOME_NAME. - Install the Lego client using the following 4 commands:
cd /tmp
curl -L -s https://api.github.com/repos/xenolf/lego/releases/latest | grep browser_download_url | grep linux_amd64 | cut -d '"' -f 4 | wget -i -
tar xf {downloaded_lego_file}.tar.gz
sudo mv lego /usr/local/bin/lego
- Generate the SSL certificate with the following commands. Make sure to replace "DOMAIN-ONE" with your base domain name (Eg.
example.com), and add an entry for every subdomain needed (www.example.com,shop.example.com, etc):
sudo /opt/bitnami/ctlscript.sh stop
sudo lego --email="EMAIL-ADDRESS" --domains="DOMAIN-ONE" --domains="DOMAIN-TWO" --path="/etc/lego" --http run
- Move the old SSH certificates somewhere else, and link in the new ones with the following commands. Make sure to change "DOMAIN-ONE" to the correct name of the files ( make sure the generated certificates are within the correct folder path before doing this! ):
sudo mv /opt/bitnami/apache2/conf/server.crt /opt/bitnami/apache2/conf/server.crt.old
sudo mv /opt/bitnami/apache2/conf/server.key /opt/bitnami/apache2/conf/server.key.old
sudo mv /opt/bitnami/apache2/conf/server.csr /opt/bitnami/apache2/conf/server.csr.old
sudo ln -s /etc/lego/certificates/DOMAIN-ONE.key /opt/bitnami/apache2/conf/server.key
sudo ln -s /etc/lego/certificates/DOMAIN-ONE.crt /opt/bitnami/apache2/conf/server.crt
sudo chown root:root /opt/bitnami/apache2/conf/server*
sudo chmod 600 /opt/bitnami/apache2/conf/server*
- Start all services again with
sudo /opt/bitnami/ctlscript.sh start
Connect to the website now to check if HTTPS is correctly being used. No further configuration should be needed as the certificates are, by default, listed in /opt/bitnami/apache2/conf/bitnami/bitnami.conf.
Auto-Renewal
- Create a new file with
sudo nano /etc/lego/renew-certificate.sh. - Paste in the following, and use
Ctrl + Oto save. The middle part should have the same information as step 3 above:
#!/bin/bash
sudo /opt/bitnami/ctlscript.sh stop apache
sudo /usr/local/bin/lego --email="EMAIL-ADDRESS" --domains="DOMAIN-ONE" --domains="DOMAIN-TWO" --path="/etc/lego" --http renew
sudo /opt/bitnami/ctlscript.sh start apache
- Make the script executable with
sudo chmod +x /etc/lego/renew-certificate.sh - Open the crontab with
sudo crontab -e - Add the line
0 0 * * 0 /etc/lego/renew-certificate.sh 2> /dev/nulland save withCtrl + O(if using nano). This will add a weekly cron job that runs on Sunday 12:00 am.
Force HTTPS
Forcing the browser to user HTTPS is both secure and good for SEO. The following steps can be used to force HTTPS.
- Open config file with
nano /opt/bitnami/apache2/conf/bitnami/bitnami.conf. - Add the following lines directly below the top of the default host,
<VirtualHost _default_:80>, and save withCtrl + O:
DocumentRoot "/opt/bitnami/apache2/htdocs"
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
- Restart apache with
sudo /opt/bitnami/ctlscript.sh restart apache
Force www to non-www
Forcing the browser to use one domain name is good for SEO. The following steps can be used to force none-www e.g.('https://mydomain.com').
- Open config file with
nano /opt/bitnami/apps/wordpress/conf/httpd-app.conf. - Add the following lines at the top just after -
RewriteEngine On:
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]
(if you have run SSL https script)
- Open config with sudo nano /opt/bitnami/apache2/conf/bitnami/bitnami.conf
- Comment out rewrite rules by adding a # to the beginning of lines 18-21 and lines 60-63 (end)
- Restart apache with
sudo /opt/bitnami/ctlscript.sh restart apache
Bitnami import MySQL database (optional for migrations).
- Get database dump with
mysqldump -u root -p DB_NAME > PATH_TO_DB_FILE.sql - Upload the database.sql file via SFTP.
- SSH into the instance.
- Find out the password for the root user (in ec2 management, select instance, Actions -> Instance Settings -> Get System Log).
- Run
mysql -u root -p DB_NAME < PATH_TO_DB_FILE.sql, where DB_NAME is the name of the DB to import to (usually bitnami_wordpress). - Enter the password from Step 3.
Logging into phpMyAdmin from the browser
- Run
ssh -N -L 8888:127.0.0.1:80 SOME_NAME. If successful, will appear frozen (leave open for the duration of phpMyAdmin). - Go to
http://localhost:8888/phpmyadmin/and login withrootandpasswordbelow. - Password is found on
AWS -> EC2 -> Actions -> Instance Settings -> Get System Log -> (Scroll down to find Password).
Setting up SMTP with AWS
REVO FITNESS NOTE: Please follow up to step 3, then click 'Retry' for the revo domain. All the rest has been done, and credentials are available in a previous email.
- Login to AWS and find Simple Email Service.
- Switch region to EU (Ireland).
- Go to Domains, and retry an existing domain or click Verify a New Domain.
- Give the domain an unused subdomain name, like "mail.companyName.com.au"
- Follow the verification instructions on the domain.
- On the left, click SMTP Settings.
- Click Create My SMTP Credentials.
- Set the username to something like "companyName-SMTP".
- Save the credentials of the new user somewhere! Maybe in an email to
[email protected]. - Use these credentials with the SMTP Plugin for Wordpress.
- SMTP will become active once the domain name has been verified on AWS.
Finding out the root password for MySQL
- Look in AWS -> EC2 -> Instance -> Actions -> Instance Settings -> Get System Log
- Scroll down and find the password.
- If the password cannot be found, it will have to be reset using the following Binami Guide, "Reset The MySQL Root Password". Note: The Bitnami instances usually ship with 5.7.22
Setting up a remote database
- SSH into the instance.
- run
mysql -u root -pto connect to the database. - create an empty database with
CREATE DATABASE bitnami_dev;. - Create a new user to use remotely with
CREATE USER 'bn_dev'@'127.0.0.1' IDENTIFIED BY 'random_password_here';. Please don't use the usual password! Use a made-up one likeM2on7Hdkem4and write it down somewhere. - Grant bn_dev full permission on bitnami_dev with
GRANT ALL PRIVILEGES ON bitnami_dev.* TO 'bn_dev'@'127.0.0.1';. - Exit mysql with
exit. - Go to the home directory by running
cd. - Clone the bitnami_wordpress to a local file with
mysqldump -u root -p bitnami_wordpress > temp.sql. - Import the local file to bitnami_dev with
mysql -u root -p bitnami_dev < temp.sql.
Connecting to the remote database with local instance
- Change your
wp-config.phpconfig to:
/** The name of the database for WordPress */
define('DB_NAME', 'bitnami_dev');
/** MySQL database username */
define('DB_USER', 'bn_dev');
/** MySQL database password */
define('DB_PASSWORD', 'random_password_here');
/** MySQL hostname */
define('DB_HOST', '127.0.0.1:8888');
- Create an SSH tunnel with
ssh -N -L 8888:127.0.0.1:3306 SERVER_NAME. - Run wordpress locally. It should work!
Multisite setup.
Please see the following Bitnami Guide on how to do this.