This is a quick guide that will show you how you can connect to a cloud server via SFTP with the PHPStorm IDE from Jet Brians and deploy files from your localhost to the cloud. This is my opinion, I am not paid to promote PHPStorm or UpCloud.
Pre-Requisites/Assumptions
This guide will assume you already have (or know how to)..
- Buy a domain name and point it’s DNS to a server (I use Namecheap.com for buying domains)
- Buy and deploy a server in the cloud. I have used AWS, Digital Ocean, Vultr but now use UpCloud for deploying fast self-managed servers. Read this guide here to see how I create a server from scratch on Up Cloud.
- Setup SSH access to your server and configure a firewall.
- You have or know how to set up PHP and Web Servers and configure them on your localhost and remote server (guides here, here, here, here, here and here).
- etc ( check out all my guides here https://fearby.com/all )
I am using Windows 10 Home (with IIS Web Server (document root redirected to S:\Code\) and a pre built Ubuntu Cloud servers.
Why no FTP? I do not create FTP servers on my serves to increase security and I only access servers via SSH via white-listed IP’s and then authenticate with hardware 2FA keys from YubiCo (read me 2FA guide here and
Background
2 years ago I used to use the Cloud 9 IDE to connect to, and code files on cloud servers and life was good. I could configure and connect to servers, drag and drop files, run bash scripts from a web page and close the Cloud 9 browsers tabs, travel hundreds of kilometres and log back into C9 and all code and bash scripts would reappear.
Here is the Cloud 9 IDE showing code on the left and a Browser on the right.
With Cloud 9 code could be easily accessed, edited and run.
See screenshot of code running from a Cloud 9 hosted server with properties windows on the right.
Regrettably, I cancelled my $9/m subscription to Cloud 9 after a minor stroke and since then I have gone back to a terminal screen to code and transfer files. In the last 2 years.
Uploading and downloading files on mass is painful via pure SSH.
AWS has since purchased Cloud 9 and I am not sure if it will ditch support of non-AWS servers in the future. AWS is good but servers are very expensive for what you get IMHO. I have found Disk IO on UpCloud is awesome (also UpCloud support is great (I am not paid to say that)).
PHPStorm IDE?
A quick Google of IDE’s like Cloud 9 mentioned PHPStorm from Jet Brains. I have used IntelliJ IDEA from Jet Brains before and PHPStorm seems to be very popular.
Go to
https://www.jetbrains.com/phpstorm/ and see the features of PHPStorm
Watch PHPStorm in action
Whats new in PHPStorm 2019.1
Install PHPStorm
Visit https://www.jetbrains.com/phpstorm/download/ and download and install PHPStorm (free trial 30 days)
System requirements
- Microsoft 10/8/7/Vista/2003/XP (incl. 64-bit)
- 2 GB RAM minimum
- 4 GB RAM recommended
- 1024×768 minimum screen resolution
Pricing
PHPStorm is $8.90/m for individual use (or $19.90/m commercial). For the first 12 months of uninterrupted subscription payments qualify you for receiving a perpetual fallback license (20% discount for an uninterrupted subscription for a 2nd year, 40% discount for an uninterrupted subscription for 3rd year onwards).
PHPStorm
Official PHPStorm Pricing Page:
https://www.jetbrains.com/phpstorm/buy/#edition=commercial
Creating a Project
Open PHPStorm and select “Create New Project”.
Choose a project type on the left (e.g “PHP Empty Project“) and choose a location to save too (I chose “S:\code\php001) on my local machine. I chose “S:\code\php001” on my local machine.
Choose a folder to save to.
Click “OK” to create the project.
PHPStorm will have created a project for you. You will notice a “.idea
- misc.xml
- modules.xml
- php001.xml
- wordspace.xml
Do not delete these files.
Creating your first PHP file
You can right click on the project root and select New then PHP File
Or clicking the File then New menu choosing PHP File.
Name the file (e.g index.php)
The file has been created and its available in my localhost web server.
Creating a Deploy Target
Now we need to specify a deploy target in PHPStorm to push the file changes to the cloud. Backup your server (yes backup your server just in case).
Open your PHPStorm project and click Tools, Deployment and then Configuration.
Click the plus icon near the top left and choose SFTP
Name the deployment target (e.g “server (project)”)
- Enter your “server name” or IP and port
- Enter your “ssh username” (ensure the SSH user had write access to the
wwwroot folder and the web server can read the files written by this user) - Under
password I chose “Key pair OpenSSH or Putty (as I had SSH details already setup in Putty details - You can add your
ppk private key from Putty (use theputtygen program toconbvert ssh public and private kets toppk format) - If you have a passphrase on your SSH key add it now
- Enter your web servers remote path (for the project)
- Enter your web server URL
I did SSH to my remote server and created the destination folder. This will ensure I can deploy code here (PHPStorm does not create the remote path
mkdir /wwwroot/php001
chown -R www-data:www-data /wwwroot/php001/
Click Test Connection
No we need to click the Mappings tab and add a mapping.
- Local path is your local path
- Deployment path is / (the web root path is carried forward from the previous tab)
- Web path is the web path that is entered in the browser
Click Add New Mapping. Now we are ready to deploy
Deploying code to the cloud
I right clicked on the root note in PHPStorm and created an index.php file.
I edited the index.php on my local machine and then click the Tools then Deployment and choose “Upload to fearby.com (php001)” menu.
The File Transfer output window showed the transfer progress.
I loaded https://fearby.com/php001/index.php in Google chrome. It worked.
Don’t forget to turn off Automatic uploads under Tools, Deployment menu.
Now when I create new files or change existing files they will auto upload.
Sourc Control
I will add this soon.
Shell Command
You can also open an SSH console to the server and run commands
e.g zip files
zip -r backup.zip .
I can also open a folder window in PHPStorm and show all remote files by clicking Tools then Deployment then Show Remote Files, Zip files can be easily
Linux Client
I will review the Linux PHPStorm client soon.
Troubleshooting
Watch the Official guide on Deployment and Remote Hosts in PhpStorm – PhpStorm Video Tutorial
Good Luck. I hope this guide helps someone.
Version
1.2 Removed advertisements
1.1 Minor Updates
1.0 Initial Version