Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP FAQs
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP FAQs This moderated forum is where our PHP experts answer some of the questions they see asked most frequently in the other PHP forums. You cannot post other messages here, use the other PHP forums for that.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP FAQs section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Closed Thread
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 5th, 2004, 05:51 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 5 Times in 5 Posts
Default Q. How do I set permissions in Win. XP or Linux?

Setting Permissions For Windows XP

Windows XP is quite straight-forward.
    Start->Run->"explorer"->(Navigate to Folder)->(Right Click On Folder)->Sharing & Security->(Check) Share this folder on the network->(Check) Allow network users to change my files.

Besides granting PHP write access, if you are on a network computer, this will allow other network users access to your files. (If anyone has found a better way email me through my P2P profile page with the answer).

Setting Permissions For Linux
(A compilation of previous replies made by Nik and I)

First the easiest and simpliest method:

To make a CHMOD command via FTP:
Download an FTP program that supports changing the CHMOD setting natively. One is WS FTP, a GUI-based tool that supports making simple shell commands like chmod. Its free to download and use, highlight the directory in the viewer and select CHMOD (Unix) from the right click menu.

To make a CHMOD command via telnet/terminal command line:
Open your favorite telnet program (Start->Run->'telnet'). Type in your website's domain name (website must support telnet for this to work). If your webserver is your home computer, or if you have a telnet or ssh program on your home computer, then it's easy to just log into your linux web server using the account username and password that you use to write/upload your PHP files. If logging in remotely you should see the welcome message, etc, and then the command line. Now think of the command line in terms of file path hierarchy. You should be now in the same folder as you would be in if you logged in by FTP. You can navigate into the folder heirarchy by typing in CD directory_name. Navigate to the folder you want to change permissions on. And then make the CHMOD command.

Each number used in the CHMOD command is added to get the permission level:

4 = (r)ead
2 = (w)rite
1 = e(x)ecute

For example, at the command line, type:

chmod 750 *.php

This sets your permissions to:

Code:
  rwxr-x---
  |||| +-> Group execute
  |||+---> Group read
  ||+----> User  execute
  |+-----> User  write
  +------> User  read
There are three groups for which you set permissions for.
Owner / Owner's Group / World at Large

So in short:
chmod 333: -wx-wx-wx
chmod 664: rw-rw-r--
chmod 444: r--r--r--
chmod 222: -w--w--w-

The PHP function chmod
Okay, when you run chmod() from within PHP, then the user that PHP is running under is the user that's trying to change the permissions level of the file. If the PHP user doesn't have access to open or read the file to begin with, odds are it won't be able to grant itself access to do so. If that were the case, what good would having permissions be in the first place?

http://www.php.net/chmod

The Best Method:
Go to the directory that your PHP scripts are located (cd command).

Code:
    chmod 750 *.php (explained above)
This means that any users in the user-group the file belongs to can read and execute your PHP scripts, but cannot modify or delete them. This also means that no other user on the system can read, write, or execute your PHP files.

Now, the only thing left to do is to change the group of your PHP files. Typically, this is "www" or "nobody" on linux systems.

Code:
    chown <your_username>:nobody *.php
This keeps you as the file owner, and sets the group to be "nobody". That allows the webserver, via it's group access, to read and execute your php files.

The last thing you need to do is allow the webserver to create new files in your directory. You need to set additional permissions on the directory, similar to how we did for your PHP scripts. Type:

Code:
    chmod 770
This sets full (Read/Write/eXecute) permissions for both you, the user, and the group. We still need to make sure that the webserver has this access via the group. Type:

Code:
    chown <your_username>:nobody
That sets the directory's group to be "nobody".

Now, PHP (via the web-server's group), can read and execute existing files in your directory and create new ones.

Alternative method For ISP-based/third-party Hosting:
If you are unable to run chown commands because it is blocked by your ISP, a chmod 777 on the destination directory may be necessary to give the PHP script proper write permissions. This of course means, read, write and execute permission for all three groups. Be warned however that chmod 777 gives read write and execute permission to anyone who wants to! This is a security hole created. Any user on the server can write to your directory. You might well be better off to paste the above instructions to a message to your ISP's technical support, politely asking them to make the command for you.
Closed Thread


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
XP Home Edition permissions sevans ASP.NET 2.0 Basics 2 February 25th, 2007 08:38 PM
help:: Prob with DCOM in Win XP sachin_dm C++ Programming 2 March 23rd, 2005 12:28 AM
Setting MySQL Permissions, Windows XP scrabala BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 1 November 2nd, 2004 04:09 PM
Installing PHP on Win XP how to ? tandhy BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 April 6th, 2004 12:51 PM
Win '98 vs. Win XP rgerald Access VBA 0 February 19th, 2004 11:30 AM



All times are GMT -4. The time now is 12:02 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.