List of project directories in Laravel is displayed instead of running the application [duplicate]

6

I would like your help to know why my PHP project with the Laravel Framework does not work, I have done all the steps correctly, but instead of seeing the framework, I am seeing your folders

    
asked by anonymous 11.10.2015 / 04:39

1 answer

8
  

Note that the instructions given here are made based on Laravel 5.1, and may or may not work in Laravel 4.2

The folder you have to access is public (I also confused myself the first time I used laravel), this is a common problem among most people who use Laravel first time.

Laravel in development environment

You have 3 options:

  • Use server.php which is a script to run php in stand-alone mode (without apache), to access the terminal and go to the folder of your project in Laravel:

    $ cd /home/user/projeto-em-laravel
    $ php -S localhost:8000 server.php
    
  • Configure Apache to point to the public folder of Laravel (you can configure a virtualhost as well)

    DocumentRoot "/home/user/projeto-em-laravel/public"
    <Directory "/home/user/projeto-em-laravel/public">
        AllowOverride all
    </Directory>
    
  • Configure a .htaccess in the ./projeto-em-laravel folder to point everything to the ./projeto-em-laravel/public/ folder, create the ./projeto-em-laravel folder in the .htaccess folder and put this content in it:

    <IfModule mod_rewrite.c>
      RewriteEngine On
    
      RewriteRule ^ /projeto-em-laravel/index.php [L]
    </IfModule>
    
  • If it is a production environment

    In case of a production environment do not use server.php (even though I think it would be almost impossible), being Apache you can try step 2 or 3 already mentioned in However if the server which will install laravel does not give you control over apache, then try to follow this:

  • Usually the servers have a folder called public_html or www if access by cpanel (if it is the case) in other cases the folder where to play the files is the name of the site, for example ./www.meusite.com .

  • In these cases you should try step 3 then you will throw all the content (just the content) of the projeto-em-laravel folder into the public_html folder for example and you should create a .htaccess file equal to step 3, structure should look like this:

    ./public_html
       |--- .htaccess
       |--- /public
              |--- index.php
              |--- .htaccess
       |--- /app
       |--- /bootstrap
       |--- /config
       |--- /database
    
  • There are developers who simply play the contents of the projeto-em-laravel out folder of public_html and in public_html they put content ./projeto-em-laravel/public , this is an option too, more You may end up getting lost with the existing server folders, something like:

    /home/user/
       |--- /access-logs     (pasta padrão em servidores com cpanel)
       |--- /etc             (pasta padrão em servidores com cpanel)
       |--- /public_ftp      (pasta padrão em servidores com cpanel)
       |--- /tmp             (pasta padrão em servidores com cpanel)
       |--- /public_html     (pasta padrão em servidores com cpanel)
              |--- index.php (arquivo da pasta /public)
              |--- .htaccess (arquivo da pasta /public)
       |--- /app             (pasta do seu projeto laravel)
       |--- /bootstrap       (pasta do seu projeto laravel)
       |--- /config          (pasta do seu projeto laravel)
       |--- /database        (pasta do seu projeto laravel)
    
  • Configuring Laravel

    • Before using Laravel it is necessary to create the file .env , note that in the laravel folder there is a file named .env.example copy it and the name of .env if it does not exist. >
    • Then you will need to set APP_KEY , it must be a 32-character key, for example:

      APP_KEY=2XXjEeJYr2jO0lboHZPHLuN6eYmnxPvl
      
    • I recommend that you use the key:generate command to generate such a key, note that to use the artesian command you must have the composer set up and have added the artesian to the environment variables , navigate to the folder of your project and then use the command:

      $ cd /home/user/laravel
      $ php artisan key:generate
      
    • When you go up the project for production (pro server online) you should change the line APP_DEBUG=true to APP_DEBUG=false , this will turn off the errors that should only be displayed by the development environment and not the end user and also change APP_ENV=local to APP_ENV=production .

    The .env in Laravel in development environment:

    APP_ENV=local
    APP_DEBUG=true
    APP_KEY=2XXjEeJYr2jO0lboHZPHLuN6eYmnxPvl
    

    The .env in Laravel in production environment:

    APP_ENV=production
    APP_DEBUG=false
    APP_KEY=2XXjEeJYr2jO0lboHZPHLuN6eYmnxPvl
    
        
    11.10.2015 / 05:17