From 582033f041cc3eaac9520956b3f758ce432711b1 Mon Sep 17 00:00:00 2001 From: Omkar Sathe Date: Sun, 29 Sep 2024 00:01:55 +0530 Subject: [PATCH] Improve README file for script to insert load environment variable code block in index.php file --- README.md | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 92fb890..5b48e33 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ sudo sed -i 's/172.20.1.101/localhost/g' /var/www/html/index.php Create an `.env` file in the root of your project folder. ```sh - cat > /var/www/html/.env <<-EOF + sudo tee /var/www/html/.env <<-EOF DB_HOST=localhost DB_USER=ecomuser DB_PASSWORD=ecompassword @@ -135,25 +135,28 @@ sudo sed -i 's/172.20.1.101/localhost/g' /var/www/html/index.php Update the `index.php` file to load the environment variables from the `.env` file and use them to connect to the database. - ```php + Create a temporary file /tmp/replacement_code_file with php function to load environment variables. + + ```sh + cat > /tmp/replacement_code_file <<-EOF - + EOF + ``` ON a multi-node setup, remember to provide the IP address of the database server in the .env file. + Insert the temporary file code block in index.php after line 104 and remove the file. + + ```sh + sudo sed -i -e '104r /tmp/replacement_code_file' /var/www/html/index.php + + rm /tmp/replacement_code_file + ``` 7. Test