×
Community Blog Connecting Your WordPress Site to an OSS Bucket

Connecting Your WordPress Site to an OSS Bucket

This article describes how to connect your WordPress site to an Alibaba Cloud OSS bucket.

By Justin Cook and Pablo Puig

Have you ever wondered if it is possible to use the elasticity of the Alibaba Cloud Object Storage Service (OSS) bucket service to place images, videos, and countless other types of static content and attach them to your WordPress site? Fortunately, you can create buckets to place these objects in and utilize them on your WordPress site.

This article will explain how to connect the OSS bucket to your WordPress site and the key features you can utilize within the architecture.

Connecting Your WordPress Site to an OSS Bucket

The following step-by-step guide explains how to connect your WordPress site to an OSS bucket.

Migrating Static Resources to OSS

  • Step 1: Log in to your Alibaba Cloud account, go to the OSS console, and click on Create Bucket:

1

  • Step 2: Enter a Bucket Name and select the Region where you want to store your files. Then, select the Standard Storage Class and Enable Versioning.

Note: Storage Class and Region cannot be changed after the bucket is created.

2

  • Step 3: Set your Access Control List (ACL) to Private, select your preferred Encryption Method, and whether you would like to have Real-time Log Query logs. For this demo, I will not select any Encryption Method and will Disable the Real-time Log Query. Then, click OK:

3

  • Step 4: Now, your OSS bucket is already created, and it is time to upload the files. Go to the Files section and click Upload:

4

  • Step 5: Select the File ACL you want. I recommend selecting Inherited from Bucket to stay consistent. Then, drag and drop your files or click on Select Files. Once you select all the files, click Upload.

Note: Uploading files to OSS is free of charge. You only pay for storing the files:

5

Getting the OSS Bucket Domain Name

Once you have finished uploading the resources, you need to copy the OSS bucket domain name for future steps.

Go to your OSS bucket. Under Overview, you will find your OSS bucket domain name under Domain Names:

6

Creating RAM Access Keys

  • Step 1: Log in to your Alibaba Cloud account and go to the RAM console.
  • Step 2: Go to the Identities section, click the Users tab, and click on Create User:

7

  • Step 3: Enter the Login Name and the Display Name. Then, select the Open API Access as your preferred Access Mode and click OK:

8

  • Step 4: Copy the AccessKey ID and the AccessKey Secret. Alternatively, you can download them as a CSV file.

Note: The AccessKey pairs are displayed only once. You must immediately save the AccessKey ID and the AccessKey Secret:

9

  • Step 5: After creating the Access Keys, you need to add permissions to the user by clicking Add Permissions:

10

  • Step 6: Select the AliyunOSSFullAccess policy provided by Alibaba Cloud under Select Policy and click OK:

11

  • Step 7: Review the permissions and click Complete:

12

Connecting to Your WordPress Site

You have already created the OSS bucket and the RAM Access Keys. Now, it is time to connect to your WordPress instance and configure your WordPress site to use OSS as the default storage.

Note: For this guide, we assume that you are using an Elastic Compute Service (ECS) instance to host your WordPress site.

  • Step 1: Log in to your Alibaba Cloud account and go to the ECS console.
  • Step 2: Select your ECS instance and click on Connect:

13

  • Step 3: Once you have entered your password and connect to your ECS instance, move the content from /data/wwwroot/default/ onto OSS with the following commands:
$ cd /data/wwwroot/default/
$ mv wp-content local-wp-content
  • Step 4: Now, download the gdebi-core by running the following commands:
$ sudo apt-get update
$ sudo apt-get install gdebi-core
$ sudo wget https://github.com/aliyun/ossfs/releases/download/v1.80.4/ossfs_1.80.4_ubuntu14.04_amd64.deb
$ sudo gdebi ossfs_1.80.4_ubuntu14.04_amd64.deb
  • Step 5: Once installed, use the OSS bucket name and RAM AccessKeys created previously and mount the bucket to the wp-content directory by running the following commands:
$ sudo –u www echo BUCKET_NAME:ACCESSKEY_ID:ACCESSKEY_SECRET > /etc/passwd-ossfs
$ chown www:www /etc/passwd-ossfs
$ chmod 640 /etc/passwd-ossfs
$ sudo -u www mkdir /data/wwwroot/default/wp-content
$ sudo -u www ossfs BUCKET_NAME /data/wwwroot/default/wp-content -ourl= OSS_INTERNAL_ADDRESS
$ sudo -u www cp -r local-wp-content/* wp-content
  • Step 6: You also need to mount the OSS bucket at boot so you don't have to do this process every time. To do so, we will set up our bootscript in /etc/init/ by running the following commands:
$ cat > /etc/init/wordpress-oss.conf
description "Mount WordPress OSS" start on startup
script
sudo -u www ossfs BUCKET_NAME /data/wwwroot/default/wp-content -ourl=OSS_INTERNAL_DOMAIN_NAME
end script
  • Step 7: The last step is to try it out by running the start command:
$ sudo service wordpress-oss start
wordpress-oss start/running, process 2000
2 1 0
Share on

Alibaba Cloud Community

1,029 posts | 252 followers

You may also like

Comments

JustinCook September 21, 2021 at 3:15 pm

Thanks again for everyone for making this possible!

JustinCook September 21, 2021 at 3:15 pm

Thanks again for everyone for making this possible!

Alibaba Cloud Community

1,029 posts | 252 followers

Related Products