Skip to content

Commit 15fcf31

Browse files
AnouckColsongilzowchadwcarlson
authored
[WordPress] review Anouck (#3891)
* init commit * adds additional files section * adds locations and mounts sections * corrects issue with the header information formatting * final change sections, adds documentation, community content, blogs sections * spelling, grammatical updates/corrections * Review * Fix description and snippets * Update table and apply suggestions. --------- Co-authored-by: Paul Gilzow <[email protected]> Co-authored-by: chadcarlson <[email protected]>
1 parent a264a2c commit 15fcf31

File tree

2 files changed

+277
-1
lines changed

2 files changed

+277
-1
lines changed

sites/upsun/layouts/shortcodes/frameworks-landing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{ $python := "[Django](/get-started/stacks/django.md)<br/>[Flask](/get-started/stacks/flask.md)" }}
2-
{{ $php := "[Symfony](/get-started/stacks/symfony/_index.md)<br/>[Laravel](/get-started/stacks/laravel.md)" }}
2+
{{ $php := "[Laravel](/get-started/stacks/laravel.md)<br/>[Symfony](/get-started/stacks/symfony/_index.md)<br/>[WordPress](/get-started/stacks/wordpress.md)" }}
33
{{ $nodejs := "[Express](/get-started/stacks/express.md)<br/>[Next.js](/get-started/stacks/nextjs.md)<br/>[Strapi](/get-started/stacks/strapi.md)" }}
44

55
<table>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,276 @@
1+
---
2+
title: Deploy WordPress on Upsun
3+
sidebarTitle: WordPress
4+
weight: -55
5+
description: |
6+
Complete the last required steps to successfully deploy WordPress on Upsun.
7+
---
8+
9+
{{< note theme="info" >}}
10+
11+
Before you start, check out the [{{% vendor/name %}} demo app](https://console.upsun.com/projects/create-project)
12+
and the main [Getting started guide](/get-started/here/_index.md).
13+
They provide all the core concepts and common commands you need to know before using the following materials.
14+
15+
{{< /note >}}
16+
17+
For WordPress to successfully deploy and operate, after completing the [Getting started guide](/get-started/here/_index.md),
18+
you still need to add some required files and make a few changes to your Upsun configuration.
19+
20+
## Before you begin
21+
22+
There are many ways you can set up a WordPress site or Upsun project.
23+
The instructions on this page were designed based on the following assumptions:
24+
25+
- You are building a composer-based WordPress site using John P Bloch's [WordPress Composer Fork](https://github.com/johnpbloch/wordpress).
26+
- You do not have a `composer.json` file, or are comfortable making changes to your existing version.
27+
- You selected PHP as your runtime, and MariaDB as a service during the Getting Started guide. It's also assumed that while using the Getting Started guide you named the project `myapp`, which you will notice is the top-level key in all configuration below.
28+
29+
## 1. Add required files
30+
31+
To ensure you have all the required files and directories in your project, follow these steps:
32+
33+
1. Copy the following files from the [Platform.sh WordPress Composer template](https://github.com/platformsh-templates/wordpress-composer/)
34+
and add them to the root of your project:
35+
36+
- The [composer.json](https://raw.githubusercontent.com/platformsh-templates/wordpress-composer/61da65da21039b280b588642cd329a2eb253e472/composer.json) file declares project dependencies and specifies project settings and metadata for [Composer](https://getcomposer.org/) to use
37+
- The [wp-cli.yml](https://github.com/platformsh-templates/wordpress-composer/blob/61da65da21039b280b588642cd329a2eb253e472/wp-cli.yml) file contains the configuration values, related to your site, for the [WordPress CLI](https://wp-cli.org/) to use
38+
- The [wp-config.php](https://github.com/platformsh-templates/wordpress-composer/blob/61da65da21039b280b588642cd329a2eb253e472/wp-config.php) file contains your site's base configuration details, such as database connection information
39+
40+
2. Optional: To support non-public plugins, add a `plugins` directory to your project.
41+
To ensure Git tracks empty folders, add a `plugins/.gitkeep` file as well.
42+
43+
3. Add and commit your changes.
44+
45+
```bash {location="Terminal"}
46+
git add .
47+
git commit -m "Add files and directory"
48+
git push
49+
```
50+
51+
Now that you have pushed all the necessary files and directories to Upsun,
52+
make the following changes to your `./.upsun/config.yaml` file.
53+
54+
## 2. Configure your root location
55+
56+
Locate the `web:locations` section and update the root (`/`) location as follows:
57+
58+
```yaml {location="./.upsun/config.yaml"}
59+
applications:
60+
myapp:
61+
source:
62+
root: "/"
63+
type: 'php:8.3'
64+
web:
65+
locations:
66+
"/":
67+
passthru: "/index.php"
68+
root: "wordpress"
69+
index:
70+
- "index.php"
71+
expires: 600
72+
scripts: true
73+
allow: true
74+
rules:
75+
^/license\.text$:
76+
allow: false
77+
^/readme\.html$:
78+
allow: false
79+
```
80+
81+
{{< note theme="info" >}}
82+
If you're migrating your site, you may already have a `composer.json` file.
83+
You may even have generated your own instead of starting from the Platform.sh template version.</br>
84+
If so, you may also have added a [`wordpress-install-dir` property](https://github.com/johnpbloch/wordpress-core-installer?tab=readme-ov-file#usage) for `extras` in your `composer.json` file.</br>
85+
In this case, set `root:` to the name of the directory where you are installing WordPress.
86+
{{< /note >}}
87+
88+
## 3. Set up a location for uploads
89+
90+
WordPress needs a writable location to store uploaded media.
91+
To set one up, follow these steps:
92+
93+
1. Create the location.</br>
94+
To do so, add a `/wp-content/uploads` location as follows:
95+
96+
```yaml {location="./.upsun/config.yaml"}
97+
applications:
98+
myapp:
99+
source:
100+
root: "/"
101+
type: 'php:8.3'
102+
web:
103+
locations:
104+
"/":
105+
passthru: "/index.php"
106+
root: "wordpress"
107+
index:
108+
- "index.php"
109+
expires: 600
110+
scripts: true
111+
allow: true
112+
rules:
113+
^/license\.text$:
114+
allow: false
115+
^/readme\.html$:
116+
allow: false
117+
"/wp-content/uploads":
118+
root: "wordpress/wp-content/uploads"
119+
scripts: false
120+
allow: false
121+
rules:
122+
'(?<!\-lock)\.(?i:jpe?g|gif|png|svg|bmp|ico|css|js(?:on)?|eot|ttf|woff|woff2|pdf|docx?|xlsx?|pp[st]x?|psd|odt|key|mp[2-5g]|m4[av]|og[gv]|wav|mov|wm[av]|avi|3g[p2])$':
123+
allow: true
124+
expires: 1w
125+
```
126+
2. To make the location writable, set up [a mount](/create-apps/app-reference.md#mounts).</br>
127+
To do so, locate the `mounts:` section that is commented it out, and update it as follows:
128+
129+
```yaml {location="./.upsun/config.yaml"}
130+
applications:
131+
myapp:
132+
source:
133+
root: "/"
134+
type: 'php:8.3'
135+
...
136+
mounts:
137+
"wordpress/wp-content/uploads":
138+
source: storage
139+
source_path: "uploads"
140+
```
141+
142+
{{< note theme="info" >}}
143+
If you have designated a different directory through the `wordpress-install-dir` property in your `composer.json` file, update the
144+
mount location accordingly.
145+
{{< /note >}}
146+
147+
## 4. Install dependencies during the build hook
148+
149+
To ensure your Composer dependencies are installed during the [build stage](/learn/overview/build-deploy.md#the-build),
150+
locate the `build:` section (below the `hooks:` section).</br>
151+
Update the `build:` section as follows:
152+
153+
```yaml {location="./.upsun/config.yaml"}
154+
applications:
155+
myapp:
156+
source:
157+
root: "/"
158+
type: 'php:8.3'
159+
...
160+
hooks:
161+
build: |
162+
set -eux
163+
composer install --prefer-dist --optimize-autoloader --apcu-autoloader --no-progress --no-ansi --no-interaction
164+
rsync -a plugins/ wordpress/wp-content/plugins/
165+
```
166+
167+
You can adjust the `composer install` command to meet your specific requirements.
168+
169+
If you aren't using the `plugins` directory to manage non-public plugins, remove the `rsync` command.
170+
171+
## 5. Launch tasks during the deploy hook
172+
173+
Some tasks need to be performed after the images for our application are built,
174+
but before the newly built application can receive requests.
175+
Therefore, the best time to launch them is during the [deploy hook](/learn/overview/build-deploy.md#deploy-steps).
176+
177+
Such tasks include:
178+
179+
- Flushing the object cache, which might have changed between current production and newly deployed changes
180+
- Running the WordPress database update procedure, in case core is being updated with the newly deployed changes
181+
- Running any due cron jobs
182+
183+
To launch these tasks during the deploy hook,
184+
locate the `deploy:` section (below the `build:` section).</br>
185+
Update the `deploy:` section as follows:
186+
187+
```yaml {location="./.upsun/config.yaml"}
188+
applications:
189+
myapp:
190+
source:
191+
root: "/"
192+
type: 'php:8.3'
193+
...
194+
hooks:
195+
deploy: |
196+
set -eux
197+
# Flushes the object cache
198+
wp cache flush
199+
# Runs the WordPress database update procedure
200+
wp core update-db
201+
# Runs all due cron events
202+
wp cron event run --due-now
203+
```
204+
205+
## 6. Configure your default route
206+
207+
Next, instruct the [router](learn/overview/structure.md#router) how to handle requests to your WordPress app.
208+
To do so, locate the `routes:` section, and beneath it, the `"https://{default}/":` route.
209+
210+
Update the route as follows:
211+
212+
```yaml {location="./.upsun/config.yaml"}
213+
applications:
214+
myapp:
215+
source:
216+
root: "/"
217+
type: 'php:8.3'
218+
...
219+
220+
routes:
221+
"https://{default}/":
222+
type: upstream
223+
upstream: "myapp:http"
224+
cache:
225+
enabled: true
226+
cookies:
227+
- '/^wordpress_*/'
228+
- '/^wp-*/'
229+
```
230+
231+
Matching the application name `myapp` with the `upstream` definition `myapp:http` is the most important setting to ensure at this stage.
232+
If these strings aren't the same, the WordPress deployment will not succeed.
233+
234+
## 7. Update your MariaDB service relationship
235+
236+
You need to update the name used to represent the [relationship](/create-apps/app-reference.md#relationships) between your app and your MariaDB service.
237+
To do so, locate the `relationships:` top-level property.
238+
Update the relationship for the database service as follows:
239+
240+
```yaml {location="./.upsun/config.yaml"}
241+
applications:
242+
myapp:
243+
source:
244+
root: "/"
245+
type: 'php:8.3'
246+
...
247+
relationships:
248+
database: "mariadb:mysql"
249+
```
250+
251+
You can now commit all the changes made to `.upsun/config.yaml` and push to Upsun.
252+
253+
```bash {location="Terminal"}
254+
git add .
255+
git commit -m "Add changes to complete my Upsun configuration"
256+
git push
257+
```
258+
259+
260+
## Further resources
261+
262+
### Documentation
263+
264+
- [PHP documentation](/languages/php/)
265+
- [Authenticated Composer repositories](/languages/php/composer-auth.md)
266+
267+
### Community content
268+
269+
- [PHP topics](https://support.platform.sh/hc/en-us/search?utf8=%E2%9C%93&query=php)
270+
- [WordPress topics](https://support.platform.sh/hc/en-us/search?utf8=%E2%9C%93&query=wordpress)
271+
272+
### Blogs
273+
274+
- [To Upsun, a WordPress migration story](https://upsun.com/blog/to-upsun-a-wordpress-migration-story/)
275+
276+
<!-- ## Video -->

0 commit comments

Comments
 (0)