简体   繁体   中英

How to set root access for all files put inside my Apache2 root directory?

I am learning PHP at the moment on Linux. I have an Apache2 server running locally. Whenever I tried to save a PHP file into the root directory of Apache2 server ( /var/www/html/), I was told that permission denined.

So, I searched around and found that by default, the admininstartor do not have the root access unless explicitly request for it (like sudo su). I have also seen some posts which ask me to use gksu nautilus . However, my linux 14.04 LTS Ubuntu doesn't comes with it. (I know I can use apt-get gksu but at the moment, downloading it from internet is not an option).

Is there anyway that I can change the permission to my Apache2 server root directoy so that I can use any text editor to save/edit to that directory directly. Only the ways that do not need downloading stuffs from internet are feasiable for me at the moment.

You can set the DocumentRoot in your /etc/apache2/httpd.conf file to a place where Apache has write access. For example, you could set it to /tmp/www if you made a directory there. (If you still don't have access, you can always give everyone read access by running chmod a+r /tmp/www , but you should probably be fine.)

Obviously leaving your Apache Document Root as /tmp/www is a bad idea, so you can change it to something like /home/chris once you've got it working.

One important note: after you make a change like this, you must restart the Apache server. This can be done by running apachectl restart ; ironically, you might have to have administrator rights in order to execute this (or even edit the config file in the first place), so make sure you prefix your edit & restart with sudo just in case.

For linux open the terminal with root login then go to the root folder and run the following command chmod 777 following is the example :-

To change all the directories to 777 (-rwxr-rwxr-rwxr):

find /opt/lampp/htdocs -type d -exec chmod 777 {} \\;

To change all the files to 644 (-rwxr-rwxr--rwxr--):

find /opt/lampp/htdocs -type f -exec chmod 777 {} \\;

If this will not work then try the following :-

Create a new group

groupadd webadmin

Add your users to the group

usermod -a -G webadmin user1 usermod -a -G webadmin user2

Change ownership of the sites directory

chown root:webadmin /var/www/html/

Change permissions of the sites directory

chmod 2775 /var/www/html/ -R

Now anybody can read the files (including the apache user) but only root and webadmin can modify their contents.

Hope this will help you in solving your problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM