0

Whenever I work on my local machine I am almost always experiencing problems related to file permissions settings, and since I guess they may be related with my local machine configuration I would like to explain how did I configure it in order to get advice on how to configure it properly (Since my knowledge on server configuration is quite limted and I am far from being a sysadmin).

My local machine is using ubuntu as OS and I installed php5, php5-mysql, mysql-server, apache2 and phpmyadmin separately using ubuntu's packages. The only custom configuration I made is that I don't place the websites in etc/apache2/www folder as default but on a specific folder at my home partition ~/www . In order to make this settings work I have to do follow this steps:

  1. I edit /etc/apache2/sites-enabled/000-default as to point to that folder by replacing /var/www with the path to ~/www
  2. Restart apache (sudo /etc/init.d/apache2 restart)
  3. Create a symlink inside ~/www which points to /usr/share/phpmyadmin (# ln -s /usr/share/phpmyadmin /home/carlos/www/phpmyadmin )

This configuration has the following benefits which are quite important to me:

  1. I can keep my code safe whenever I install a new ubuntu release (this is, every six months) yet at the same time I can format / partition without losing any data.
  2. I don't need extra permissions (sudo) every time I want to edit any file (which is often, since it's my development environment), update modules and so on.

However, it also has some drawbacks like the ones I mentioned with file permissions, and I think they are related to the fact that the owner of the files and folders is not www-data user but my own user.

Is there any way to prevent problems with file permissions but also preventing having to place the files in etc/apache2/www folder?

1

The web server must have a properly configured file structure to operate. The files should be placed under /var/www or /usr/local, not under /home. The /etc directory is for system and configuration files, not web data files.

There should be no reason for you to format the root partition when maintaining a system, but if you insist on doing so, put /var /usr and /home on a separate drive, and mount them under the root during boot. That way you will not lose any data.

If you are so desperate to ease the editing, work as root and learn to be careful. But make sure the files are under the correct group and owner for the web server to operate.

1

I've got solution for localhost (Linux Mint) test Apache server (only for local tests).

You need change user and group for Apache to local username (greg as example).

/etc/apache2/envvars:

export APACHE_RUN_USER=greg

export APACHE_RUN_GROUP=greg

Restart Apache.

1

Apache shouldn't be able to write to any files or directories without you explicitly allowing it to be changing ownership or permissions where required e.g. sites/default/files. On a publicly accessible site anything else would be a huge security risk.

Some people like to run apache as their own user locally for convenience but IMO it's better to be aware of which directories need write permissions so you can replicate them on your production environment.

  • I'm using this setup on a local machine, and I am tracking files with git, so there's no way that any file gets modified without noticing it. – ccamara Jun 16 '15 at 8:09
0

One possible answer that I found to solve problems with drupal using this configuration is to change owner and group for sites/default folder to www-data in this way there won't be any problem when drupal wants to create image-styles, cache css or js, create temporal files, attach files... which are the common problems that I found, yet, on the other hand I will be able to edit files without sudo permissions and being able to format / at my wish without losing anything.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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