如何在浏览器中访问我的 zend 项目?

发布于 2024-11-05 00:44:13 字数 1445 浏览 0 评论 0原文

我在 /var/www/ 中创建了一个项目 student 但我无法使用虚拟热点访问它。

zf.sh create prohect student

我在 /etc/apache2/sites-available 中创建了一个文件 student ,如下所示:

<VirtualHost *:80>
        ServerName student.dev
        ServerAlias student.dev
        DocumentRoot /var/www/student/public/
</VirtualHost>

然后我在终端中运行此文件:

sudo a2ensite student

我在 /etc/hosts 中有以下行

127.0.0.1    student.dev

重新启动 apache 服务器后:

sudo /etc/init.d/apache2 restart

但是当我在浏览器中访问 http://student.dev/ 时,它给我以下错误:

The server encountered an internal error or misconfiguration and was unable to complete your request.

但是当我访问 http://localhost/student/public/index.php 直接然后它就显示我欢迎成功,就像这样

Welcome to the Zend Framework!
This is your project's main page

编辑:

公共文件夹中的.htaccess文件

SetEnv APPLICATION_ENV development

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

I created a project student in /var/www/ But I am unable to access it using virtual hots.

zf.sh create prohect student

I created a file student in /etc/apache2/sites-available like this:

<VirtualHost *:80>
        ServerName student.dev
        ServerAlias student.dev
        DocumentRoot /var/www/student/public/
</VirtualHost>

Then I run this in terminal:

sudo a2ensite student

I have following line in /etc/hosts

127.0.0.1    student.dev

After I restarted the apache server:

sudo /etc/init.d/apache2 restart

But when I access http://student.dev/ in browser it gives me following error:

The server encountered an internal error or misconfiguration and was unable to complete your request.

But when I access http://localhost/student/public/index.php directly then it shows me Welcome successfully like this

Welcome to the Zend Framework!
This is your project's main page

Edit:

.htaccess file in public folder

SetEnv APPLICATION_ENV development

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

静谧 2024-11-12 00:44:13

您的虚拟主机配置中缺少 配置。

您的配置必须如下所示:

<VirtualHost *:80>
    ServerName student.dev
    DocumentRoot /var/www/student/public/
    <Directory /var/www/student/public/>
        AllowOverride All
    </Directory>
</VirtualHost>

AllowOverride 设置告诉 apache 公共目录中的 .htaccess 文件可能会覆盖常规设置。

You're missing the <Directory> configuration in your vhost config.

Your config has to look like that:

<VirtualHost *:80>
    ServerName student.dev
    DocumentRoot /var/www/student/public/
    <Directory /var/www/student/public/>
        AllowOverride All
    </Directory>
</VirtualHost>

The AllowOverride setting tells apache that .htaccess files in your public directory may override the general settings.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文