How to upload and configure a project with Laravel on the server

2

I'm starting with Laravel 5.3 and learning how to explore all of its features. But I have a question. How would my project look on the server (in production). Today my projects are inside a folder with the index.php file in the root. What would change in a project using Laravel?

    
asked by anonymous 28.07.2017 / 16:17

2 answers

4

When you upload a Laravel project to the server, you must configure Virtual Host to point to the public folder of your project, because as the name of the folder says, this is the folder that should be public.

Thinking about the Apache2 case, you could set it up as follows:

<VirtualHost *:80>
    DocumentRoot /var/www/nome-do-projeto/public
    ServerName www.nome-do-projeto.com.br
    ErrorLog /tmp/nome-do-projeto_apache.log
</VirtualHost>

It is also necessary to remove the file .env , since it should only be used in the development environment.

The .env file directly affects the file settings in the config folder. For example, the config/database.php file must contain in the second parameter of the env function the value for the connections in production, because the first parameter will be the parameters defined in the .env file. In the absence of this file, the second parameter of the env function will be considered for its configuration.

Example:

'host' => env('DB_HOST', 'url-do-banco-em-producao.com')

In the file .env

DB_HOST=localhost

That is, you only need to send the files of your application to the specific folder on the server, with the exception of the file .env .

    
28.07.2017 / 17:58
2

In addition to the care of the .env file, as already answered above, if you do not have access / control to configure a virtualhost, you can do the following:

Assuming your document-root is the 'www' or 'public_html' folder:

  • Copy only the contents of the 'public' folder of your project to the document-root;
  • Edit the 'index.php' file to reference the directories in the file correctly;
  • Edit the 'server.php' file that is at the root of your project to point to the 'index.php' of document-root.
28.07.2017 / 19:06