【发布时间】:2020-08-08 23:50:18
【问题描述】:
laravel 项目在 OpenServer localhost 的 "http://localhost/public/ 文件夹中不起作用。然而,它与 localhost/8000 上的 php artisan 服务器配合得很好。但我需要在我的本地主机中使用该项目并进行进一步部署。[
外观截图
【问题讨论】:
-
启用调试,以便您了解遇到错误 500 的原因
laravel 项目在 OpenServer localhost 的 "http://localhost/public/ 文件夹中不起作用。然而,它与 localhost/8000 上的 php artisan 服务器配合得很好。但我需要在我的本地主机中使用该项目并进行进一步部署。[
外观截图
【问题讨论】:
您需要按照Laravel documentation/ web server configuration 中的说明配置服务器。
如果您想将 apache 配置为您的服务器,您应该在 /etc/apache2/site-available/000-default.conf 中添加以下行
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/{user}/{project_root}/public
ServerName example.local
ServerAlias www.example.local
<Directory /home/{user}/{project_root}/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/example_error.log
CustomLog ${APACHE_LOG_DIR}/example_access.log combined
</VirtualHost>
在{user} 中插入您的用户名,在{example} 中插入您想要的域。
然后,运行 sudo a2enmod rewrite 和 sudo systemctl restart apache2。
之后,将/etc/hosts 中的 ip 添加到您想要的域,如下所示:
127.0.0.1 example.local
【讨论】:
本地主机允许访问您的
htdocs 文件夹 (如果使用 xamp)
www 文件夹 (正在使用 wamp)
您还需要在您的网址中添加项目名称
例子:
http://localhost/<project_name>/public
【讨论】: