Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Change docroot to public to align with Symfony's best practice structure #101

Open
wants to merge 4 commits into
base: 6.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 32 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies with [Composer](https://getcomposer.org/).

## Usage

First you need to [install composer 2](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx).
First you need to install [Composer v2](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx).

> Note: The instructions below refer to the [global composer installation](https://getcomposer.org/doc/00-intro.md#globally).
You might need to replace `composer` with `php composer.phar` (or similar)
Expand All @@ -14,7 +14,7 @@ for your setup.
After that you can create the project:

```
composer create-project mautic/recommended-project:^5.0 some-dir --no-interaction
composer create-project mautic/recommended-project:^6.0 some-dir --no-interaction
```

With `composer require ...` you can download new dependencies to your installation.
Expand All @@ -33,12 +33,12 @@ all files not excluded by the .gitignore file.

When installing the given `composer.json` some tasks are taken care of:

* Mautic will be installed in the `docroot`-directory.
* Mautic will be installed in the `public/` directory.
* Autoloader is implemented to use the generated composer autoloader in `vendor/autoload.php`,
instead of the one provided by Mautic (`docroot/vendor/autoload.php`).
* Plugins (packages of type `mautic-plugin`) will be placed in `docroot/plugins/`
* Themes (packages of type `mautic-theme`) will be placed in `docroot/themes/`
* Creates `docroot/media`-directory.
instead of the one provided by Mautic (`public/vendor/autoload.php`).
* Plugins (packages of type `mautic-plugin`) will be placed in `public/plugins/`
* Themes (packages of type `mautic-theme`) will be placed in `public/themes/`
* Creates `public/media` directory.
* Creates environment variables based on your .env file. See [.env.example](.env.example).

## Updating Mautic Core
Expand All @@ -56,9 +56,9 @@ Follow the steps below to update your core files.
2. Run `git diff` to determine if any of the scaffolding files have changed.
Review the files for any changes and restore any customizations to
`.htaccess` or others.
1. Commit everything all together in a single commit, so `docroot` will remain in
3. Commit everything all together in a single commit, so `public/` will remain in
sync with the `core` when checking out branches or running `git bisect`.
1. In the event that there are non-trivial conflicts in step 2, you may wish
4. In the event that there are non-trivial conflicts in step 2, you may wish
to perform these steps on a branch, and use `git merge` to combine the
updated core files with your customized files. This facilitates the use
of a [three-way merge tool such as kdiff3](http://www.gitshah.com/2010/12/how-to-setup-kdiff-as-diff-tool-for-git.html). This setup is not necessary if your changes are simple;
Expand All @@ -75,7 +75,7 @@ workrounds if a project decides to do it anyway](https://getcomposer.org/doc/faq
### Should I commit the scaffolding files?

The [Mautic Composer Scaffold](https://github.com/mautic/core-composer-scaffold) plugin can download the scaffold files (like
index.php, .htaccess, …) to the docroot/ directory of your project. If you have not customized those files you could choose
index.php, .htaccess, …) to the `public/` directory of your project. If you have not customized those files you could choose
to not check them into your version control system (e.g. git). If that is the case for your project it might be
convenient to automatically run the mautic-scaffold plugin after every install or update of your project. You can
achieve that by registering `@composer mautic:scaffold` as post-install and post-update command in your composer.json:
Expand Down Expand Up @@ -110,43 +110,48 @@ section of composer.json:
}
```

### How do I specify a PHP version ?
### How do I specify a PHP version?

This project supports PHP 7.4 as minimum version, however it's possible that a `composer update` will upgrade some package that will then require PHP 7+ or 8+.
This project supports PHP 8.1 as the minimum version (see [Mautic requirements](https://mautic.org/mautic-requirements/)). However, running a `composer update` may upgrade some packages that require a higher PHP version.

To prevent this you can add this code to specify the PHP version you want to use in the `config` section of `composer.json`:
To prevent this, you can specify the PHP version in the `config` section of `composer.json` by adding the following code:
```json
"config": {
"sort-packages": true,
"platform": {
"php": "7.4"
"php": "8.1"
}
},
```

### How do I use another folder than docroot as webroot
Alternatively, you can run the following command:
```bash
composer config platform.php 8.1
```

### How do I use another directory than `public` as web root

By default the composer.json file is configures to put all Mautic core, plugin and theme files in the `docroot` folder.
It is possible to change this folder to your own needs.
By default the composer.json file is configures to put all Mautic core, plugin and theme files in the `public/` directory.
It is possible to change this directory to your own needs.

In following examples, we will change `docroot` into `public`.
In following examples, we will change `public/` into `docroot/`.

##### New installations

* Run the `create-project` command without installing
* Run the `create-project` command without installing
```bash
composer create-project mautic/recommended-project:^4.0 some-dir --no-interaction --no-install
composer create-project mautic/recommended-project:^6.0 some-dir --no-interaction --no-install
```
* Do a find and replace in the `composer.json` file to change `docroot/` into `public/`.
* Do a find and replace in the `composer.json` file to change `public/` into `docroot/`.
* Review the changes in the `composer.json` file to ensure there are no unintentional replacements.
* Run `composer install` to install all dependencies in the correct location.

##### Existing installations

* move the `docroot/` to `public/`
* Move the `public/` to `docroot/`
```bash
mv docroot public
mv public docroot
```
* Do a find and replace in the `composer.json` file to change `docroot/` into `public/`.
* review the changes in the `composer.json` file to ensure there are no unintentional replacements.
* run `composer update --lock` to ensure the autoloader is aware of the changed folder.
* Do a find and replace in the `composer.json` file to change `public/` into `docroot/`.
* Review the changes in the `composer.json` file to ensure there are no unintentional replacements.
* Run `composer update --lock` to ensure the autoloader is aware of the changed directory.
* Ensure that config parameters related to the `media` directory in the `config/local.php` file point to the correct directory (`docroot/media` instead of `public/media`)
17 changes: 11 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
},
"autoload": {
"psr-4": {
"MauticPlugin\\": "docroot/plugins/"
"MauticPlugin\\": "public/plugins/"
}
},
"scripts": {
Expand All @@ -124,22 +124,27 @@
],
"npm-ci": "npm ci --prefer-offline --no-audit",
"npx-patch-package": "npx patch-package",
"generate-assets": "@php bin/console mautic:assets:generate"
"generate-assets": "@php bin/console mautic:assets:generate",
"migrate-webroot": [
"@php -r \"if (!is_dir('docroot')) { echo 'ERROR: Directory docroot/ not found. Already migrated? Exiting.' . PHP_EOL; exit(1); } if (is_dir('public')) { echo 'ERROR: Directory public/ already exists. Already migrated? Exiting.' . PHP_EOL; exit(1); } rename('docroot', 'public');\"",
"@php -r \"\\$file='composer.json'; copy(\\$file, \\$file.'.backup'); \\$content = file_get_contents(\\$file); \\$content = preg_replace('/\\\"web-root\\\": \\\"docroot\\//','\\\"web-root\\\": \\\"public/', \\$content); \\$content = preg_replace('/\\\"docroot\\/app\\\": \\[/', '\\\"public/app\\\": [', \\$content); \\$content = preg_replace('/\\\"docroot\\/plugins\\/\\{\\\\\\$name\\}\\\": \\[/', '\\\"public/plugins/{\\\\\\$name}\\\": [', \\$content); \\$content = preg_replace('/\\\"docroot\\/themes\\/\\{\\\\\\$name\\}\\\": \\[/', '\\\"public/themes/{\\\\\\$name}\\\": [', \\$content); file_put_contents(\\$file, \\$content);\"",
"@php -r \"\\$file='config/local.php'; copy(\\$file, \\$file.'.backup'); \\$content = file_get_contents(\\$file); \\$content = preg_replace('/(\\'[^\\']+\\'\\s*=>\\s*\\')(.*?)\\/docroot\\/media(.*?\\')/', '\\1\\2/public/media\\3', \\$content); file_put_contents(\\$file, \\$content);\""
]
},
"extra": {
"mautic-scaffold": {
"locations": {
"web-root": "docroot/"
"web-root": "public/"
}
},
"installer-paths": {
"docroot/app": [
"public/app": [
"type:mautic-core"
],
"docroot/plugins/{$name}": [
"public/plugins/{$name}": [
"type:mautic-plugin"
],
"docroot/themes/{$name}": [
"public/themes/{$name}": [
"type:mautic-theme"
]
},
Expand Down