Visting一个laravel项目与本地主机通过Apache [英] Visting a laravel project with localhost via apache
问题描述
我刚刚安装了一个laravel项目到我的文件夹中。我给它一个名字,让我们把它叫做
laravel
用于这一目的。因此,安装到模板主页/的public_html / laravel
然后我跑了作曲安装
。我有一个数据库密码错误。我固定的,再运行它,一切都很顺利。然后,我创建了一个迁移,控制器和视图。我试图通过的本地主机/ laravel /公/事件的(事件是我创建的视图),我收到了404。我记得我需要一个配置文件中的等/ Apache2的导航到它/站点可用
我创建了这种结构的配置文件:
I have just installed a laravel project into my Home/public_html
folder. I gave it a name, let's call it laravel
for this purpose. So the template installed to Home/public_html/laravel
and then I ran a composer install
. I got a database password error. I fixed that, ran it again, and all went well. I then created a migration, a controller, and a view. I tried to navigate to it via localhost/laravel/public/events (events is my created view) I get a 404. I remembered I needed a config file in etc/apache2/sites-available
I created the config file with this structure:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /home/user/public_html/laravel/public/
<Directory /home/user/public_html/laravel/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/laravel-error.log
CustomLog ${APACHE_LOG_DIR}/laravel-access.log combined
</VirtualHost>
然后,我创建了一个符号链接
到启用的站点 -
文件夹中。这并没有帮助。
然后,我浏览到本地主机/ laravel
键,它只是给我的目录结构。
I then created a symlink
into the sites-enabled
folder. That didn't help.
I then navigated to localhost/laravel
and it just gives me the directory structure.
什么我错过了?我做了什么错?
What have I missed? What have I done wrong?
我在的public_html
另一个文件夹与工程完美自己的配置文件(它指向,它也有一个符号。有什么在每个项目中,告诉使用哪个配置的项目吗?他们只是工作?我这方面的知识真的停在这里。基本上,我已经用尽了我知道了。我是什么我缺少/做错了吗?
I have another folder inside public_html
with its own config file that works perfectly (it points to home/user/public_html/
. It also has a symlink. Is there something in each project that tell the project which config to use? Do they just work? My knowledge of this really stops here. Basically, I've exhausted what I know. What am I missing/doing wrong?
呵呵,我已经重新启动Apache的为好。 - 通过步骤几次我只是详细
Oh and I have restarted apache as well. - a couple of times through the steps I just detailed.
推荐答案
揭露Laravel安装目录到Web服务器是不是一个好主意。既然你可以访问 laravel
文件夹中的文件清单,我相信你的文档根目录设置为 / home / user中/的public_html
。
Exposing the Laravel instalation to the web server is never a good idea. Since you can access the file listing of the laravel
folder, I believe your document root is set to /home/user/public_html
.
更好的方法来解决这个问题将是如下:
Better approach to solve this problem will be as follows.
-
请整个laravel安装
的public_html
目录之外。让我们假定在/家庭/用户/开发
Keep entire laravel installation outside
public_html
directory. Let's assume inside/home/user/development
您可能需要添加以下到下面的Apache配置的DocumentRoot
。
You may need to add following to the apache configuration below DocumentRoot
.
Alias /laravel /home/user/development/laravel/public
添加以下目录
配置
<Directory /home/user/development/laravel/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
添加以下内容的.htaccess
在 /家庭/用户/开发文件/ laravel /公/
下面 RewriteEngine叙述
规则。
RewriteBase /laravel
重新启动的Apache2服务器,您的网站应该可以在localhost / laravel。确保没有命名的文件夹 laravel
的里面的public_html
文件夹中。
Restart the apache2 server, your site should be available on localhost/laravel. Make sure there are no folder named laravel
inside the public_html
folder.
这篇关于Visting一个laravel项目与本地主机通过Apache的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!