Snippets Collections
// Configurration for lanch.json

{
	"version": "0.2.0",
    "configurations": [
        {
          	"name": "Listen for XDebug",
          	"type": "php",
          	"request": "launch",
          	"port": 9000,
          	"pathMappings": {
            	"/var/www/project/": "${workspaceFolder}/site/project/"
            }
    	}
    ]
}


    
// Content of xdebug.ini on server
    
zend_extension=xdebug.so

xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_host=10.0.2.2
xdebug.remote_port=9000
xdebug.remote_connect_back=1
xdebug.remote_cookie_expire_time=30
xdebug.idekey=vscode
xdebug.max_nesting_level=512

xdebug.profiler_enable=0
xdebug.profiler_output_name=xdebug.out.%t
xdebug.profiler_output_dir=/vargrant/profiler
xdebug.profiler_enable_trigger=1
  
  
// To install xdebug on server run
sudo apt-get install php-xdebug
// Edit xdebug.ini
sudo nano /etc/php/mods-available/xdebug.ini
#!/bin/sh

### SSH Info ###
SUSER="serverusername";
SHOST="example.com";
SDIR="/srv/www/example.com";

echo 'starting rsync'

rsync -e "/usr/bin/ssh" --compress --stats -rlDHS $SUSER@$SHOST:$SDIR /srv/www/example.com

WPDBHOST=`cat /srv/www/example.com/wp-config.php | grep DB_HOST | cut -d \' -f 4`;
WPDBNAME=`cat /srv/www/tomjn.com/wp-config.php | grep DB_NAME | cut -d \' -f 4`;
WPDBUSER=`cat /srv/www/tomjn.com/wp-config.php | grep DB_USER | cut -d \' -f 4`;
WPDBPASS=`cat /srv/www/tomjn.com/wp-config.php | grep DB_PASSWORD | cut -d \' -f 4`;

echo 'finished rsync, grabbing database'

FILE=$SDIR/mysql-$WPDBNAME.sql.gz;        # Set the backup filename

#echo "mysqldump -q -u $WPDBUSER -h $WPDBHOST -p$WPDBPASS $WPDBNAME | gzip -9 > $FILE";
ssh $SUSER@$SHOST "mysqldump -q -u $WPDBUSER -h $WPDBHOST -p$WPDBPASS $WPDBNAME | gzip -9 > backup.sql.gz"

scp $SUSER@$SHOST:./backup.sql.gz .              # copy all the files to backup server
ssh $SUSER@$SHOST rm ./backup.sql.gz             # delete files on db server

gunzip -d backup.sql.gz

mysql -u root -e "CREATE DATABASE IF NOT EXISTS $WPDBNAME"
mysql -u root -e "GRANT ALL PRIVILEGES ON $WPDBNAME.* To 'wp'@'localhost'"
mysql -u wp -pwp $WPDBNAME < backup.sql

sed -i "/DB_HOST/s/'[^']*'/'localhost'/2" wp-config.php
sed -i "/DB_USER/s/'[^']*'/'wp'/2" wp-config.php
sed -i "/DB_PASSWORD/s/'[^']*'/'wp'/2" wp-config.php
star

Mon Jun 07 2021 18:14:17 GMT+0000 (UTC) https://tomjn.com/2014/03/01/wordpress-bash-magic/

#wordpress #automate #provision #vagrant #vm

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension