From e5bde0b71e07cf5ce73923b634066acbed37149c Mon Sep 17 00:00:00 2001 From: Ali Mahdavi Date: Mon, 4 Mar 2024 10:05:09 +0300 Subject: [PATCH 1/8] test permission issue --- php-fpm.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/php-fpm.sh b/php-fpm.sh index b0d250d..87c07ba 100644 --- a/php-fpm.sh +++ b/php-fpm.sh @@ -9,14 +9,16 @@ pid=$(cat $pidfile) kill $pid # loop that resests php-fpm and folder permissions each 30 minutes while true; do + # reset wp folder permissions + chmod -R g+rwx /var/www/html/ + chown -R www-data:www-data /var/www/html/ + # Start the process - php-fpm -g $pidfile & + #php-fpm -g $pidfile & # Wait for 30 minutes sleep 1800 # Kill the process - pid=$(cat $pidfile) - kill $pid - # reset wp folder permissions - chmod -R g+rwx /var/www/html/ - chown -R www-data:www-data /var/www/html/ + #pid=$(cat $pidfile) + #kill $pid + done \ No newline at end of file From 5da334a2c970fcf661bc2e99f164ad6c42df5266 Mon Sep 17 00:00:00 2001 From: Ali Mahdavi Date: Mon, 4 Mar 2024 10:37:41 +0300 Subject: [PATCH 2/8] test php-fpm --- php-fpm.sh | 4 +- wp-config.php | 335 +++++++++++++++++++++++++------------------------- 2 files changed, 169 insertions(+), 170 deletions(-) diff --git a/php-fpm.sh b/php-fpm.sh index 87c07ba..3538a9c 100644 --- a/php-fpm.sh +++ b/php-fpm.sh @@ -14,11 +14,11 @@ while true; do chown -R www-data:www-data /var/www/html/ # Start the process - #php-fpm -g $pidfile & + php-fpm -g $pidfile & # Wait for 30 minutes sleep 1800 # Kill the process - #pid=$(cat $pidfile) + pid=$(cat $pidfile) #kill $pid done \ No newline at end of file diff --git a/wp-config.php b/wp-config.php index 652e019..94e19fd 100644 --- a/wp-config.php +++ b/wp-config.php @@ -1,168 +1,167 @@ -connect_errno ) {// this is a slave node - //Disable cron on slave nodes - define( 'DISABLE_WP_CRON' , true ); - //Disable WP_AUTO_UPDATE_CORE on slave nodes - define( 'WP_AUTO_UPDATE_CORE', false ); -} else { - $is_slave = false; - $mysqli->close(); -} - -// If we're behind a proxy server and using HTTPS, we need to alert WordPress of that fact -// see also https://wordpress.org/support/article/administration-over-ssl/#using-a-reverse-proxy -if ( !empty( $_SERVER['HTTP_HOST'] ) || $_SERVER['REMOTE_ADDR'] === '127.0.0.1' ) { - if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && strpos( $_SERVER['HTTP_X_FORWARDED_PROTO'], 'https' ) !== false ) { - $_SERVER['HTTPS'] = 'on'; - } else { - define( 'WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/' ); - define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/' ); - } -} else { - // request comming from FDM health check, check if node is slave - if ( $is_slave ) { - header('HTTP/1.1 500 Internal Server Error'); - echo 'Database connection failed'; - exit(0); - } else { - echo 'OK'; - $mysqli->close(); - exit(0); - } -} - -if ( $configExtra = getenv_docker('WORDPRESS_CONFIG_EXTRA', '') ) { - // eval($configExtra); -} - -define( 'WP_MEMORY_LIMIT', '1024M' ); - -# define( 'WP_DEBUG', true); -# define( 'WP_DEBUG_LOG', true ); -/* That's all, stop editing! Happy publishing. */ - -/** Absolute path to the WordPress directory. */ -if ( ! defined( 'ABSPATH' ) ) { - define( 'ABSPATH', __DIR__ . '/' ); -} - -/** Sets up WordPress vars and included files. */ -require_once ABSPATH . 'wp-settings.php'; - +connect_errno ) {// this is a slave node + //Disable cron on slave nodes + define( 'DISABLE_WP_CRON' , true ); + //Disable WP_AUTO_UPDATE_CORE on slave nodes + define( 'WP_AUTO_UPDATE_CORE', false ); +} else { + $is_slave = false; + $mysqli->close(); +} + +// If we're behind a proxy server and using HTTPS, we need to alert WordPress of that fact +// see also https://wordpress.org/support/article/administration-over-ssl/#using-a-reverse-proxy +if ( !empty( $_SERVER['HTTP_HOST'] ) || $_SERVER['REMOTE_ADDR'] === '127.0.0.1' ) { + if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && strpos( $_SERVER['HTTP_X_FORWARDED_PROTO'], 'https' ) !== false ) { + $_SERVER['HTTPS'] = 'on'; + } else { + define( 'WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/' ); + define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/' ); + } +} else { + // request comming from FDM health check, check if node is slave + if ( $is_slave ) { + header('HTTP/1.1 500 Internal Server Error'); + echo 'Database connection failed'; + exit(0); + } else { + echo 'OK'; + exit(0); + } +} + +if ( $configExtra = getenv_docker('WORDPRESS_CONFIG_EXTRA', '') ) { + // eval($configExtra); +} + +define( 'WP_MEMORY_LIMIT', '1024M' ); + +# define( 'WP_DEBUG', true); +# define( 'WP_DEBUG_LOG', true ); +/* That's all, stop editing! Happy publishing. */ + +/** Absolute path to the WordPress directory. */ +if ( ! defined( 'ABSPATH' ) ) { + define( 'ABSPATH', __DIR__ . '/' ); +} + +/** Sets up WordPress vars and included files. */ +require_once ABSPATH . 'wp-settings.php'; + From 27ef0bed5819a7fb683eb2f013b1de5853535075 Mon Sep 17 00:00:00 2001 From: Ali Mahdavi Date: Mon, 4 Mar 2024 10:42:03 +0300 Subject: [PATCH 3/8] add logs --- php-fpm.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/php-fpm.sh b/php-fpm.sh index 3538a9c..2950ed6 100644 --- a/php-fpm.sh +++ b/php-fpm.sh @@ -9,13 +9,15 @@ pid=$(cat $pidfile) kill $pid # loop that resests php-fpm and folder permissions each 30 minutes while true; do - # reset wp folder permissions - chmod -R g+rwx /var/www/html/ - chown -R www-data:www-data /var/www/html/ # Start the process php-fpm -g $pidfile & # Wait for 30 minutes + + # reset wp folder permissions + chmod -R g+rwx /var/www/html/ + chown -R www-data:www-data /var/www/html/ + echo "Reseted Permissions." sleep 1800 # Kill the process pid=$(cat $pidfile) From 4f49158c22a266c8c54a3851d36335f7e985c282 Mon Sep 17 00:00:00 2001 From: Ali Mahdavi Date: Mon, 4 Mar 2024 10:47:31 +0300 Subject: [PATCH 4/8] minor change --- php-fpm.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/php-fpm.sh b/php-fpm.sh index 2950ed6..6bf17cd 100644 --- a/php-fpm.sh +++ b/php-fpm.sh @@ -2,25 +2,24 @@ pidfile="/usr/local/bin/php-fpm-pid" # Start the process php-fpm -g $pidfile & -# Wait for 10 seconds -sleep 10 +# Wait for 5 seconds +sleep 5 # Kill the process pid=$(cat $pidfile) kill $pid +sleep 5 # loop that resests php-fpm and folder permissions each 30 minutes while true; do # Start the process php-fpm -g $pidfile & - # Wait for 30 minutes - # reset wp folder permissions chmod -R g+rwx /var/www/html/ chown -R www-data:www-data /var/www/html/ echo "Reseted Permissions." + # Wait for 30 minutes sleep 1800 # Kill the process pid=$(cat $pidfile) - #kill $pid - + kill $pid done \ No newline at end of file From 6917f2719af279c39e3e4a2b9a5b6d04c69d975a Mon Sep 17 00:00:00 2001 From: Ali Mahdavi Date: Mon, 4 Mar 2024 10:49:20 +0300 Subject: [PATCH 5/8] test permission --- php-fpm.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/php-fpm.sh b/php-fpm.sh index 6bf17cd..7345dc8 100644 --- a/php-fpm.sh +++ b/php-fpm.sh @@ -6,20 +6,20 @@ php-fpm -g $pidfile & sleep 5 # Kill the process pid=$(cat $pidfile) -kill $pid +#kill $pid sleep 5 # loop that resests php-fpm and folder permissions each 30 minutes while true; do # Start the process - php-fpm -g $pidfile & + #php-fpm -g $pidfile & # reset wp folder permissions chmod -R g+rwx /var/www/html/ chown -R www-data:www-data /var/www/html/ echo "Reseted Permissions." # Wait for 30 minutes - sleep 1800 + sleep 5 # Kill the process - pid=$(cat $pidfile) - kill $pid + #pid=$(cat $pidfile) + #kill $pid done \ No newline at end of file From 17be7eb1b95755a3747d6851ebde89f4ce31f366 Mon Sep 17 00:00:00 2001 From: Ali Mahdavi Date: Mon, 4 Mar 2024 11:04:53 +0300 Subject: [PATCH 6/8] reset permissions every 5 min --- php-fpm.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php-fpm.sh b/php-fpm.sh index 7345dc8..b06cb22 100644 --- a/php-fpm.sh +++ b/php-fpm.sh @@ -17,8 +17,8 @@ while true; do chmod -R g+rwx /var/www/html/ chown -R www-data:www-data /var/www/html/ echo "Reseted Permissions." - # Wait for 30 minutes - sleep 5 + # Wait for 5 minutes + sleep 300 # Kill the process #pid=$(cat $pidfile) #kill $pid From 8e684bd4603273a00cebd3c18641753dee4aefca Mon Sep 17 00:00:00 2001 From: Ali Mahdavi Date: Fri, 15 Mar 2024 11:47:25 +0300 Subject: [PATCH 7/8] disable ip:port browsing --- wp-config.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-config.php b/wp-config.php index 94e19fd..b17607e 100644 --- a/wp-config.php +++ b/wp-config.php @@ -132,8 +132,8 @@ function getenv_docker( $env, $default ) { if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && strpos( $_SERVER['HTTP_X_FORWARDED_PROTO'], 'https' ) !== false ) { $_SERVER['HTTPS'] = 'on'; } else { - define( 'WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/' ); - define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/' ); + // define( 'WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/' ); + // define( 'WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/' ); } } else { // request comming from FDM health check, check if node is slave From bfc94d68f4abbdfc4b47f99a0cf2559fdd3aefc7 Mon Sep 17 00:00:00 2001 From: Ali Mahdavi Date: Fri, 15 Mar 2024 11:53:12 +0300 Subject: [PATCH 8/8] error handling --- wp-config.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/wp-config.php b/wp-config.php index b17607e..5e6818a 100644 --- a/wp-config.php +++ b/wp-config.php @@ -114,16 +114,24 @@ function getenv_docker( $env, $default ) { /* Add any custom values between this line and the "stop editing" line. */ // Check DB connection -$mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $is_slave = true; -if ( $mysqli->connect_errno ) {// this is a slave node +try { + $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); + if ( $mysqli->connect_errno ) {// this is a slave node + //Disable cron on slave nodes + define( 'DISABLE_WP_CRON' , true ); + //Disable WP_AUTO_UPDATE_CORE on slave nodes + define( 'WP_AUTO_UPDATE_CORE', false ); + } else { + $is_slave = false; + $mysqli->close(); + } +} +catch(Exception $e) { //Disable cron on slave nodes define( 'DISABLE_WP_CRON' , true ); //Disable WP_AUTO_UPDATE_CORE on slave nodes define( 'WP_AUTO_UPDATE_CORE', false ); -} else { - $is_slave = false; - $mysqli->close(); } // If we're behind a proxy server and using HTTPS, we need to alert WordPress of that fact