解决apache (php)开发中root权限目录文件不能编辑的两个方法

来源:互联网 发布:cc2530中文数据手册 编辑:程序博客网 时间:2024/05/18 02:26
解决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$ 
原创粉丝点击