Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
automatic Config.php integration
It would be swell if upon first install the Config.php information could be automatically into the configuration details. The current behavior displays a user error when it exists and requires the user to delete/rename it before continuing. Removing this behavior would help to encourage automatic installs similar to WP.
Offline
Re: automatic Config.php integration
Do you mean when there’s an existing config.php but no database / no database tables?
If I upload a site with an existing config.php and an existing DB, it just works. If I try and run setup on that, it warns me so I don’t overwrite it.
TXP Builders – finely-crafted code, design and txp
Offline
Re: automatic Config.php integration
No. I mean where there is nothing existing and it is a brand new install. If the configuration information is already within the config file, why do you have to enter it into the web interface? It would make automating the installation that much easier.
Offline
Re: automatic Config.php integration
Sounds like the same situation to me. It would need some additional admin user credentials in the config, I suppose? And a way of preventing others from running it inadvertently, thereby overwriting your nice site.
Maybe the UI setup could ask to use the information if already present?
Or there be an automatic CLI / url flag based way of overriding the confirmation requirement?
TXP Builders – finely-crafted code, design and txp
Offline
Re: automatic Config.php integration
Let me get this straight in my head. You’re installing a fresh Txp but in your filesystem, you have pre-prepared config.php and uploaded it. You visit /textpattern/setup and want it to guess the language, fill in the database credentials by reading them from the config file, test them, then guess the user credentials and theme in the nest step so you can automate installation? Not sure how to do that.
We do allow automated installs already by fully populating the config file and XML files, minus user credentials which I think have to be injected. See CLI and ask Pete how it’s done on the demo server.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: automatic Config.php integration
Parse the information from the config.php file and load it into the form. The UI doesn’t need to do anything. If the configuration file is present, auto populate the form values. If not present, don’t auto populate.
Offline
Offline
Re: automatic Config.php integration
TheEric wrote #340797:
Parse the information from the config.php file and load it into the form.
Oooft, not a fan of that. I like to keep setup as insulated as possible for security reasons, especially since someone might forget to delete the directory and it could leak database access credentials.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: automatic Config.php integration
Bloke wrote #340796:
See CLI and ask Pete how it’s done on the demo server.
That would interest me, as I often spin up sites for testing and then remove them again. Or I end up doing the same set of steps and standard plugins. At the moment, I do all that manually.
Is the CLI method officially documented anywhere? I found this post by Pete and gave it a whirl but the json syntax has changed since then. I got it working with a setup.json
as follows (by looking up what options there are in setup.php and setup_lib.php):
{
"site": {
"language_code": "en",
"public_url": "joebloggs.test",
"admin_theme": "hive",
"public_theme": "four-point-nine",
"content_directory": ""
},
"database": {
"user": "mysql_db_user",
"password": "mysql_db_pass",
"host": "localhost",
"db_name": "mysql_db_name",
"table_prefix": "",
"charset": "utf8mb4"
},
"user": {
"full_name": "Joe Bloggs",
"email": "joe@bloggs.com",
"login_name": "joe",
"password": "blogger-bloggs"
}
}
I see you can supply a data directory for importing prefs, articles, plugins, etc. but have not yet tried any of that. Could it be that Yes (thanks Pete)?datadir
has also changed and is now content_directory
I found I first had to create the database, or is it possible to automate that part too?
One last question: is it by chance possible to install textpattern using composer?
TXP Builders – finely-crafted code, design and txp
Offline
Re: automatic Config.php integration
My ears were burning…hi!
In the case of the demo sites, it’s not an exact match to your situation since I’ve prepped a clean room database that includes ~1,000 users. However, here’s how I automate the install ([…]
is the path to the server root, with live
and staging
being subdirectories of that server root):
php […]/live/textpattern/setup/setup.php --config=[…]/staging/release-demo.json
The release-demo.json
file comprises:
{
"site": {
"language_code": "en",
"public_url": "release-demo.textpattern.co",
"admin_url": "",
"admin_theme": "",
"public_theme": "four-point-eight",
"content_directory": "",
"cookie_domain": ""
},
"database": {
"user": "release_demo",
"password": "PLAINTEXTPASSWORDGOESHERE",
"host": "127.0.0.1",
"db_name": "release_demo",
"charset": "utf8mb4",
"table_prefix": "",
"client_flags": ""
},
"user": {
"full_name": "Textpattern Demo Robot",
"email": "domo-arigato-mr-roboto@example.com",
"login_name": "textpattern-robot",
"password": "PLAINTEXTPASSWORDGOESHERE"
}
}
The textpattern-robot
is used for the install, and then I add users, images, files, and then tweak some settings. These additions / changes are all prebuilt .sql files and some have associated files copied into place. There’s some preflight and post flight prep / nuke / tidy up, but that’s about the size of it.
Offline
Re: automatic Config.php integration
gaekwad wrote #340804:
My ears were burning…hi!
:-) Thank you Pete. That was helpful.
jakob wrote #340802:
I found I first had to create the database, or is it possible to automate that part too?
One last question: is it by chance possible to install textpattern using composer?
To answer those two, I made a shell script (macOS / zsh) that does that. This is a first attempt that grabs the current dev branch of the repo, cleans out the git, linting, readme and sites files/folders to leave only the core files, creates a database and runs setup with predefined config values and admin user details of your choosing. It’ll probably evolve as I experiment with it. If anyone thinks it’s helpful/useful, I could put it online as a Gist on GitHub.
Once it’s ready for use, creating new local sites is as simple as (in my case using Valet, but certainly adaptable to other local webservers):
- Create a folder with the site name in your
/Sites/
folder. With valet that will automatically be reachable as http://foldername.test. - Create your setup.json according to the pattern above in that folder. The database does not need to exist but php and mysql services must be running.
- Open that folder in the terminal (in Finder, right-click on the folder and choose Services › New Terminal at folder) and enter
./setup_textpattern.zsh
in the prompt. Wait for the script to run. Enter your mysql password if requested. - In your browser, sign in at
http://foldername.test/textpattern/
It takes all of 10 seconds on my computer and connection. Creating the setup.json takes longest, and often there will be only be a few details to change from site to site.
This is the script
#!/bin/zsh
# --- CONFIGURABLE VARIABLES ---
REPO_URL="https://github.com/textpattern/textpattern.git"
REPO_BRANCH="dev"
REPO_DIR="textpattern"
TMP_DIR="textpattern_tmp"
SETUP_JSON="setup.json"
# List of files/folders (relative to $REPO_DIR) to delete; extend/alter as needed
TO_DELETE=(
".git"
".github"
".gitignore"
".gitattributes"
".phpstorm.meta.php"
"phpcs.xml"
"composer.lock"
"composer.json"
"package.json"
"HISTORY.txt"
"UPGRADE.txt"
"INSTALL.txt"
"LICENSE.txt"
"README.txt"
"README.md"
"CONTRIBUTING.md"
"CODE_OF_CONDUCT.md"
"SECURITY.md"
"rpc"
"sites"
)
# --- SCRIPT START ---
set -e # Exit on errors
# 1. Clone the repo
git clone "$REPO_URL" --branch "$REPO_BRANCH"
# 2. Delete listed files/folders
for item in $TO_DELETE; do
target="$REPO_DIR/$item"
if [[ -e $target ]]; then
rm -rf "$target"
echo "Deleted: $target"
fi
done
# 3. Rename the folder
mv "$REPO_DIR" "$TMP_DIR"
# 4. Copy contents to base folder
cp -a "$TMP_DIR/." .
# 5. Delete leftover folder
rm -rf "$TMP_DIR"
# 6. Read setup.json and create MySQL DB if it doesn't exist
if [[ ! -f $SETUP_JSON ]]; then
echo "ERROR: $SETUP_JSON not found!"
exit 1
fi
db_host=$(jq -r '.database.host' "$SETUP_JSON")
db_user=$(jq -r '.database.user' "$SETUP_JSON")
db_pass=$(jq -r '.database.password' "$SETUP_JSON")
db_name=$(jq -r '.database.db_name' "$SETUP_JSON")
db_char=$(jq -r '.database.charset' "$SETUP_JSON")
if mysql -h"$db_host" -u"$db_user" -p"$db_pass" -e "USE \`$db_name\`;" 2>/dev/null; then
echo "Database $db_name already exists. Exiting."
exit 1
else
mysql -h"$db_host" -u"$db_user" -p"$db_pass" --default-character-set="$db_char" -e "CREATE DATABASE \`$db_name\`;"
echo "Database $db_name created."
fi
# 7. Run setup
php textpattern/setup/setup.php --config="$SETUP_JSON"
To make it ready for use:
- Save this as a text file in your folder with the name
setup_textpattern.zsh
(change as desired). Optionally make it usable system-wide (see below). - Run
chmod +x setup_textpattern.zsh
to make it executable.
Prerequisites:
- MacOS (the shell here is zsh)
- A local webserver running git, php and mysql
- jq installed in your shell
- Optional: Add the location of
setup_textpattern.zsh
to your $PATH variable in.zshrc
or.zprofile
. You can also simply copy the .zsh file temporarily to your newly created web root folder and make it executable (as above).
Adapting:
- If you prefer to keep certain files & folders in your textpattern installation, edit the TO_DELETE variable.
- If you want to copy a different branch, or different setup.json filename, you can change those at the top of the script.
Still to solve:
- It prompts twice for the SQL server’s password. Can that be skipped to run silently?
TXP Builders – finely-crafted code, design and txp
Offline
#12 Today 02:55:00
Re: automatic Config.php integration
I’ve been installing, nuking, and reinstalling as I work on a few of my projects. Having to go through the install is frustrating when I want a clean install. I created a shell script to install it, but it stops at that spot. At some point I’ll just create my own install script since we’re a touch boomer here.
Offline