Created
June 28, 2019 10:45
-
-
Save salgua/bd27fbe9788b7ff5bc18527db95ff912 to your computer and use it in GitHub Desktop.
Magento 2 rapid deployment - from local to remote server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Author: Salvatore Guarino - [email protected] | |
# Instructions: | |
# | |
# 1. Manually rsync the local Magento 2 folder on the remote server. | |
# 2. Change the Mysql DB settings on app/etc/env.php on the remote server. | |
# 3. Copy the script on your local Magento 2 folder | |
# 4. Change variables according to your local and remote environment | |
# 5. Execute the bash script | |
# 6. Enjoy :) | |
# VARIABLES | |
LOCAL_PHP='/usr/local/bin/php' | |
LOCAL_MYSQLDUMP='/usr/local/bin/mysqldump' | |
LOCAL_MYSQLUSER='root' | |
LOCAL_MYSQLPASSWORD='root' | |
LOCAL_MYSQLHOST='127.0.0.1' | |
LOCAL_MYSQLDB='magento' | |
LOCAL_RSYNC='/usr/local/bin/rsync' | |
REMOTE_SSHHOST='www.yourmagento2site.com' | |
REMOTE_SSHUSER='user' | |
REMOTE_MAGENTOPATH='/path/to/magento2/folder' | |
REMOTE_PHP='/usr/bin/php' | |
REMOTE_MYSQL='/usr/bin/mysql' | |
REMOTE_MYSQLUSER='root' | |
REMOTE_MYSQLPASSWORD='root' | |
REMOTE_MYSQLDB='remote-db' | |
REMOTE_MAGENTO_BASE_URL='https://yourmagento2site.com/' | |
REMOTE_MAGENTO_SECURE_URL='https://yourmagento2site.com/' | |
# | |
# STOP - DON'T EDIT THE FILE FROM HERE | |
# | |
$LOCAL_PHP bin/magento cache:flush #svuoto la cache | |
$LOCAL_MYSQLDUMP --column-statistics=0 -u $LOCAL_MYSQLUSER -p$LOCAL_MYSQLPASSWORD -h $LOCAL_MYSQLHOST $LOCAL_MYSQLDB > dbdump.sql | |
$LOCAL_RSYNC -avz --exclude 'app/etc/env.php' ./ $REMOTE_SSHUSER@$REMOTE_SSHHOST:$REMOTE_MAGENTOPATH --delete | |
ssh $REMOTE_SSHUSER@$REMOTE_SSHHOST << ENDSSH | |
cd $REMOTE_MAGENTOPATH | |
$REMOTE_MYSQL -u $REMOTE_MYSQLUSER -p$REMOTE_MYSQLPASSWORD $REMOTE_MYSQLDB < dbdump.sql | |
$REMOTE_PHP bin/magento setup:store-config:set --base-url="$REMOTE_MAGENTO_BASE_URL" | |
$REMOTE_PHP bin/magento setup:store-config:set --base-url-secure="$REMOTE_MAGENTO_SECURE_URL" | |
$REMOTE_PHP bin/magento cache:flush | |
$REMOTE_PHP bin/magento deploy:mode:set developer | |
$REMOTE_PHP bin/magento deploy:mode:set production | |
ENDSSH |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment