Laravel 5 / Apache 2.4.9配置问题

时间:2015-12-17 04:46:46

标签: php apache .htaccess mod-rewrite laravel-5

我正在尝试在CentOS全新服务器上安装和配置Laravel 5.

但我恐怕没有足够的知识来理解和解决我的环境有什么问题。因此,我将尝试尽可能准确地描述我的实际设置和问题。

让我们从Apache 2.4.9开始

httpd.conf中的所有内容几乎都是默认的。我刚刚编辑了文档根路径,直接指向未来的laravel公共文件夹:

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#

DocumentRoot "/usr/local/apache/htdocs/public"
<Directory "/usr/local/apache/htdocs/public">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.4/mod/core.html#options
    # for more information.
    #
    Options -Indexes -FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
#   AllowOverride FileInfo AuthConfig Limit
#
AllowOverride None

#
# Controls who can get stuff from this server.
#
Require all granted

在你问之前,是的,启用了mod_rewrite模块。

然后我的PHP也有基本配置,它的版本是5.6.15。

然后我安装了composer并用它来创建一个新的laravel项目

composer create-project laravel/laravel {directory} "~5.0.0" --prefer-dist

一切顺利运行,没有任何问题。

但是现在我尝试通过输入我的服务器IP地址来访问我刚安装的laravel应用程序,但它只显示一个空白页面,如果我检查控制台,它会给我一个500错误。

所以我的目的是为了解决问题:

  1. 我在laravel博客上发现了一个帖子,说我们应该完全拥有我所做的/ storage文件夹,现在我不再有白页了,而是我有:'哎呀错误的'错误。

  2. 我尝试在官方laravel doc上建议的备用.htaccess配置文件 - 没有改变

  3. 我不知道为什么我这样做了,但我运行了php artisan serve命令,现在我看到了Laravel欢迎页面......即使我退出服务模式,它仍然运行?!?我不确定我是否明白为什么,但即使我这样做也没有完全起作用...我只得到欢迎页面但如果我尝试http://my-ip-address/home它会显示我找不到404。

  4. 我觉得我到处都搜索但是我找不到答案而且我接近了抑郁症。这里有人有关于我的问题的任何线索吗?

    感谢任何可以帮助我的人!

    @ 更新

    抱歉,我忘记了服务器日志:

        [2015-12-17 04:22:03] production.ERROR: exception 'ReflectionException' with message 'Class encrypter does not exist' in /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php:776
    Stack trace:
    #0 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(776): ReflectionClass->__construct('encrypter')
    #1 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(656): Illuminate\Container\Container->build('encrypter', Array)
    #2 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(613): Illuminate\Container\Container->make('encrypter', Array)
    #3 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(887): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
    #4 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(848): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter))
    #5 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(813): Illuminate\Container\Container->getDependencies(Array, Array)
    #6 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(656): Illuminate\Container\Container->build('Illuminate\\Cook...', Array)
    #7 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(613): Illuminate\Container\Container->make('Illuminate\\Cook...', Array)
    #8 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(127): Illuminate\Foundation\Application->make('Illuminate\\Cook...')
    #9 /usr/local/apache/htdocs/public/index.php(57): Illuminate\Foundation\Http\Kernel->terminate(Object(Illuminate\Http\Request), Object(Symfony\Component\HttpFoundation\Response))
    #10 {main}
    [2015-12-17 04:22:03] production.ERROR: exception 'ErrorException' with message 'file_put_contents(/usr/local/apache/htdocs/vendor/services.json): failed to open stream: Permission denied' in /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Filesystem/Fi$
    Stack trace:
    #0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'file_put_conten...', '/usr/local/apac...', 74, Array)
    #1 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(74): file_put_contents('/usr/local/apac...', '{\n    "provider...', 0)
    #2 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php(193): Illuminate\Filesystem\Filesystem->put('/usr/local/apac...', '{\n    "provider...')
    #3 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php(139): Illuminate\Foundation\ProviderRepository->writeManifest(Array)
    #4 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php(59): Illuminate\Foundation\ProviderRepository->compileManifest(Array)
    #5 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(439): Illuminate\Foundation\ProviderRepository->load(Array)
    #6 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/RegisterProviders.php(15): Illuminate\Foundation\Application->registerConfiguredProviders()
    #7 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(167): Illuminate\Foundation\Bootstrap\RegisterProviders->bootstrap(Object(Illuminate\Foundation\Application))
    #8 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(195): Illuminate\Foundation\Application->bootstrapWith(Array)
    #9 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(106): Illuminate\Foundation\Http\Kernel->bootstrap()
    

    这是我得到的2个错误。

3 个答案:

答案 0 :(得分:0)

抱歉,我无法添加评论。

我想你可能会错过php-mcrypt扩展程序。

答案 1 :(得分:0)

首先使用以下命令为laravel 5.1应用程序生成密钥。 例如 $ php artisan key:generate 应用程序密钥[Idgz1PE3zO9iNc0E3oeH3CHDPX9MzZe3]设置成功。

现在复制此密钥并将其粘贴到yourproject / config / app.php

'key' => 'Idgz1PE3zO9iNc0E3oeH3CHDPX9MzZe3',

答案 2 :(得分:0)

试试这个:

sudo chmod 775 /usr/local/apache/htdocs/vendor/services.json