2

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.

3
  • 1
    DO NOT SET MODE 777 - This is a gaping security hole!
    – Daenyth
    Commented Aug 17, 2012 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
    Commented Aug 17, 2012 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
    Commented Aug 17, 2012 at 16:18

2 Answers 2

6

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.

2
  • 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
    Commented Aug 17, 2012 at 19:42
  • 1
    @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
    Commented Aug 17, 2012 at 21:42
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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