How to edit a file directly on the server
Making a quick change to a file already on the server, using the editor built into your control panel, without downloading and re-uploading it by hand.
For a small, specific change — fixing a typo, adjusting one line in a configuration file, adding a redirect rule — editing the file directly on the server is quicker than downloading it, opening it locally, editing it, and uploading it back. This guide covers doing that safely, since editing in place also means a mistake takes effect immediately.
Before editing anything, particularly a configuration file such as .htaccess or wp-config.php, make a copy. In the file manager, this usually means right-clicking the file and choosing Copy or Duplicate, and renaming the copy something like filename.php.bak. If the edit breaks something, you can restore the original in seconds rather than trying to reconstruct it from memory.
Editing with the control panel file manager
-
Back up the file first
Duplicate the file within the same folder, or download a copy to your own computer, before making any change.
-
Open the built-in editor
Right-click the file in the file manager and choose Edit or Code Editor, rather than View, which usually only displays the file without letting you change it. The editor opens in your browser and shows the file's plain text content.
-
Make the change and save
Keep changes as small and targeted as possible — the more you change in one sitting, the harder it is to work out what caused a problem if one appears. Save using the button in the editor rather than trying to use your browser's own save function, which would download the page instead of saving your change.
-
Check the site immediately
Load the page the file affects straight away. If something has gone visibly wrong, you will know immediately rather than finding out later, and the backup copy from step one is right there to restore from.
Editing with an FTP client
Many FTP clients, including FileZilla, offer a "View/Edit" option when you right-click a remote file. Choosing it downloads the file to a temporary local folder, opens it in your computer's default text editor for that file type, and — once you save and close it — asks whether to upload the changed version back. This is a convenient middle ground when you would rather use your own text editor than a browser-based one.
Programs such as Microsoft Word add invisible formatting even to documents that look like plain text on screen, and saving a code or configuration file with a word processor is one of the more common ways a working file stops working with no visible change. Use a plain text or code editor — Notepad, TextEdit set to plain text mode, or a proper code editor — for anything you plan to upload back to the server.
Which files are safe to edit this way
| File type | Editing in place |
|---|---|
| HTML, CSS, plain text | Safe — a mistake typically breaks only the styling or content of that page. |
| PHP files | Fine for small changes, but a syntax error can take the whole page down immediately — check the site right after saving. |
.htaccess | Powerful and easy to get wrong. A single incorrect rule can affect the entire site, not just one page. Keep a backup copy at hand. |
| Binary files — images, archives, PDFs | Not editable as text. Opening one of these in a text editor and saving it will corrupt it. |
Editing on a live site versus a quiet moment
A PHP or configuration file edit takes effect the instant it is saved — there is no separate deployment step, and no delay before visitors start seeing the new version. For anything more than a trivial change, it is worth making the edit at a time when the site has fewer visitors, so that if something does go wrong briefly while you fix it, fewer people encounter the problem. This matters much less for a small content change to a plain HTML or CSS file, where the worst case is usually cosmetic rather than the page failing to load at all.
Working with line endings and character encoding
A file edited on Windows and one edited on macOS or Linux can end up with different invisible line-ending characters, and mixing the two within the same file occasionally causes a script to behave oddly even though the visible text looks identical. Most browser-based code editors in a control panel handle this automatically, but if you are editing locally and re-uploading, save the file with UTF-8 encoding and consistent line endings if your editor offers the choice, particularly for a file that already works and that you are making a small change to rather than rewriting.
If an edit breaks the page
Reopen the file, undo the specific change you made, and save again — or, faster, replace the file with the backup copy you made in step one. If you did not make a backup and the site is now showing an error, our guide to getting back a file you overwrote covers the options available, including checking whether your hosting account keeps its own automatic backups you can pull an earlier version from.
For finding the file in the first place if you are not sure where it lives, see finding a file on your hosting account.
Related reading
Using the search built into your file manager, or narrowing it down folder by folder in an FTP client, when you cannot remember where a file went.
How to get back a file you overwroteWhere to look immediately after overwriting a file by mistake, in the order most likely to get it back without restoring anything you did not need to.
How to use the file managerUploading, editing and setting permissions on your website files without needing FTP.
FTP, FTPS and SFTP: which to useThree protocols with confusingly similar names, one of which sends your password in the open. Here is what actually separates them.