Rsync using PhpStorm on Save

Imran Sayed
2 min readFeb 24, 2019

--

There are times when you have a copy of your project files from your remote server and you need to work locally. However, when you make changes in the files locally, you want to be able to update the files on your remote server as well and see the changes in the server files real-time when you hit save on your code editor.

In this blog, you will learn how you can you can configure PhpStorm to do real-time sync of your local files with the files on the remote server.
We can achieve this using 2 simple steps:

Step 1: Create an executable rsync file.

We will create an executable file in which we will write the rsync command.
Create a directory called sync in Document

Create a file called rsync.sh inside the sync directory. Add the below code to rsync.sh file.

//~/Document/sync/rsync.shrsync -avzO --chmod=Dg+s --exclude node_modules /Users/imransayed/htdocs/wordpress-test/wp-content/themes/xyz-theme/ username@something.com:/var/www/someproject/wp-content/themes/xyz-theme/

Here /Users/imransayed/htdocs/wordpress-test/wp-content/themes/xyz-theme/ is the local path of your theme project files.
And username@something.com:/var/www/someproject/wp-content/themes/xyz-theme/ is the path to the theme directory on your server you want to sync with.

Notice the --exclude flag, which allows us to exclude the directory we don’t want to sync. Here we are excluding node_modules directory to prevent it from syncing.

We can also create a file called .exclude-files in our home directory put all the file names we want to exclude from sync and instead of --exclude node_moduleswe can use --exclude-from=$HOME/.exclude-files

.git*
.DS*
error_log
.ht*
.*
node_modules
.idea
Vagrantfile
cache

Now let's make the rsync.sh file executable

cd ~/Document/sync/
chmod +x rsync.sh

Step 2: Configure PhpStorm for rsync

Open your project in PhpStrom and go to PhpStorm > Preferences > Tools > File Watchers .

Now let’s click on the + icon and select custom

Now lets put name as any name that we want e.g. rsync-some-project.
File Type: Any
Scope: Project Files
Program: Select the path to the sync.sh file that you created above.
Now press OK > Apply >OK

Now each time you hit save in your project, the filesynch.sh will be executed and it will run the rsync that it contains, which will sync your project files to the files on remote server.

--

--

Imran Sayed
Imran Sayed

Written by Imran Sayed

👤 Full Stack Developer at rtCamp, Speaker, Blogger, YouTuber, Wordpress, React, Node, Laravel Developer http://youtube.com/ImranSayedDev

Responses (1)