The recommended Bedrock in this issue is a modern WordPress stack to help you get started with the best development tools and project structures.
Bedrock特征
-
- Better folder structure
- Use Composer for dependency management
- Easily configure WordPress using environment specific files
- Dotenv environment variable
- Automatic loader for mu plugins (using regular plugins as mu plugins)
Enhanced security (using WP password bcrypt to separate web root and secure password)
Bedrock installation
1. Create a new project:
$ composer create-project roots/bedrock
2. Update the environment variable. env in the file. Wrap values that may contain non alphanumeric characters in quotation marks, otherwise they may be interpreted incorrectly</ p>
- Database variables
DBNAME - Database Name
DB-USER - Database User
DB-PASSWORD - Database Password
DB_SOST - Alternatively, you can define DATABASE-URL to use DSN instead of the variables above (e.g. mysql://user: password@127.0.0.1 :3306/db_name)
- WP-INV – Set as environment (development, staging, production)
- WP.HOME – Full URL of WordPress homepage( https://example.com )
- WP_SITEURL – The complete URL of WordPress, including subdirectories( https://example.com/wp )
- AUTH_KEY, SECURE_AUTH_KEY, LOGGED_IN_KEY, NONCE_KEY, AUTH_SALT, SECURE_AUTH_SALT, LOGGED_IN_SALT,NONCE_SALT
3. web/app/themes/Add themes like adding a regular WordPress website
4. Set the document root directory on your network server to Bedrock’s web folder:/path/to/site/web/
5. Accessing WordPress administrators
https://example.com/wp/wp-admin/
Bedrock特征示例
1. WordPress template with modern development tools, simpler configuration, and improved folder structure
# Create a new Bedrock project
$ composer create-project roots/bedrock
# Add plugins with Composer
$ composer require wpackagist-plugin/safe-redirect-manager
$ composer require wpackagist-plugin/simple-page-ordering
$ composer require wpackagist-plugin/woocommerce
2. Better WordPress project structure
Bedrock’s organization is similar to putting WordPress in its own subdirectory, but with some improvements, including renaming wp-content/ to app/.
├── composer.json
├── config
│ ├── application.php
│ └── environments
│ ├── development.php
│ ├── staging.php
│ └── production.php
├── vendor
└── web
├── app
│ ├── mu-plugins
│ ├── plugins
│ ├── themes
│ └── uploads
├── wp-config.php
├── index.php
└── wp
3. Dependency Management using Composer
Manage your WordPress installation and plugins with PHP dependency manager Composer. Composer will make development more reliable, help team collaboration, and help maintain better Git repositories.
4. Simple WordPress configuration
Use Dotenv for environment-specific profiles and environment variables.
5. Enhanced security
Isolate Web roots by wp-password-bcrypt to restrict access to non-Web files and more secure passwords.
Bedrock document
Documentation for the Roots project, including Acorn, Bedrock, Sage, and Trellis.
1.Acorn Docs
Acorn is a way to use Laravel components in WordPress.
Acorn brings elements of the Laravel ecosystem to any WordPress plugin or theme.
In short, Acorn provides a way to load Laravel application containers gracefully within WordPress, while respecting the WordPress lifecycle and template hierarchy.
< Using Composer to install Acorn
Install Acorn in a WordPress installation managed by Composer, for example using Bedrock:
$ composer require roots/acorn
We also recommend adding Acorn’s postAutoloadDump function to composer’s post-autoload-dump event composer.json:
"post-autoload-dump": [
"Roots\\Acorn\\ComposerScripts::postAutoloadDump"
]
Server requirements:
Acorn has very few server requirements, mostly from WordPress and Laravel 8.
PHP > =7.3 or > = 8.0 < / p >
WordPress > = 5.4
BCMath PHP extension
Ctype PHP extension
File info PHP extension
JSON PHP extension
Mbstring PHP extension
Tagger PHP extension
XML PHP extension
2.Bedrock Docs
Bedrock is a WordPress template.
Install Bedrock with Composer
Create a new bedrock project:
$ composer create-project roots/bedrock
Multiple sites:
Bedrock is compatible with multi-site networks, but requires a mu-plugin installation on the root/multisite-url-fixer subdomain to ensure that the administrative urls work properly. Subdirectory installations do not require this plug-in, but they can be used well. From your Bedrock directory:
$ composer require roots/multisite-url-fixer
3.Sage Docs
Sage is a WordPress starter theme.
< Installing Sage with Composer
Install Sage from your WordPress theme directory using Composer (your-theme-name is replaced with your theme name below) :
# From your WordPress themes directory, run:
$ composer create-project roots/sage your-theme-name
To install the latest development version of Sage, dev-main add:
at the end of the command
$ composer create-project roots/sage your-theme-name dev-main
You must build theme assets in order to access your site. Failure to build the asset will result in an error:
The manifest [/path/to/sage/public/manifest.json] cannot be found.
Run the first build:
-
- yarn runs installation dependencies from the subject directory
- bud.config.js updates
with local development URL
- yarn build – Compile assets
4.Trellis Docs
Trellis is a tool for creating WordPress Web servers and deploying WordPress sites.
Trellis allows you to create and manage production-ready, performance-optimized servers based on constantly improving best practices. Since you benefit from the community and experience of Roots, Trellis is the right way to self-host.
Install Trellis-cli
$ brew install roots/tap/trellis-cli
Create project:
To create a new project, first, select a descriptive name (and use it instead of the default name example.com). For convenience, we recommend the domain for this site.
$ trellis new example.com
Or to explicitly set the site name and host, use the following command:
trellis new --name example.com --host www.example.com ~/path/to/my/project
After creating the project, the folder structure of the Trellis project will look like this:
example.com/ # → Root folder for the project
├── trellis/ # → Your server configuration (a customized install of Trellis)
└── site/ # → A Bedrock-based WordPress site
└── web/
├── app/ # → WordPress content directory (themes, plugins, etc.)
└── wp/ # → WordPress core (don't touch! - managed by Composer)
Assuming you use the CLI, you will also automatically configure your first WordPress site based on the project folder (or the name and host provided). View the following files to see the basic site configuration:
- trellis/group_vars/development/wordpress_sites.yml
- trellis/group_vars/production/wordpress_sites.yml
Building an example with Bedrock
—END—
Open Source protocol: MIT License