I am working on Magento 2 Project.
I did Setup Git on my server. so I can push and pull changes on server directly without using ftp.
in my local i do push changes to git. and I do pull on remote side. so I get my changes over there.
So I am thinking to create shell script that manually written command are perform one by one by just executing one script.
In Script I am thinking too.
- Connect server using ssh. hosts name and password.
- and then enter in project directory using cd project name.
- and there it perform git pull command.
- and some magento commands to update changes. (Like: bin/magento setup:upgrade etc…)
So is there any way to do something like this?
2
Answers
You can execute commands over ssh by doing
ssh user@host 'command1;command2'
and either use sshpass (but you’d have to store the password in plain text, which is a bit of a no no) or set up key-based authentication (recommended)First, you’ll have to install sshpass, can install by running following command in your terminal:
Now go to /home/{youruser}/ and open .bashrc file in any editor ( Press Ctrl+H, if file not visible ).
Now let’s create a command alias, create a new line in .bashrc file as per your project details. For example:
Copy-paste above command in .bashrc file and save it and open a new terminal. Enter “connect-magento” in the terminal and now you’ll connect to the server without a copy, pasting, or typing anything.
Similarly, you can make shortcut of other commands whichever you wish to by adding in .bashrc file and giving it an alias.