Download

Guides

How to Edit PHP Files Directly on a Server via SFTP

How to fix a PHP file on a live server from Windows over SFTP: credentials, tools, a safe step-by-step flow and common errors.

Short answer

Connect over SFTP with the host, port, username and password or key from your hosting panel, then open the file in an editor that can save it back to the server. On Windows you can use an FTP client plus a local editor, VS Code with an SFTP extension, or an editor with SFTP built in. Whichever you pick, back up the file before you change anything.

Sometimes a site needs a quick fix and there is no deployment pipeline to run it through. A typo in config.php, a wrong link in a footer include, a setting that has to change today.

This guide is for anyone on shared hosting who needs to fix one file quickly from a Windows PC. It is not a replacement for a proper deployment workflow.

FTP, SFTP and FTPS: which one to use

Three protocols get mixed up all the time:

  • FTP (port 21) sends your password and files unencrypted. Avoid it whenever you have a choice.
  • SFTP runs over SSH, usually on port 22. It is a different protocol from FTP, not “FTP with encryption”. Everything, including your login, is encrypted.
  • FTPS is classic FTP wrapped in TLS. Explicit FTPS starts on port 21 and upgrades to TLS. Implicit FTPS uses port 990.

If your host offers SFTP, use it. It works through a single port, which makes firewall problems less likely, and it is what most SSH-enabled hosting plans expect.

Get your SFTP credentials from your host

Before you open any tool, collect four things from your hosting control panel (cPanel, Plesk, DirectAdmin or the host’s own dashboard):

  1. Host name. Usually your domain or a server name like server123.example-host.com.
  2. Port. Often 22, but many shared hosts use a custom port. Hostinger, for example, uses 65002 for SFTP.
  3. Username. Often your hosting account username, not your email address.
  4. Password or SSH key. Some hosts require you to enable SSH access first, or to upload a public key. On cheaper plans SFTP may not be available at all.

Also note the path to your site’s files (often public_html, www or htdocs). You will need it to find the right file.

Three ways to edit files on a server from Windows

1. An FTP client plus a local editor

This is the classic approach. WinSCP and FileZilla both support SFTP. WinSCP can open a remote file in its own editor or an external one, and it uploads the file again each time you save. FileZilla’s “View/Edit” option downloads the file to a temporary folder and asks whether to upload it after you change it.

Pros: free, well documented, and it works with any editor. Cons: you are juggling two programs. Temporary copies can get confused with your real files. It is also easy to forget the upload prompt, or to approve it too quickly.

2. VS Code with an SFTP extension

Visual Studio Code has no built-in SFTP support, but extensions add it. A popular one is the SFTP extension maintained by Natizyskunk, which continues the original liximomo extension. You configure a connection per project, and you can turn on upload-on-save. Recent versions ship with that setting off by default.

Pros: a full-featured editor, and the extension is free. Cons: you have to install and configure the extension, the setup is a JSON config file rather than a dialog, and quality varies between extensions. For a one-off fix it can be more setup than the fix itself.

3. An editor with built-in SFTP, such as Spider V6

The third option is a code editor that includes the SFTP client, so connecting, editing and publishing all happen in one window. Our own editor, Spider V6, works this way on Windows 10 and 11. It has a built-in SFTP, FTP and WebDAV client, a file queue, and synchronization between your local and remote project versions. For the editing itself you get PHP syntax highlighting and formatting, code folding for long files, unlimited undo/redo and a built-in terminal.

Pros: no plugins to find, and no separate FTP program. It is handy when you look after several small client sites. Cons: it is Windows-only (on macOS or Linux it needs Windows emulation). The full feature set is paid after a 7-day trial: editing files directly on the server, syncing folders and several servers are premium features ($33.95 perpetual or $19.95 per year, net of VAT), and the free basic version (private, non-commercial use) works with one open document and one server connection. And if your team has standardized on VS Code, adding another editor may not be worth it.

Step by step: editing a PHP file over SFTP

The flow is the same in every tool. Only the buttons differ.

  1. Add the server connection. Enter the host, port (22 or your host’s custom port), username and password or private key. Choose SFTP as the protocol, not FTP or FTPS.
  2. Accept the host key only after checking it. On the first connection you will see the server’s fingerprint. If your host publishes it, compare the two before you accept.
  3. Browse to the file. Go to your web root (for example public_html) and find the file.
  4. Make a backup. Download a copy, or duplicate the file on the server as file.php.bak. Delete that copy afterwards, because a .bak file in a public folder may be readable by anyone.
  5. Edit and save. Keep the change small. If your tool does not upload on save, upload the file yourself.
  6. Check the site at once. Reload the page in a private browser window. If something breaks, put the backup back right away.

In Spider V6 you add the server connection to your project. You then use the built-in SFTP client to fetch the file, edit it in the editor and publish it back. Synchronization keeps your local copy and the server in step.

Safety checklist before you touch production

  • Back up the file first. One copy is enough for a quick fix. For larger changes, back up the whole folder and the database.
  • Edit a copy when you can. If the site has a staging subdomain, test the change there first.
  • Check PHP syntax before uploading. If PHP is installed on your PC, run php -l file.php (you can use the built-in terminal in your editor). A single missing semicolon in a file that is loaded on every page can take down the whole site.
  • Keep file permissions sensible. On typical shared hosting, files are 644 and folders are 755. Never “fix” an error by setting 777.
  • Have a rollback. Know exactly how you will restore the previous version before you click save. Without one, do not edit production at all.

Common errors and how to fix them

“Permission denied” usually means you are trying to write to a file or folder your account does not own, or the file is read-only (for example 444). Check the owner and permissions in your client, or ask your host. On some hosts, certain files such as wp-config.php are deliberately locked down.

Connection refused or time-outs most often come from the wrong port or protocol. SFTP on port 21 will not work, and neither will FTP on port 22. Confirm the port in your hosting panel. Also check that SSH/SFTP is enabled for your plan.

Host key prompt or “host key has changed” warning. The first prompt is normal. A changed key on a server you already use can mean the host moved your account to new hardware, or it can mean something worse. Ask your host before you accept it.

“Headers already sent” after editing. This classic PHP error appears when anything is sent to the browser before a header() or session_start() call. Two invisible culprits come from Windows editors: a space or blank line before <?php, and a UTF-8 byte order mark (BOM) at the start of the file. Save PHP files as UTF-8 without BOM and check the very first characters of the file.

Line endings. Windows uses CRLF line endings and Linux servers use LF. PHP itself copes with both, but shell scripts and cron jobs saved with CRLF can fail with odd errors. If you edit those, set your editor to LF.

Frequently asked questions

Can I edit files on a server without FileZilla?

Yes. Any tool that speaks SFTP will do: WinSCP, VS Code with an SFTP extension, or an editor with a built-in SFTP client such as Spider V6. Your host’s web-based file manager also works for tiny changes, though it has no real code editor.

Is it safe to edit PHP files directly on a live server?

It is acceptable for small, urgent fixes if you back up the file first, check the syntax and know how to roll back. For anything bigger, edit locally or on staging and publish the tested result.

Why does my host say SFTP is not available?

SFTP depends on SSH access, and some entry-level shared hosting plans leave it out or require you to switch it on in the panel. If it is not available, FTPS is the next best option. Plain FTP should be the last resort.