我已经拖网了几天,现在想我已经尝试了几乎所有的东西,以获得在我的Ubuntu服务器上设置一些虚拟主机,但在webroot上的所有短chmod 777失败。
我有我的默认Apache conf指向/ home / server / public_html与下面的设置显示
<VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /home/server/public_html/ <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /home/server/public_html/> Options Indexes FollowSymLinks MultiViews AllowOverride All 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 Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from all </Directory> </VirtualHost>
然后,我为我正在开发的一个项目创build了一个虚拟主机,比如说project.name.co.uk.conf,里面有以下内容
<VirtualHost *:80> ServerName http://www.local.dirty-briefs.co.uk ServerAlias local.project-name.co.uk DocumentRoot /home/server/public_html/project-name/ DirectoryIndex index.php index.html </VirtualHost>
然后我运行sudo a2ensite project.name.co.uk.conf 。 我正在使用samba在Windows 7机器上访问服务器上的文件。 我添加了project.name.co.uk到我的Windows主机文件,但无论我做什么,我得到403权限错误。
思想ID添加Apache错误日志的尾巴,以防万一它有用
*==> /var/log/apache2/error.log <== [Sat Jun 11 13:22:23 2011] [error] [client 192.168.0.3] PHP Warning: require(/home/server/public_html/dirty-briefs/site/protected/config/main.php): failed to open stream: Permission denied in /home/server/public_html/dirty-briefs/framework/base/CApplication.php on line 120 [Sat Jun 11 13:22:23 2011] [error] [client 192.168.0.3] PHP Fatal error: require(): Failed opening required '/home/server/public_html/dirty-briefs/site/protected/config/main.php' (include_path='.:/usr/share/php:/usr/share/pear') in /home/server/public_html/dirty-briefs/framework/base/CApplication.php on line 120*
这也可能是值得一提的我正在Yii的PHP框架我有一个.htaccess文件,住在我的网站文件夹与以下内
# Disable directory browsing Options All -Indexes # File types AddType application/x-font-woff .eot .ttf # Font-Face # URL Rewriting <IfModule mod_rewrite.c> RewriteEngine On # Site Maintenance # RewriteCond %{REMOTE_ADDR} !^10\.0\.2\.2 # RewriteCond %{REQUEST_FILENAME} !-f # RewriteRule ^(.*)$ /maintenance.html [L] # LOCAL RewriteCond %{SERVER_NAME} ^local.project-name.co.uk RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /index-local.php/$1 # ----- # PRODUCTION RewriteCond %{HTTP_HOST} ^project-name.co.uk RewriteRule ^(.*)$ http://www.project-name.co.uk/$1 [R=301,L] RewriteCond %{SERVER_NAME} ^www.project-name.co.uk RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /folder/index.php/$1 # ----- </IfModule>
我尾巴的Apache错误和访问日志,发现由于权限错误导致我的PHP脚本内导入文件烫发错误。
我已经阅读有关检查什么用户和组运行Apache下,这是万维网数据www数据,所以我猜测Apache基本上没有烫发访问/ home / server / public_html下的文件,除非我给文件夹777烫发,我不想要,所以我只是想知道如果任何人都可以发现我做错了什么或build议任何事情,我可以尝试得到这个工作
这个文件夹布局是一个混乱的问题。 您的默认vhost指令将/home/server/public_html/指定为DocumentRoot ,但是您将其指定为应用程序根目录的子文件夹 。 这不是一个最佳的configuration。 尝试将网站移出public_html到自己的文件夹( /home/server/project或somesuch),并相应地设置DocumentRoot 。
一旦它被移动,你不需要777权限,使其可访问,虽然它需要www-data可读。 尝试:
chmod -R 644 /home/server/project find /home/server/project -type d -exec chmod 755 {} \+
这将使一切世界可读,所有的文件夹可以穿越(设置文件夹上的执行位做到这一点)。
另一件事: ServerName不使用http://前缀。 你应该从configuration中删除,只留下域名。
更改后重新启动您的Apache,您应该能够到达与您的主机名称的网站。
您可以让Apache有权访问这些文件,而不必将其设置为“万能的一切”(rwxrwxrwx或777),您只需授予它读取文件的权限,以便PHP可执行文件可以读取它们。 如果PHP检查,你可能也需要给予执行权限。 更好的办法是用chown www-data:www-data <file>改变所有权chown www-data:www-data <file>然后你可以给Apache完全的权限,并且没有权限给chmod 700 (或者chmod u+rwx <file>; chmod go-rwx <file>如果你喜欢使用助记码而不是基于位模式的)。
如果你有其他网站从同一个Apache安装(也运行www-data运行),并希望保持它们分开一个网站在一定程度上受到其他人的保护,然后看看使用suPHP ( 由此提供在Ubuntu中包 )。 它比bog标准的mod_php效率低(虽然不是很多,除非你的硬件受到严格限制),但是通过使用户/站点之间(无意或无意)互相影响,给用户/站点提供了额外的保护层或者读对方的东西。 每个脚本都由一个充当拥有它的用户的进程运行,所以user1所拥有的php文件以user1运行,并且没有其他用户(即使是www数据或通常运行的脚本)也需要访问它。 您可能会遇到suphp中的其他权限错误,直到您将事情设置正确为止,因为在运行任何脚本之前,默认情况下都会强制执行某些安全检查(如目录和脚本不是世界可写的)。
PS。 require(/home/server/public_html/dirty-briefs/site/protected/config/main.php): failed : require(/home/server/public_html/dirty-briefs/site/protected/config/main.php): failed – 咖啡染色会议简报,还是别的?
您可能需要在/home/server上执行访问,以便Apache用户可以遍历它来读取public_html文件夹(这应该是其他可读的)。
# If not already drwx--x--x... chmod o+x /home/server
这可能是一个selinux问题。
编辑:
要确定你可以设置seLinux为宽容模式,然后再试一次。 如果你在RedHat上工作,我会推荐使用system-config-selinux,但是我不知道在Ubuntu上有一个工具