Deploy Laravel application

Asked

Viewed 1,940 times

0

I’m having trouble getting my application up to production environment. I tried several times as I find in step by step and documentation, but the error persists.

Current scenario: I moved the project, with the name of backend, to the directory at the same level of www: raiz

Inside the www are the front-end files, which were developed by someone else: www

In this same directory I created the admin folder, where are the files of the project’s Public folder: admin

I have run the scripts for installing Composer and migrations, but when trying to access another page other than the "/" (home) route, it does not find, as shown in the image below: erro

I know that the ideal is that the Public files of my project are in WWW, but as there are already the front files, I created the folder "admin", in the intention that the administrator has access to a panel to manage the contents of the page.

Can anyone tell me where I’m going wrong? Grateful from now on.

  • hosting and shared or is a VPS ?

  • It is on an own company server, available for this application.

  • Which operating system ? and has git in it ?

  • Debian 9 Com git

  • the project has been uploaded to some git ?

  • Yes. Ta here: [email protected]:thiagomrvieira/pinheiro.git

  • I will answer with a step by step for you to raise this project

Show 2 more comments

2 answers

2

We will do an installation from scratch of your project, (I believe it is the best way):

Access your project from the terminal ssh, navigate to the directory www (usually stays within /var/www/)

Inside the clone directory your project with the following command:

$ git clone https://github.com/thiagomrvieira/pinheiro.git

After completion access the project directory (pinheiro)

$ cd pinheiro

Create the file .env (I saw that did not commit the .env.example (click on the link to see the template)) After creation edit to add database settings and etc.

Or you can define this information from .env also inside the directory config/database.php or config/app.php and etc..

Install packages with the following command from commiserate:

composer install

Wait for it to finish we will create the project key for this run the following command below, to generate the new key:

php artisan key:generate

Ready now we have the project configured and ready to start importing the tables with the migrate:

php artisan migrate

Wait for command to complete if no error occurs the database has already been imported.

You can test with the command:

php artisan serve --host 127.0.0.1

The --host 127.0.0.1 is an optional parameter for you to determine the server ip (necessary in external connections).

Okay, with the functional application, now let’s go to the Linux, and for that we will work with virtual hosts. I believe this is the best way to do this.

Access the directory /etc/apache2/sites-enabled/ create a file with your domain name finished by .conf except: abcd.com.br.conf, I usually already have a model ready here and I will use it as an example.

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin [email protected]
    DocumentRoot /var/www/AdmMedico/public
    ServerName  pinheiro.com.br
    ServerAlias www.pinheiro.com.br

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
<Directory "/var/www/pinheiro/public">
    AllowOverride All
</Directory>

</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

I’ve already kind of set it up for your case, assuming you use the domain name pine.com.br, if it is not change for its use.

Creating just restart the apache service and it’s ready,

service apache2  restart

Now just access by pinheiro.com.br that will load the page as it should.

For more information on Virtual Host

  • Thank you so much for your help, @Bulfaitelo. Actually what I wanted was to keep an existing project in the directory and climb mine in a subdirectory like pinheiro.com.br/admin. I ended up creating another directory with another domain and the front application consuming the API with the backend data. Anyway, thank you.

0

Maybe I didn’t explain it very well. What I wanted to do was keep an existing project in my directory and create a subdirectory like pinheiro.com.br/admin with my Laravel project.

I couldn’t set it up that way. As the server is proper, I ended up creating another domain and moving the project up in another directory, where I developed an API that was consumed by the initial project (what was already there).

Browser other questions tagged

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