Applicable to:
- Plesk
Symptoms
-
WordPress instance example.com cannot be cloned, process hangs at 51% or fails with the error:
PLESK_ERROR: WP-CLI command has not finished working in 60 seconds, so it was terminated. Usually this means that there are problems with WordPress instance WordPress instance #12 ('https://staging.example.com') itself, for example it could be infected with malware. Check the wp-config.php file of the instance for potential malware code.
-
Below errors can be found in
/var/log/plesk/panel.log
:CONFIG_TEXT: [2019-06-05 19:24:03.957] ERR [1] '/usr/local/psa/admin/bin/filemng' 'jdoe' 'exec' '/var/www/vhosts/example.com/staging.example.com' '/opt/plesk/php/7.2/bin/php' '-d' 'safe_mode=off' '-d' 'display_errors=off' '-d' 'opcache.enable_cli=off' '-d' 'open_basedir=' '-d' 'error_reporting=341' '-c' '/var/www/vhosts/system/staging.example.com/etc/php.ini' '/usr/local/psa/admin/plib/modules/wp-toolkit/vendor/wp-cli/wp-cli/php/boot-fs.php' '--path=/var/www/vhosts/example.com/staging.example.com' 'search-replace' 'https://example.com' 'https://staging.example.com' '--precise' '--all-tables' failed with code 15.
-
PHP handler of the main domain of the subscription is PHP 7.2 or 7.3;
Cause
Issue in the function `search-replace` from WP-CLI utility in combination with PHP 7.2 & 7.3.
Resolution
Two workarounds are possible:
-
Create the subdomain where to clone the instance (E.G: staging.example.com).
-
Go to Domains > staging.example.com > PHP Settings and switch PHP version to 7.1 for example.
-
Go to WordPress > example.com > Clone
Check Use existing domain or subdomain and select the new domain staging.example.com as Target in the list, the database name can be optionally changed. -
Once cloning finishes, go again to Domains (Or as customer: Websites & Domains) > staging.example.com > PHP Settings and switch back the PHP version to 7.2.
If cloning still fails, clone WordPress manually:
-
Connect to the server via SSH.
-
Create the subdomain where to clone the instance (E.G: staging.example.com):
# plesk bin subdomain --create staging -domain example.com -www-root /staging.example.com -empty-document-root true
Note: In case the target instance is not a subdomain of the source instance, run this command instead:
# plesk bin site --create staging.example.com -webspace-name example.com -hosting true -www-root /staging.example.com -empty-document-root true
-
Copy the files from the source instance to the target folder:
# cp -pr /var/www/vhosts/example.com/httpdocs/* /var/www/vhosts/example.com/staging.example.com/
-
Replace the source URL by the target URL in all these files:
# for i in $(grep -rl "example.com" /var/www/vhosts/example.com/staging.example.com/); do sed -i "s/example.com/staging.example.com/g" $i; done
-
Find the source database details:
# cat /var/www/vhosts/example.com/httpdocs/wp-config.php | egrep 'DB_NAME|DB_USER|DB_PASSWORD|DB_HOST'
define('DB_NAME', 'example-db');
define('DB_USER', 'wp_abcdef');
define('DB_PASSWORD', 'pa$$w0rd');
define( 'DB_HOST', 'localhost:3306' ); -
And make a dump of this database:
# mysqldump -u wp_abcdef -p example-db -h localhost > example-db.sql
-
Replace all strings example.com by staging.example.com in the dump:
# sed -i 's/example.com/staging.example.com/g' example-db.sql
-
Create the new database for the target:
# plesk bin database --create example-stg -domain example.com -server localhost:3306
-
Create a user for this database:
# plesk bin database --create-dbuser stg-example -passwd "MyPass" -domain example.com -server localhost:3306 -database example-stg
-
Edit the file
/var/www/vhosts/example.com/staging.example.com/wp-config.php
and change the values ofDB_NAME
,DB_USER
andDB_PASSWORD
accordingly with the previous step (+DB_HOST
if needed):# cat /var/www/vhosts/example.com/staging.example.com/wp-config.php | egrep 'DB_NAME|DB_USER|DB_PASSWORD'
define('DB_NAME', 'example-stg');
define('DB_USER', 'stg-example');
define('DB_PASSWORD', 'MyPass'); -
Insert the dump into the newly created database example-stg:
# mysql -u stg-example -p example-stg < example-db.sql
-
Connect to the server via RDP.
-
Create the staging subdomain:
C:\> plesk bin subdomain --create staging -domain example.com -www-root /staging.example.com -empty-document-root true
Or, in case the target instance is not a subdomain of the source instance, run this command instead:
C:\> plesk bin site --create staging.example.com -webspace-name example.com -hosting true -www-root /staging.example.com -empty-document-root true
-
Copy the files from the source instance to the target folder, e.g. from
C:\inetpub\vhosts\example.com\httpdocs
toC:\inetpub\vhosts\example.com\staging.example.com
. -
Open
wp-config.php
file in the document root of the copied domain and replace the source URL with the target URL, if it is mentioned.
Find the source database details:CONFIG_TEXT: define('DB_NAME', 'example-db');
define('DB_USER', 'wp_abcdef');
define('DB_PASSWORD', 'pa$$w0rd');
define( 'DB_HOST', 'localhost:3306' ); -
Create a dump of source database in Domains > example.com > Databases > example-db > Export Dump.
-
Open the database dump with a text editor and replace all strings 'example.com' by 'staging.example.com':
-
Create a new database and database user for the target domain in Domains > staging.example.com > Databases.
-
Edit the file
C:\inetpub\vhosts\example.com\staging.example.com\wp-config.php
and change the values ofDB_NAME
,DB_USER
andDB_PASSWORD
accordingly with the previous step:CONFIG_TEXT: define('DB_NAME', 'example-stg');
define('DB_USER', 'stg-example');
define('DB_PASSWORD', 'MyPass'); -
Import the dump into the newly created database in Domains > staging.example.com > Databases > example-stg > Import Dump.
Comments
0 comments
Please sign in to leave a comment.