How to edit a file in cPanel

The built-in File Manager editor lets you fix a file right in the browser, without FTP or programs on your computer. Most often it is used for .htaccess, wp-config.php, .user.ini, robots.txt and site templates.

Open a file

  1. Select the file in "File Manager".
  2. Click "Edit".
  3. In the encoding check window, click "Edit". For UTF-8 sites you do not need to change the encoding.
Opening a file in the editor
Opening a file in the editor

Encoding: when it matters

Old Ukrainian and Russian sites are sometimes saved in the windows-1251 encoding. If you open such a file as UTF-8 and save it, Cyrillic text turns into garbage or question marks. For these files choose windows-1251 or cp1251 in the encoding window. The site encoding is shown by charset in the template or in the CMS settings.

The "Disable Encoding Check" link removes this window; you can bring it back in the File Manager "Settings". If the account has sites in windows-1251, better keep the window.

Editing and saving

The editor opens in a new tab, with syntax highlighting, search and line numbers.

  1. Make your changes.
  2. Click "Save Changes" at the top right.
  3. Click "Close".
Code editor
Code editor

After saving, open the site in a private window and check the page the change affects. If an error appears, put the copy of the file back.

Make a copy before editing important files: copying. A mistake in .php or .htaccess breaks the site at once.

"View" opens a file read-only - handy for looking at a log or settings without changing anything by accident. "HTML Editor" is a visual editor for .html pages; do not open .php files in it, it can damage the code.

Common mistakes

  • A missing semicolon or quote in .php - the site shows a blank page or error 500. The error text is in the error log.
  • Code pasted from Word or a messenger - curly quotes instead of straight ones break it. Copy code from a plain text file.
  • Large files (logs, database dumps) open slowly in the editor - download them and view them on your computer.
Questions and answers
Restore your copy of the file if you made one, or restore the file from a backup in JetBackup.
A windows-1251 file was opened as UTF-8. Put the copy back and open the file with windows-1251 selected in the encoding window.
In the File Manager "Settings", clear "Disable Character Encoding Verification Dialogs".