← All Posts

Deploying WordPress on Leafcloud

Enjoy your own truly green WordPress website!

By Contribution
Published on

create an instance

- Follow the “Getting Started” instructions to create an Ubuntu instance, keypair, security group, and to connect to your instance using SSH. - Create an instance that fits your website’s resource demand. For this example, we will use a small instance (ec1.small with 20GB). Depending on the number of concurrent visitors, this is sufficient for most small/medium websites. - For your Security groups, the ports used by WordPress are 80 & 443 (http & https) - Create a DNS A record to point your domain to your assigned IP, this might take some time and is needed later for SSL/HTTPS Next, we’re going to run through the required steps to prep your new instance. ‍


update your instance

sudo apt update
sudo apt -y upgrade
sudo apt -y dist-upgrade
sudo apt -y autoremove
sudo apt -y autoclean

Download requirements

sudo apt install -y apache2 mysql-server php libapache2-mod-php php-mysql php-curl php-gd php-mbstring php-xml php-xmlrpc php-soap php-intl php-zip

reboot your instance (in case of kernel changes)

sudo reboot

Now ssh back into your instance ‍

Next, we’re going to create an SQL database

set a root password for mysql

sudo mysql

replace “my_supersecure_pwd” with your preferred pasword

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'my_supersecure_pwd';

exit mysql:

exit;

run the secure installation procedure:

sudo mysql_secure_installation

Enter the root password you set before (excluding the ”) ‍ Choose wether you want the ‘VALIDATE PASSWORD COMPONENT’ this is advised, however for this tutorial we choose not to enable it ‍ Choose whether you want to keep or change the root password ‍ Choose 'Y' to remove the anonymous user ‍ Since you are connecting over SSH choose ‘N’ for disallowing remote root login ‍ Choose 'Y' for removing the test database ‍ And a final 'Y' to reload the privilege tables ‍

Login to mysql:

mysql -u root -p

Create a database for your site, replacing ‘MY_WEBSITE’ with your preferred database name

CREATE DATABASE MY_WEBSITE DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;

Create a separate mysql user & user password by replacing “MY_USER” and “MY_PWD”

CREATE USER 'MY_USER'@'%' IDENTIFIED WITH mysql_native_password BY 'MY_PWD';

Grant your new user access to your database, make sure you replace the fields

GRANT ALL ON MY_WEBSITE.* TO 'MY_USER'@'%';

Apply privileges and exit mysql:

FLUSH PRIVILEGES;
exit;

Configure apache2

Enable your site in apache2

a2ensite 000-default

Enable the rewrite module

sudo a2enmod rewrite

Restart apache2

sudo systemctl restart apache2

Download WordPress

Go to your temporary folder ```cd /tmp` `````

Download WordPress

wget https://wordpress.org/latest.tar.gz

Extract the package

tar xzvf latest.tar.gz

Create some files and folders to avoid permission issues later

touch /tmp/wordpress/.htaccess

cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

mkdir /tmp/wordpress/wp-content/upgrade

Copy the wordpress folder to your webroot

sudo cp -a /tmp/wordpress/. /var/www/html

Change ownership of your webroot to the ‘www-data’ user and group

sudo chown -R -v www-data:www-data /var/www/html

Use the WordPress keygen to create some secure keys for your config file by opening the following page in your browser:

https://api.wordpress.org/secret-key/1.1/salt/

Copy these keys & edit the config file

sudo nano /var/www/html/wp-config.php

‍ Scroll down until you find the example keys. Remove the examples and copy your newly generated ones in their place. ‍ Now scroll up until you find the ‘Database settings’ section and fill in the variables you entered earlier in the mysql section of this tutorial ‍

define( 'DB_NAME', 'MY_WEBSITE' );

/* Database username */
define( 'DB_USER', 'MY_USER' );

/* Database password */
define( 'DB_PASSWORD', 'MY_PWD' );

‍ Close the config file with'ctrl+x'followed by'y' and'enter'

Remove the apache2 default index file

sudo rm /var/www/html/index.html

Now finish your WordPress installation

In your browser visit your URL and follow the installation step ‍

Get a certificate

In your SSH session install certbot

sudo snap install --classic certbot

‍ Make sure certbot can work outside it’s snap

sudo ln -s /snap/bin/certbot /usr/bin/certbot

‍ Get a certificate by running this command and following the steps

sudo certbot --apache

Get yourself a drink, sit back, and relax

Your WordPress site is now fully operational and can be reached at https://yourdomain