note 87479 added to function.opendir
| From: | Postfromeverything2dotcom at osu1 dot php dot net | Date: | Sat, 06 Dec 2008 19:54:04 +0000 |
| Subject: | note 87479 added to function.opendir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-147757@lists.php.net to get a copy of this message | ||
when you run Apache as a service on your Windows computer, it chooses to run as the LocalSystem
account by default (usually SYSTEM). The LocalSystem account has no network privileges whatsoever
which, while no doubt a good thing, makes it impossible to access networked resources (such as a
shared drive) in your Apache service.
First, you have to change the user the Apache service runs as.
Go to your Services panel (Start -> Run -> "services.msc").
Find the Service labeled Apache, right-click, and hit Properties.
Choose the "Log On" tab.
Presumably you'll see that Apache is set up to run as the Local System Account. You'll
want to change this to the second option, "This account", and then fill in the details of
the User account you would like Apache to run under.
Some sites tell you to create a special Apache-based user account just for this occasion. It's
not a bad idea, but then you have to make sure it has all of the proper permissions that an Apache
user would need, such as read/write to to htdocs and the .conf and .log files, and permissions to
log on as a service, etc etc - as well as the permissions to access the network resource you're
trying to get to in the first place.
In light of that process, I chose to just run it under my own account instead. Once you get it
working, you can go back and create that special account.
Hit "Apply" - it'll pop up a box saying you need to restart Apache to take effect,
but hold off on that for a moment.
This is the tricky part: you have to give the user (the one you're running Apache as)
permissions to act as part of the OS.
Go to the Local Security Policy panel (Start -> Run -> "secpol.msc").
Under the navigation section in the left sidebar, choose Local Policies -> User Rights
Assignments.
In the right-hand frame, double-click the item "Act as part of the operating system" to
open up its properties.
Select "Add User or Group, Enter the appropriate user in the box provided, and hit
"OK."
At this point, you are technically complete - Apache can now do the same things to the network
resource that your user can - read, write, execute, whatever. However, in my case, I was trying to
create an actual readable resource, so I edited my Apache config file to create an alias to my
share.
Open up your Apache configuration file. For most people it's httpd.conf in the conf
subdirectory of your Apache install directory.
Add the following text to your config file (obviously substituting your UNC for
"//servername/sharename" and renaming ALIAS_DIRECTORY to whatever you'd like):
Alias /ALIAS_DIRECTORY "//servername/sharename"
<Directory "//servername/sharename">
Options Indexes
AllowOverride None
Order allow,deny
Allow from all
</Directory
The other thing that is tricky and caught me up is that unlike Windows UNCs, the Apache config file
requires forward slashes, not backslashes. So if you're copying the UNC directly from Windows,
you'll have to turn all those slashes around.
Now you can restart your Apache service. Take a swing over to http://your.site.name/ALIAS_DIRECTORY and you
should be able to view the network resource just fine.
----
Server IP: 195.54.192.44
Probable Submitter: 127.0.0.1
----
Manual Page -- http://www.php.net/manual/en/function.opendir.php
Edit -- https://master.php.net/note/edit/87479
Del: integrated -- https://master.php.net/note/delete/87479/integrated
Del: useless -- https://master.php.net/note/delete/87479/useless
Del: bad code -- https://master.php.net/note/delete/87479/bad+code
Del: spam -- https://master.php.net/note/delete/87479/spam
Del: non-english -- https://master.php.net/note/delete/87479/non-english
Del: in docs -- https://master.php.net/note/delete/87479/in+docs
Del: other reasons-- https://master.php.net/note/delete/87479
Reject -- https://master.php.net/note/reject/87479
Search -- https://master.php.net/manage/user-notes.php