0

I'm trying to open the /private/etc/apache2/httpd.conf file to make some changes. I thought I'd be able to open this with the correct permissions from the command line, so I tried:

cd /private/etc/apache2
sudo open -a TextEdit httpd.conf

This opened the file in TextEdit, but TextEdit gave me this message:

You don't own the file "httpd.conf" and don't have permission to write to it. You can duplicate this document and edit the duplicate. Only the duplicate will include your changes.

Fine. Apparently using open even with sudo opens the app as the user. So I tried this:

sudo /Applications/TextEdit.app/Contents/MacOS/TextEdit httpd.conf

But I immediately get this popup:

The document "httpd.conf" could not be opened. You don't have permission. To view or change permissions, select the item in the Finder and choose File > Get Info.

This makes TextEdit hang too, so I have to force quit it.

I also tried to open the file using my Komodo text edit, which is my normal development environment:

sudo -b /Applications/Komodo\ Edit\ 8.app/Contents/MacOS/komodo httpd.conf

The terminal spits out this strange message:

2014-09-24 11:48:29.583 komodo[30647:507] * WARNING: Method userSpaceScaleFactor in class NSWindow is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead.

And Komodo opens, but doesn't open the file. How do I edit this file with my program of choice?

2

The reason these applications can't write to that files is to do with application sandboxing feature of OS X, which you can read about here if you are interested.

One GUI application that can write to these files is TextWrangler which you can download for free here. There is also a version of TextWrangler in the Mac App Store (MAS) but it doesn't have the ability to write to system files by default (MAS guidelines don't allow applications with those abilities), but you can find an update here that will update the MAS version of TextWrangler so that it can.

Alternatively you can use command line tools to edit these files. For example sudo nano https.conf works okay, and nano is relatively user friendly.

1

To expand on 'dylans'' point, you can use Sublime Text to edit files and open them straight from the Terminal. The CLI utility that Sublime provides called subl.

To use Sublime Text 3:

open /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl

For Sublime Text 2:

open /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl

Next, create symlink named sublime that links subl CLI to a folder that can execute these binaries:

Sublime Text 3:

ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/sublime

Sublime Text 2:

ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/sublime

Now check that the symlink was created in the correct place:

open ~/.bash_profile

In your profile, make sure this folder is somewhere in your $PATH. If not, add it:

export PATH=/usr/local/bin:

If no $PATHs are set, type this line in your bash_profile and then refresh/source it:

export PATH=/usr/local/bin:$PATH
source ~/.bash_profile

These commands should now allow Sublime to be opened automatically:

sublime . - To open current directory in Sublime
sublime filename – To open a file (replace 'file' w/ actual name i.e. 'httpd.conf')

For reference or more detailed info goto https://gist.github.com/artero/1236170

-1

Sublime text 3 works for these files.

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .