Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I installed Apache2 and PHP5 last night on my fresh Linux Mint machine.

I created a folder and created a simple index.php file with a call to phpinfo() to test out the installation and every works correctly.

However when I open the file with Sublime Text 2 or any other editor, I cannot save my changes. I can use the sudo nano command to open it with super user privileges and I can save just fine.

The same goes with Mercurial. I cannot hg commit because of permissions. I can only sudo hg commit.

Is this how the basic workflow is supposed to be? If I run the chmod command and recursively give 777 permissions to the folders and files within Apache can run it just fine, but if it's a dynamically created file (created by my web app) then it seems Apache cannot access or run it. I have to run the chmod command again!

Any suggestions on what I should do? I feel like 30% of my time is spent on redundant processes that shouldn't be done at all.

share|improve this question
DO NOT SET MODE 777 - This is a gaping security hole! – Daenyth Aug 17 '12 at 16:09
@Daenyth: Oh I know, it's just what was easiest for my dev machine. That's why I'm asking the question - I want to know what the proper workflow is. – sergserg Aug 17 '12 at 16:10
Is the dev server on a virtual machine? If so, I tend to ensure the 'web docs directory' is a shared directory and edit the files on my host machine. – JW01 Aug 17 '12 at 16:18
up vote 6 down vote accepted

You've indidcated this is your dev environment, so beyond Daenyth's suggestion of using source control (which you should definitely do) I'd suggest doing a little indirection.

In other words, simply use a symbolic link from /var/www to a working directory that you have permission to work in. Then you can mess around in your working directory as needed and apache will happily serve it up.

share|improve this answer
I've never heard of a "symbolic link" before. Does that means Apache will run a PHP script from anywhere as long as there is a Symbolic Link set up? – sergserg Aug 17 '12 at 19:42
@Serg If you have a symlink /var/www -> /home/serg/wwwdev/ and index.php is in wwwdev, then as far as Apache knows, /var/www/index.php exists, as does everything else in wwwdev. So any php scripts that could run under /var/www/ will still run under the new location, because Apache thinks they're still in the first location. – Izkata Aug 17 '12 at 21:42

You should store your code in source control (mercurial for example). Edit it on a local copy and push to your remote repository, then pull the changes to the server as needed.

Make a user/group for the web process to run under, and set the permissions & ownership for that user/group. Any new files will be owned by the process's user, so when configured correctly it should work just fine.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.