Skip to content

Commit 5bdaf0b

Browse files
committed
Update readme
1 parent 97945f7 commit 5bdaf0b

File tree

9 files changed

+110
-63
lines changed

9 files changed

+110
-63
lines changed

README.md

Lines changed: 54 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,91 +9,80 @@
99
- Backend in WordPress.
1010
- Front end in React
1111

12-
## [Backend](https://github.com/imranhsayed/nextjs-headless-wordpress/tree/master/backend)
13-
Run this from root
14-
```bash
15-
docker-compose -f backend/docker-compose.yml up -d
16-
```
12+
#Setup
1713

18-
*WordPress Backend* will be available on [http://localhost:8020](http://localhost:8020)
14+
First clone/fork the repo and cd into it.
1915

20-
*[phpMyAdmin](https://github.com/phpmyadmin/phpmyadmin)*: You can access php myadmin on [http://localhost:8183](http://localhost:8183)
21-
```shell script
22-
port: mysql:3306
23-
username: root
24-
password: root
25-
```
16+
```bash
17+
git clone https://github.com/imranhsayed/nextjs-headless-wordpress.git
18+
cd nextjs-headless-wordpress
19+
```
20+
It's very simple to setup the project with just one command and this `./nxtwp configure`
2621

27-
phpmyadmin docker image already comes with the username `root` and we have set the mysql password in the dockerfile
22+
**One command project setup**
2823

29-
* If you happen to use your own WordPress setup, be sure to install and activate plugins from composer.json and add your own WordPress site URL
30-
in an .env file, You can check the .env-example file for reference.
24+
The below command is going to set up the project in the interactive mode.
25+
It creates an .env file for front-end next.js project and setsup up frontend and/or backend.
26+
Run this from the root of the project.
3127

32-
## [Frontend](https://github.com/imranhsayed/nextjs-headless-wordpress/tree/master/frontend)
33-
Run this from root for the first time.
3428
```bash
35-
cd frontend; npm i && npm run dev
29+
./nxtwp configure
3630
```
31+
It's going to ask you a few of questions.
3732

38-
### During development
3933
```bash
40-
cd frontend; npm run dev
34+
Q1. Do you already have a WordPress setup that you want to continue with? [y/n]:
4135
```
36+
*Answer*
4237

43-
Frontend will be available on port [http://localhost:3000](http://localhost:3000)
44-
45-
### Evironment vars.
46-
Create a `.env` file taking reference from `.env-example` inside frontend directory and add your WordPress Site URL ( for local development put `http://localhost:8020` as your WordPress URL)
38+
`y`: If you would like to use this project's WordPress Docker setup ( In which case make sure to install and active all plugins from [backend/plugins-collection])
39+
`n`: If you want to use your own WordPress setup.
4740

48-
## Development ( Developers only )
49-
50-
1. When we change the composer.json, run from root
51-
```shell script
52-
docker-compose -f backend/docker-compose.yml down && \
53-
docker-compose -f backend/docker-compose.yml up -d
54-
```
55-
56-
First line command will stops and removes all the docker containers and second line command will restart all containers.
57-
Notice that `-d` is to run in detach mode and you can always remove that flag, and run the command so you can see the live logs.
58-
Or you can check the logs for
59-
60-
2. Check the logs
61-
While the above command is running in detached mode ( -d ), you can run this command in a new terminal tab to see the live logs.
62-
```shell script
63-
docker logs -f container-name
41+
```bash
42+
Q2. ✍️ What is your WP backend URL? (defaults to http://localhost:8020):
6443
```
44+
Leave it blank if you would like to use this project's WordPress Docker setup,
45+
else enter your own WordPress site URL.
6546

66-
3. Login to SSH and wp cli.
67-
```
68-
docker exec -it image-name bash // e.g. docker exec -it backend_wordpress_1 bash
69-
wp
47+
```bash
48+
✍️ What is your frontend next js URL? (defaults to http://localhost:3000):
7049
```
50+
Leave this blank for development, as it will be the same as default for next.js
7151

72-
e.g.
7352
```bash
74-
docker container ls
53+
✍️ What is your Disqus comments shortname? (leave blank if you are not using):
7554
```
7655
77-
#### result
78-
```shell script
79-
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
80-
d0b4a3b0074f wordpress:latest "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:8000->80/tcp backend_wordpress_1
81-
aad078ebe131 mysql:5.7 "docker-entrypoint.s…" About a minute ago Up About a minute 3306/tcp, 33060/tcp backend_db_1
82-
```
83-
Here container-name is `backend_db_1` or `backend_wordpress_1`
56+
Leave this blank if you are not going to use the Disqus comments, else enter your Disqus comments shortname.
8457
85-
3. If you make changes to docker-compose.yml file, run the following:
58+
That's it!
59+
This is going to automatically:
60+
- Creates the `.env` file in the frontend directory.
61+
- Setup WordPress backend with all the plugins via composer (if you chose y for the first question)
62+
- Install npm packages for next.js frontend and start development server.
8663
87-
If you happend to change the port in `docker-compose.yml` make sure to delete the `db` directory and then run below.
64+
**WordPress Backend** will be available on [http://localhost:8020](http://localhost:8020)
65+
**Next.js Backend** will be available on port [http://localhost:3000](http://localhost:3000)
66+
67+
* Make sure to activate all plugins that it has installed via composer.
68+
* Update block registry by going to WordPress Dashboard > GraphQL Gutenberg.
69+
* For more information checkout the project [Wiki](https://github.com/imranhsayed/nextjs-headless-wordpress/wiki/)
8870
89-
```shell script
90-
docker-compose -f backend/docker-compose.yml down && \
91-
docker-compose -f backend/docker-compose.yml up -d
71+
### During development
72+
73+
Useful commands:
74+
75+
```bash
76+
./nxtwp configure # Sets up backend and frontend and creates an .env file
77+
./nxtwp start-all # Creates and starts docker environment for WP and runs Next JS server
78+
./nxtwp start-backend # Creates and starts docker environment
79+
./nxtwp start-frontend # Installs all packages and Runs Next JS server
80+
./nxtwp stop # Stops the WordPress docker containers
9281
```
9382
9483
## Debugging
9584
96-
1. If you get 404 on frontend for graphql request, check to see that the .htaccess file in wordpress directory has the rules
85+
1. If you get 404 on frontend for graphql request, check to see that the `.htaccess` file in wordpress directory has the rules
9786
9887
```shell script
9988
# BEGIN WordPress
@@ -112,6 +101,12 @@ RewriteRule . /index.php [L]
112101
# END WordPress
113102
```
114103
104+
2. If front-end isn't throwing some other error.
105+
106+
- Check if all the required WordPress plugins form `backend/plugins-collection` are active.
107+
- Ensure you have updated the block registry from WordPress backend > GraphQL Gutenberg
108+
- Ensure that `.env` file has correct env variables and their values in `frontend/.env`
109+
115110
## References for Docker Images.
116111
117112
1. [phpMyAdmin](https://github.com/fuadajip/dockercompose-mysql-phpmyadmin/blob/master/docker-compose.yml)

backend/docker-compose.yml-e

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
version: '3.3'
2+
3+
services:
4+
composer:
5+
image: composer
6+
command: update
7+
volumes:
8+
- ./wordpress:/app
9+
10+
mysql:
11+
image: mysql:5.7
12+
volumes:
13+
- mysql_data:/var/lib/mysql
14+
restart: always
15+
environment:
16+
MYSQL_ROOT_PASSWORD: root
17+
MYSQL_DATABASE: wordpress
18+
MYSQL_USER: wordpress
19+
MYSQL_PASSWORD: wordpress
20+
volumes:
21+
- ./mysql:/var/lib/mysql
22+
23+
phpmyadmin:
24+
image: phpmyadmin/phpmyadmin
25+
depends_on:
26+
- mysql
27+
environment:
28+
PMA_HOST: mysql
29+
PMA_PORT: 3306
30+
PMA_ARBITRARY: 1
31+
restart: always
32+
ports:
33+
- 8183:80
34+
35+
wordpress:
36+
depends_on:
37+
- mysql
38+
- composer
39+
image: wordpress:latest
40+
ports:
41+
- "8020:80"
42+
restart: always
43+
environment:
44+
WORDPRESS_DB_HOST: mysql:3306
45+
WORDPRESS_DB_USER: wordpress
46+
WORDPRESS_DB_PASSWORD: wordpress
47+
WORDPRESS_DB_NAME: wordpress
48+
volumes:
49+
- ./wordpress:/var/www/html
50+
51+
volumes:
52+
mysql_data: {}
Binary file not shown.
3.42 MB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2.5 MB
Binary file not shown.

nxtwp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ BOLD='\033[1m'
1010
# Configureation part of .env file and docker-compose file
1111
function proceed_with_WP_environment() {
1212

13-
# user-input - WP Backend URL
13+
# user-input - WP Backend URL
1414
read -p "$(echo -e $BOLD"✍️ What is your WP backend URL? (defaults to http://localhost:8020): "$NOCOLOR)" WP_backend_url
1515
[ -z "$WP_backend_url" ] && echo -e $YELLOW"⚠️ Using default WP URL"$NOCOLOR && WP_backend_url="http://localhost:8020"
1616
check_url_input $WP_backend_url
@@ -68,7 +68,7 @@ function check_url_input() {
6868
user_input=$1
6969

7070
if ! [[ $user_input =~ $regex ]]
71-
then
71+
then
7272
echo -e $RED"🛑 URL is not valid."$NOCOLOR
7373
echo -e $RED"Example URL is: http://example.com:8000"$NOCOLOR
7474
exit
@@ -106,8 +106,8 @@ function command_help() {
106106

107107
echo "Please pass an argument"
108108
echo "Arguments: [ configure | start-all | start-backend | start-frontend | stop ]"
109-
echo ""
110-
echo "configure Configures WP Url and .env file"
109+
echo ""
110+
echo "configure Sets up backend and frontend and creates an .env file"
111111
echo "start-all Creates and starts docker environment for WP and runs Next JS server"
112112
echo "start-backend Creates and starts docker environment"
113113
echo "start-frontend Runs Next JS server"

0 commit comments

Comments
 (0)