MODX Community

How can I edit a PHP file from within MODX?

I would like to edit a standard .php file from within MODX. How can I do this?

On the Files tab in the manager, right-click on the file and select “Edit File.” If you have the Ace code editor extra installed, you’ll also get some minimal error checking and auto-completion.

1 Like

If you’re not allowed to save the PHP files, you’ll need to allow the php extension. Go to System > System Settings and search for the upload_files setting. Edit it, and add php into that comma-separated list. After that, saving PHP files will work.

Do note that allow users to edit PHP files from the manager can lead to either wrecking the site (e.g. editing the root index.php or configuration file) or them gaining additional permissions. If you have other users you don’t 100% trust with manager access, it’s best to disable php editing again after you’re done.

1 Like

Building on Mark’s answer, when I install Modx, I normally define a new Media Source for “normal” users (Content Editors or other roles we need), pointing to a specific directory. I then define this new media source as default media source for Modx (in system settings) and limit the “Filesystem” media source to administrators (or any other group you need, like a “developers” group you might want to define).

In this way, I can prevent “normal” users from accessing the file system, which includes the core folder & other sensitive directories.

On some sites where I had the need to edit PHP files through the manager, I changed (as Mark suggests) the “allowedFileTypes” value for the “Filesystem” media source, allowing me to edit the PHP files while users don’t get this right as it is not defined for their media source.

Hope this helps

If you’ve moved the core directory above the web root (recommended), this article explains how to make the core files show in the File tree. As jcreiss suggests, you’ll want to restrict access to the core Media Source.