解决apache (php)开发中root权限目录文件不能编辑的两个方法
方法一. 更改/var/www$ Owner 即可时用当前用户编辑(但是文件目录还是在原来的目录)
hulk@hulk-Lenovo:/var/www$ sudo chown -R hulk:hulk ./
hulk@hulk-Lenovo:/var/www$ cd /etc/apache2/sites-
sites-available/ sites-enabled/
方法二. 更改/var/www$ 为用户自己的目录,可在自己的home下的目录中新建dir.
具体办法:
1. 再自己的home中新建文件夹:mkdir /home/hulk/htdocs
2. 修改文件/etc/apache2/sites-enabled/000-default
<VirtualHost *:80>
ServerAdmin webmaster@localhost
#原来是/var/www/, 改成:
DocumentRoot /home/hulk/htdocs
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
#原来是/var/www/, 改成:
<Directory /home/hulk/htdocs/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
保存退出,可以用vim来编辑.
3. 重启apache服务器:
sudo /etc/init.d/apache2 restart
* Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[ OK ]
完成,大家可以再自己的目录下编辑文件index.php,还是访问之前的localhost地址: http://127.0.0.1/index.php (可以是其他任意php文件)
hulk@hulk-Lenovo:/var/www$ cd /etc/apache2/sites-enabled/
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$ ls
000-default
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$ sudo vim 000-default
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$ sudo /etc/init.d/apache2 restart
* Restarting web server apache2 Warning: DocumentRoot [/home/hulk/htdocs] does not exist
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting Warning: DocumentRoot [/home/hulk/htdocs] does not exist
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[ OK ]
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$ mkdir /home/hulk/htdocs
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$ sudo /etc/init.d/apache2 restart
* Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[ OK ]
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$ vim /home/hulk/htdocs/index.php
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$ vim /home/hulk/htdocs/index.php
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$
方法一. 更改/var/www$ Owner 即可时用当前用户编辑(但是文件目录还是在原来的目录)
hulk@hulk-Lenovo:/var/www$ sudo chown -R hulk:hulk ./
hulk@hulk-Lenovo:/var/www$ cd /etc/apache2/sites-
sites-available/ sites-enabled/
方法二. 更改/var/www$ 为用户自己的目录,可在自己的home下的目录中新建dir.
具体办法:
1. 再自己的home中新建文件夹:mkdir /home/hulk/htdocs
2. 修改文件/etc/apache2/sites-enabled/000-default
<VirtualHost *:80>
ServerAdmin webmaster@localhost
#原来是/var/www/, 改成:
DocumentRoot /home/hulk/htdocs
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
#原来是/var/www/, 改成:
<Directory /home/hulk/htdocs/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
保存退出,可以用vim来编辑.
3. 重启apache服务器:
sudo /etc/init.d/apache2 restart
* Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[ OK ]
完成,大家可以再自己的目录下编辑文件index.php,还是访问之前的localhost地址: http://127.0.0.1/index.php (可以是其他任意php文件)
hulk@hulk-Lenovo:/var/www$ cd /etc/apache2/sites-enabled/
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$ ls
000-default
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$ sudo vim 000-default
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$ sudo /etc/init.d/apache2 restart
* Restarting web server apache2 Warning: DocumentRoot [/home/hulk/htdocs] does not exist
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting Warning: DocumentRoot [/home/hulk/htdocs] does not exist
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[ OK ]
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$ mkdir /home/hulk/htdocs
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$ sudo /etc/init.d/apache2 restart
* Restarting web server apache2 apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
[ OK ]
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$ vim /home/hulk/htdocs/index.php
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$ vim /home/hulk/htdocs/index.php
hulk@hulk-Lenovo:/etc/apache2/sites-enabled$
本文提供两种解决Apache(php)开发中因root权限导致无法编辑文件的问题的方法:一是更改文件所有者;二是将/var/www替换为用户的个人目录,并通过修改Apache配置文件实现。
1050

被折叠的 条评论
为什么被折叠?



