How to go up and configure a project with Laravel on the server

Asked

Viewed 4,790 times

2

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

2 answers

4


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

Thinking about the case of Apache2, you could configure it 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 a development environment.

The archive .env directly affects the file settings in the folder config. For example, the file config/database.php should contain in the second function parameter env the value referring to the connections in production, since the first parameter will be the parameters defined in the file .env. If this file is missing, the second parameter of the function env will be considered for your configuration.

Example:

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

In the archive .env

DB_HOST=localhost

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

2

Besides the care with the file. env, 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':

  • Only copy the contents of your project’s public folder to Document-root;
  • Edit the 'index.php' file to reference the directories existing in the file correctly;
  • Edit the file 'server.php' which is at the root of your project to point to the 'index.php' of Document-root.

Browser other questions tagged

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