PHP read from a mounted drive

Recently, I needed to read from a mounted drive on osx using Apache and PHP. I need to grab some file names in a certain directory using opendir or scandir, then dynamically populate a select dropdown box.

The issue is, the default apache user is _www being in the _www group, while the mounted drive allows only the “staff” group to enter.

In my case, I cannot change the mounted drive access permissions.

So, what options are left? I guess I can only change the apache user. If you decide to take this path, there are two options. One is to add the “staff” group to your default _www user. Read the man page yourself… The other option is to assign an existing user (who has access to the mounted drive) to apache. I picked the latter, don’t ask me why… ok, coz I am lazy…

Open up your /etc/apache2/httpd.conf , you will need to sudo.

Find the line that has “User _www”. Change that to say “User john_smith”. Then change the next line to the right group. If you don’t know what user and group to use here, just do an “ls -ld /Volumes/mounted_drive/” and use the user and group there.

Save it. Then restart apache by issuing “sudo apachectl restart”.

That should do it.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s