$command = "sudo ssh -p 22 root@XXX.XXX.XX.XX python3 /home/scripts/apps/xxx/xxx/email_address/email_builder.py"; shell_exec($command); note the you have to configure both server to be able to communicate via ssh (creating the key on the first one, uploading the pub key to the other, etc.)