多次尝试修复后,虚拟主机在Zend Framework中无法运行

时间:2014-12-16 20:33:25

标签: zend-framework virtual host

在site-available和sites-enabled文件夹中,我有一个名为" zend-framework.conf"的conf文件。这就是我在文件中包含的内容。

 <VirtualHost *:80>
     # The ServerName directive sets the request scheme, hostname and port that
     # the server uses to identify itself. This is used when creating
     # redirection URLs. In the context of virtual hosts, the ServerName
     # specifies what hostname must appear in the request's Host: header to
     # match this virtual host. For the default virtual host (this file) this
     # value is not decisive as it is used as a last resort host regardless.
     # However, you must set it for any further virtual host explicitly.
     ServerName zendlocalhost
     ServerAlias zendlocalhost
     ServerAdmin root@localhost
     DocumentRoot /var/www/zend-framework/public
     SetEnv APPLICATION_ENV "development"
     <Directory /var/www/zend-framework/public>
         DirectoryIndex index.php
         AllowOverride All
         Order allow,deny
         Allow from All
     </Directory>

     # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
     # error, crit, alert, emerg.
     # It is also possible to configure the loglevel for particular
     # modules, e.g.
     #LogLevel info ssl:warn

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined

     # For most configuration files from conf-available/, which are
     # enabled or disabled at a global level, it is possible to
     # include a line for only one particular virtual host. For example the
     # following line enables the CGI configuration for this host only
     # after it has been globally disabled with "a2disconf".
     #Include conf-available/serve-cgi-bin.conf 
</VirtualHost>

#vim:syntax = apache ts = 4 sw = 4 sts = 4 sr noet

这就是我在etc / hosts文件中的内容

127.0.0.1   localhost
#127.0.1.1  lazerorca-iMac
127.0.0.1   zendlocalhost

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

这就是我在ports.conf文件中的内容。我收到一条消息,说明NameVirtualHost *:80将在以后的版本中弃用。我尝试添加它只是因为我在另一个问题中看到了它

# If you just change the port or add more ports here, you will likely also
# have to change the VirtualHost statement in
# /etc/apache2/sites-enabled/000-default.conf

Listen 80

<IfModule ssl_module>
 Listen 443
</IfModule>

<IfModule mod_gnutls.c>
 Listen 443
</IfModule>

NameVirtualHost *:80

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

这是我去http://zendlocalhost

时得到的错误
  

内部服务器错误

     

服务器遇到内部错误或配置错误   无法完成您的请求。

     

请与root @ localhost的服务器管理员联系以告知   它们发生此错误的时间以及您执行的操作   就在这个错误之前。

     

有关此错误的详细信息可能在服务器错误中可用   日志中。

这就是access.log所说的

  

127.0.0.1 - - [16 / Dec / 2014:15:05:22 -0500]&#34; GET / HTTP / 1.1&#34; 500 798&#34; - &#34; &#34; Mozilla / 5.0(X11; Ubuntu; Linux i686; rv:35.0)Gecko / 20100101   火狐/ 35.0&#34;

这就是error.log所说的

  

[Tue Dec 16 15:25:20.271792 2014] [core:alert] [pid 4825] [客户   127.0.0.1:60826] /var/www/zend-framework/public/.htaccess:无效命令&#39; RewriteEngine&#39;,可能拼写错误或由模块定义   包含在服务器配置中

我检查.htaccess文件,它对我来说没问题,但显然它不是。这是.htaccess文件中的内容

RewriteEngine On
# The following rule tells Apache that if the requested filename
# exists, simply serve it.
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
# The following rewrites all other queries to index.php. The 
# condition ensures that if you are using Apache aliases to do
# mass virtual hosting, the base path will be prepended to 
# allow proper resolution of the index.php file; it will work
# in non-aliased environments as well, providing a safe, one-size 
# fits all solution.
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

有趣的是,如果我去http://zendlocalhost/phpmyadmin它会拉起来 如果我转到127.0.0.1,它会提取通用的Ubuntu apache index.html文件 我是Zend的新手,因为这是我第一次尝试它。我知道有一些疯狂的URL重写等。我本以为去根地址会拉起index.php文件。

提前感谢您的帮助

1 个答案:

答案 0 :(得分:0)

Apache并不了解你的.htaccess中的第一个指令RewriteEngine。这意味着未启用mod_rewrite。如果您使用的是Ubuntu,请运行sudo a2enmod rewrite,然后重新启动Apache并重试。