Project directory list in Laravel is displayed instead of running the application

Asked

Viewed 5,068 times

7

Projeto Não está funcionando

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

1 answer

10

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

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

Laravel in development environment

You have 3 options:

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

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

    DocumentRoot "/home/user/projeto-em-laravel/public"
    <Directory "/home/user/projeto-em-laravel/public">
        AllowOverride all
    </Directory>
    
  3. Configure an . htaccess in the folder ./projeto-em-laravel to point everything to the folder ./projeto-em-laravel/public/, create in folder ./projeto-em-laravel the file .htaccess 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 the case of a production environment nay use the server.php (although I think it would be almost impossible), with Apache you can try step 2 or 3 already mentioned, however if the server that will install the Laravel does not give you control over apache, then try to follow this:

  1. Usually servers have a folder called public_html or www access through Cpanel (if applicable) in other cases the folder where you should play the files is the name of the site, for example ./www.meusite.com.

  2. In these cases you should try step 3 then you will play all the content (only the content) of the folder projeto-em-laravel in the briefcase public_html for example and should create a file .htaccess same as step 3, the folder structure should look like this:

    ./public_html
       |--- .htaccess
       |--- /public
              |--- index.php
              |--- .htaccess
       |--- /app
       |--- /bootstrap
       |--- /config
       |--- /database
    
  3. There are developers who simply play the contents of the folder projeto-em-laravel out of of public_html and in public_html place the content of ./projeto-em-laravel/public, This is an option too, but you may end up getting lost with the existing folders of the server, it should look 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)
    

Setting up the Laravel

  • Before using Laravel you need to create the file .env, note that in the Laravel folder there is a file called .env.example copy it and the name of .env if it does not exist.

  • Then you will need to configure the APP_KEY, it must be a 32 character key, for example:

    APP_KEY=2XXjEeJYr2jO0lboHZPHLuN6eYmnxPvl
    
  • I recommend you use the command key:generate to generate such key, note that to use the command artesian it is necessary to have configured by Poser and have added the environment variables, navigate to the folder of your project and then use the command:

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

O . env in Laravel in development environment:

APP_ENV=local
APP_DEBUG=true
APP_KEY=2XXjEeJYr2jO0lboHZPHLuN6eYmnxPvl

O . env in Laravel in production environment:

APP_ENV=production
APP_DEBUG=false
APP_KEY=2XXjEeJYr2jO0lboHZPHLuN6eYmnxPvl

Browser other questions tagged

You are not signed in. Login or sign up in order to post.