13 php settings document localhost root
我正在为一个有网站的人做一份工作.对我来说这是一个异类网站,我正在慢慢地研究这些奇怪的代码.我在本地有MAMP,我的http:// localhost /有很多客户端文件夹.在这段代码中有很多$ _SERVER ['document_root']命令和引用
这些只是迷失在我当地的PHP开发区域.
我怎样才能轻松地将document_root引用设置为它应该是什么(只是在本地,但实际上并不想弄乱网站文件,因为我需要再次上传它们而不想破坏实时网站!是否存在间接设置的方式,PHP认为网站的根目录是这样的,图像的src引用"/ images/..."将正确显示...我的本地PHP开发网址为:http:// localhost:8888/_CLIENTS/clientsite/www / ...但在代码中'/ images/...'开头的'/'引用了http:// localhost:8888 / ??
谢谢.
@Eddie的答案对我帮助很大,但我还是要做一些额外的研究,以便在OSX上使用XAMPP来解决同样的问题.为了后代的利益,我想我会在这里添加我的完整解决方案.
首先,我将以下条目添加到httpd-vhosts.conf(在XAMPP中的"etc/extra /"文件夹下):
NameVirtualHost *:80
<VirtualHost *:80>
ServerName localhost
DocumentRoot "/Applications/xampp/xamppfiles/htdocs/"
</VirtualHost>
<VirtualHost *:80>
ServerName client1.my-machine
DocumentRoot "/Applications/xampp/xamppfiles/htdocs/clients/client1/"
</VirtualHost>
<VirtualHost *:80>
ServerName client2.my-machine
DocumentRoot "/Applications/xampp/xamppfiles/htdocs/clients/client2/"
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
请注意,我专门为VirtualHost网址使用了通配符而不是"localhost",并在我指定每个子域名的位置添加了ServerName配置.另请注意,我使用了我的机器名称("my-machine")而不是"localhost" - 这样就可以正确评估来自任何机器(不仅仅是localhost)的所有请求.我在OSX中开发,但通过Parallels在各种VM中测试浏览器.使用这种方法,我可以从网络上的任何计算机或VM 访问http://client1.my-machine.指定"localhost"后,它只能在我的开发机器上运行.
注意:第一个VirtualHost条目用作默认值(如此处所述:http://httpd.apache.org/docs/2.2/vhosts/name-based.html)并且是必需的,以便请求不会默认为自定义网站.
我还将权限设置添加到httpd.conf,如@ Eddie的回答所示.这并不总是必需的,但我遇到了两个不同的情况,我需要进行此更改:
AllowOverride选项的注释会使错误的原因显而易见,但我之前忽略了这一点.将此更改为"全部"可修复错误.请注意,在编辑httpd.conf时,您可能需要取消注释以下行(默认情况下它已被注释掉),或者上面的vhosts更改将不会生效:
# Virtual hosts
Include /Applications/xampp/etc/extra/httpd-vhosts.conf
Run Code Online (Sandbox Code Playgroud)
最后,我还必须将自定义域名添加到我的hosts文件中,如上面的注释中所述.在OSX上,您可以通过编辑"/ private/etc/hosts"(在Windows上这将是"Windows/System32/drivers/etc/hosts")并添加以下行:
127.0.0.1 my-machine
127.0.0.1 client1.my-machine
127.0.0.1 client2.my-machine
Run Code Online (Sandbox Code Playgroud)
注意:在默认的OSX Finder UI中,隐藏文件夹(包括/ private)不可见.您可以通过黑客内部Finder选项(Google了解详细信息)永久更改此内容,或者更简单地进行偶尔更改,只需使用"转到>转到文件夹"菜单选项,即可直接按名称打开隐藏文件夹.就个人而言,我使用一个名为PathFinder的第三方OSX shell ,我衷心推荐(值得小额许可费).它包括一个隐藏/显示隐藏文件的菜单选项,以及许多其他有用的功能.
有一点拖累是我还必须在我的Windows VM主机文件中添加指向我的物理开发机器的匹配条目,以便通过Apache/OSX解析URL:
192.168.1.5 client1.my-machine
192.168.1.5 client2.my-machine
Run Code Online (Sandbox Code Playgroud)
我不需要单独的机器名称条目(自动解析),但是如果没有这些主机条目,则向其添加子域名无法正确解析.这确实很糟糕,有时我的Mac的IP改变(通过DHCP),但这是一个小麻烦.我会假设我可以设置它不需要那些IP,但我无法弄明白并准备继续前进:)(如果有人知道答案请发表评论)
现在我有多个客户端站点在一个地方运行,可以从我的所有开发/测试环境中访问.希望这有助于其他人.
我推荐的是vhosts,这样你就可以在本地提供"外星人站点"而不会弄乱你的默认Web服务器.
NameVirtualHost localhost:80
# the mysql tool's url
<VirtualHost phpmyadmin.localhost:80>
# and absolute path
DocumentRoot "/srv/www/phpMyAdmin/"
</VirtualHost>
#Same for the Client Site
<VirtualHost foo.localhost:80>
DocumentRoot "/path/to/desired/webroot/"
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
您可以通过首先指定以下内容来控制权限并设置整体全局网站
DocumentRoot "/srv/www/htdocs"
#
# Configure the DocumentRoot Properties
#
<Directory "/srv/www/htdocs">
Options All
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
AllowOverride All
# Controls who can get stuff from this server.
Order allow,deny
Allow from all
</Directory>
#
# Configure Sub-Domain Properties. This prevents those nasty 403 errors
#
# mysql administration tool
<Directory "/srv/www/phpMyAdmin/">
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>
# a client web site built with CakePHP
<Directory "/home/eddie/workspace/Digital_Business/app/webroot/">
Options All
AllowOverride All
Order allow,deny
Allow from all
</Directory>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
66336 次 |
| 最近记录: |