简体   繁体   中英

Laravel 5 / Apache 2.4.9 Configuration problems

I am trying to install and configure Laravel 5 on a CentOS brand new server.

But I am afraid I don't have enough knowledge to understand and fix what is wrong with my environment. So I will try to describe as accurate as I can my actual setup and problems.

Let's start with Apache 2.4.9

Everything in the httpd.conf is almost default. I just edited the document root path to point directly at the future laravel public folder:

#
# 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

And before you ask, yes the mod_rewrite module is enabled.

Then my PHP also has basic configuration and it's version is 5.6.15.

Then I installed composer and used it to create a new laravel project

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

Everything successfully ran with no issues.

But now I try to visit my freshly installed laravel app by entering my server IP address but it only displays a blank page and if I check the console it gives me an 500 error.

So here is in order what I did to try to fix the problem:

  1. I found a post on the laravel blog that said we should give full right to the /storage folder which I did and now I don't have a white page anymore but instead I have the: 'whoops something went wrong' error.

  2. I try the alternate .htaccess config file suggested on the official laravel doc - nothing changed

  3. I don't why exactly I did this but I ran the php artisan serve command and now I see the Laravel welcome page... even if I exit the serve mode it still runs ?!? I am not sure if I understand why but even if I did it actually doesn't work completely... I only get the welcome page but if I try http://my-ip-address/home it shows me a 404 not found.

I feel like I have searched everywhere but yet I couldn't find an answer and I am close to the depression. Does anyone here has any clues about my problem ?

Thanks to anyone who can help me with this !

@ update

Sorry I forgot the server logs:

    [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()

This is the 2 errors I get.

Sorry I couldn't add a comment.

I think you might be missing the php-mcrypt extension.

First generate key for laravel 5.1 application using below command. eg $ php artisan key:generate Application key [Idgz1PE3zO9iNc0E3oeH3CHDPX9MzZe3] set successfully.

Now copy this key and paste it in yourproject/config/app.php

'key' => 'Idgz1PE3zO9iNc0E3oeH3CHDPX9MzZe3',

尝试这个:

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

Sorry, I haven't replied during the weekend, I was a bit busy.

Everybody had a bit of right in their answers. It was definetlely directories permission problem. I haven't found yet the perfect level of permission because I am not an expert. But I can tell you if I chmod -R 777 /storage /vendor and /public it works.

I know chmod 777 is probably insecure but I am really not an expert in permissions..

But anyway I'll mark this answer as solved because I indeed solved my problem in a way :)

But if anybody has a better answer or would like to give a more detailled explanation I'll update this post or mark the best answer as solved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM