New project structure init
This commit is contained in:
192
README.md
192
README.md
@@ -1,34 +1,174 @@
|
||||
# Place for wiaas based on woo commerce
|
||||
# New Wiaas
|
||||
|
||||
Wiaas implementation based on wordpress [woocommerce](https://woocommerce.com/) plugin.
|
||||
|
||||
## Dependencies
|
||||
|
||||
- PHP (7.0)
|
||||
- MySQL server (5.7)
|
||||
- [Composer](http://getcomposer.org)
|
||||
- [WP CLI](https://wp-cli.org/#installing)
|
||||
- NodeJS (for building & developing frontend)
|
||||
|
||||
## Local Docker setup
|
||||
|
||||
1) Copy environment.env file and rename it to .env
|
||||
|
||||
```
|
||||
cp environment.env .env
|
||||
```
|
||||
|
||||
2) Edit .env file and add needed information
|
||||
* `MYSQL_ROOT_PASSWORD` - MySQL database root password for MySQL docker image
|
||||
* `MYSQL_DATABASE` - Wordpress database name
|
||||
* `MYSQL_USER` - Wordpress database user
|
||||
* `MYSQL_PASSWORD` - Wordpress database password
|
||||
* `MYSQL_HOST` - Wordpress database host (will be `db` for docker)
|
||||
* `WP_ENV` - Set to environment (`local`, `development`, `production`)
|
||||
* `API_URL` - Full URL to WordPress home (http://localhost:8081 if you are testing locally)
|
||||
* `WP_AUTH_KEY`, `WP_SECURE_AUTH_KEY`, `WP_LOGGED_IN_KEY`, `WP_NONCE_KEY`, `WP_AUTH_SALT`, `WP_SECURE_AUTH_SALT`, `WP_LOGGED_IN_SALT`, `WP_NONCE_SALT`, `WP_JWT_AUTH_SECRET_KEY`
|
||||
|
||||
3) Execute in the root of the project :
|
||||
|
||||
```sh
|
||||
sudo docker-compose build
|
||||
sudo docker-compose up
|
||||
```
|
||||
|
||||
Frontend is running on http://localhost:8080 and backend on http://localhost:8081
|
||||
|
||||
|
||||
#How to run
|
||||
|
||||
1) copy environment.env file and rename it to .env
|
||||
|
||||
2) edit .env file (it is sufficent to change API_URL to http://localhost:8081 if you are testing locally)
|
||||
(on test server, this value is API_URL=http://next.wiaas.saburly.com/api)
|
||||
|
||||
3) execute in the root of the project :
|
||||
|
||||
sudo docker-compose build
|
||||
sudo docker-compose up
|
||||
|
||||
now, frontend is running on http://localhost:8080 and backend on http://localhost:8081
|
||||
|
||||
## Local development setup
|
||||
|
||||
|
||||
#Credentials
|
||||
### DB setup
|
||||
|
||||
wordpress credentials : (wp-admin)
|
||||
user : wpUser
|
||||
password : Test987!
|
||||
1) Create MYSQL database / user
|
||||
|
||||
wooCommerce API key :
|
||||
consumer key : ck_1ee57854e327639d33ca072073499d4adaf9d8f4
|
||||
consumer secret : cs_e51bf71b6ce05fe9a0d17d3e4f249c2b6ec8cbd5
|
||||
```sql
|
||||
CREATE DATABASE ${MYSQL_DATABASE};
|
||||
CREATE USER '${MYSQL_USER}'@'localhost' IDENTIFIED BY '${MYSQL_PASSWORD}';
|
||||
GRANT ALL PRIVILEGES ON ${MYSQL_DATABASE}.* TO '${MYSQL_USER}'@localhost;
|
||||
```
|
||||
|
||||
(use bacic Auth, consumer key is user name, consumer secret is password)
|
||||
2) Seed database with `new-wiaas/database/clean-dump.sql`
|
||||
|
||||
mysql :
|
||||
user : wp_admin
|
||||
password : wp_password
|
||||
database : wordpress
|
||||
### Backend setup
|
||||
|
||||
1) Environment variables
|
||||
|
||||
For handling environment variables during local development we use `dotenv` library which will load all variables from `local.env` file
|
||||
if such file is present. These variables will then be accessible inside wordpress.
|
||||
|
||||
```
|
||||
cp environment.env local.env
|
||||
```
|
||||
Update `local.env` with your local environment variables.
|
||||
|
||||
2) Apache
|
||||
|
||||
Point your apache server to `new-wiaas/backend` by updating apache default host files to point to it.
|
||||
(do not copy folder content to `/var/www/html`, since then dotenv will not be able to load `local.env` file since it is placed one folder above.)
|
||||
|
||||
3) Wordpress
|
||||
|
||||
Run setup commands to install wordpress and required plugins with composer:
|
||||
|
||||
```sh
|
||||
cd backend
|
||||
composer install
|
||||
composer update-db
|
||||
```
|
||||
|
||||
|
||||
|
||||
### Frondend setup
|
||||
|
||||
1) Install dependencies
|
||||
|
||||
```sh
|
||||
cd frontend
|
||||
npm install
|
||||
```
|
||||
2) Start local server
|
||||
```sh
|
||||
cd frontend
|
||||
npm start
|
||||
```
|
||||
|
||||
## Contribution
|
||||
|
||||
### Backend
|
||||
|
||||
- Project structure
|
||||
|
||||
Project structure is inspired with [Roots Bedrock structure](https://roots.io/bedrock/).
|
||||
|
||||
```
|
||||
├── composer.json # → Manage versions of WordPress, plugins & dependencies
|
||||
├── config # → WordPress configuration files
|
||||
│ ├── application.php # → Primary WP config file (wp-config.php equivalent)
|
||||
│ └── environments # → Environment specific configs
|
||||
│ ├── development.php # → Development config
|
||||
│ ├── local.php # → Local config
|
||||
│ └── production.php # → Production config
|
||||
├── vendor # → Composer packages (never edit)
|
||||
├── app # → wp-content equivalent
|
||||
│ ├── mu-plugins # → Must use plugins
|
||||
│ ├── plugins # → Plugins
|
||||
├── wiaas # → Our code goes here
|
||||
│ ├── themes # → Themes
|
||||
│ └── uploads # → Uploads
|
||||
├── wp-config.php # → Required by WP (never edit)
|
||||
├── index.php # → WordPress view bootstrapper
|
||||
└── wp # → WordPress core (never edit)
|
||||
```
|
||||
|
||||
This approach enables:
|
||||
- Better folder structure (wordpress core is in separate folder and is treated as dependency)
|
||||
- Dependency management with Composer (wordpress core and plugins)
|
||||
- Easy WordPress configuration with environment specific files
|
||||
- Environment variables with [Dotenv](https://github.com/vlucas/phpdotenv)
|
||||
- Enhanced security (all sensitive information is accessed with environment variables)
|
||||
- Secure passwords with [wp-password-bcrypt](https://github.com/roots/wp-password-bcrypt)
|
||||
- Composer as task runner for automatic wordpress db updates
|
||||
|
||||
- Dependencies management
|
||||
|
||||
Wordpress core (`"johnpbloch/wordpress"`) and wordpress plugins code are managed with `composer.json` file.
|
||||
|
||||
But using combination of [Composer scripts](https://getcomposer.org/doc/articles/scripts.md) and [WP CLI commands](https://developer.wordpress.org/cli/commands/)
|
||||
we can automate database updates as well (mainly plugin activation and db updates after plugin version change);
|
||||
|
||||
For adding new plugin from wordpress official repo add `"wpackagist-plugin/{plugin_name}": "{plugin_version}"` to `composer.json`.
|
||||
Then add package to `"activate-plugins"` composer script in `composer.json` file in order in which you wish them to be activated.
|
||||
If plugin exposes wp cli command for database updates add it to `"update-db"` composer script in `composer.json` file
|
||||
(ex: woocommerce plugin exposes `wp wc update` which will apply pending database plugins for woocommerce).
|
||||
|
||||
For updating wordpress core or plugins, update version for package
|
||||
(wordpress core database changes will be applied with `wp core update-db` cli command ).
|
||||
|
||||
After any of these actions run:
|
||||
|
||||
composer update # → Will download latest code
|
||||
composer update-db # → Activate plugins and calls all exposed wp cli commands for db updates
|
||||
|
||||
For removing plugin that has no db changes just remove it from composer.json and execute `composer update` which will remove its code;
|
||||
If plugin has database changes that we wish to be removed that is oneoff migration that can be done from
|
||||
admin panel or using `wp plugin deactivate {plugin_name} && composer remove wpackagist-plugin/{plugin_name}` script.
|
||||
|
||||
WP CLI is very powerful tool for writing automation scripts without need to track and copy mysql dumps.
|
||||
|
||||
- Wiaas plugin
|
||||
|
||||
Our code is placed inside `backend/app/plugins/wiaas` folder.
|
||||
This folder will be managed by git and commited to repository (check `backend/.gitignore`).
|
||||
|
||||
Wiaas exposes `wp wiaas update-db` command to WP CLI which will execute pending db updates for wiaas.
|
||||
|
||||
If your feature requires some database updates that can be easiliy executed from wordpress code, then
|
||||
place this update to `wiaas/includes/db-updates/wiaas-db-update-functions.php` as a function named `wiaas_db_update_{name}`.
|
||||
Then add this function to `wiaas/includes/class-wiaas-db-update.php` with its timestamp.
|
||||
This way after `composer update-db` is executed your database update will be applied.
|
||||
|
||||
Reference in New Issue
Block a user