2.8.4.2.2. Transfer Laravel to hosting

Attention!

The information in this article is for informational purposes only. Transferring a Laravel project to hosting is quite complex and has certain nuances that only the developer can foresee.

To transfer a Laravel project first of all you need to upload the files to the server in any of the ways:

  • When using Git, you can connect to the hosting via SSH and clone the project:
    git clone http://github.com/example/example_site/
  • Upload project files to the server.

After uploading the files to the server connect via SSH and perform the following steps:

  1. Configure database connection.
  2. Go to the directory with the uploaded project:
    cd ~/example.com/www/
  3. Update dependencies and all packages:
    PATH=/usr/local/php70/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin
    composer install
  4. Execute the command:
    /usr/local/php70/bin/php artisan migrate
  5. Project files are usually located in the public directory, so change the site's root directory in one of the following ways:
    Change the site root directory so that it points to the public directory.
    Add or edit two .htaccess files:
    1. In the site's root directory:
      <IfModule mod_rewrite.c>
      RewriteEngine on
      RewriteRule ^$ public/ [L]
      RewriteRule ((?s).*) public/$1 [L]
      </IfModule>
    2. In the public directory:
      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteRule ^((?s).*)$ index.php?_url=/$1 [QSA,L]
      </IfModule>
  6. If necessary, create a symbolic link pointing from public/storage to storage/app/public. This can be done in two ways:
    1. Go to the /storage/app/ directory in your project and create a symbolic link pointing to the public directory.
    2. Insert the created symbolic link into the public/storage directory in the project root directory.
    1. Connect to the hosting via SSH.
    2. Create a symbolic link:
      ln -s /home/example/example.com/www/public/storage /home/example/example.com/www/storage/app/public

      In the command, instead of /example/example.com/www/, specify the site root directory where your project is located.

  7. Check the site operation.

Besides the above described, additional actions may be required to customize the project. In this case, please contact the project developer for more detailed information.

Content

    (2)

    Comments

    krikunenko.m.v
    UPD від 02.12.2024 | Laravel 11

    Додатково потрібно в налаштуваннях сайту змінити "Кореневий каталог" вказати "public" повна існтрукція
    https://www.ukraine.com.ua/uk/wiki/hosting/sites/my-sites/site-settings/root-dir/#change

    Для
    роботи з "storage" треба створити окремо символьне посилання

    Перейдіть у директорію /storage/app в файл-менеджері, натисніть правою кнопкою миші там на папку public і оберіть опцію "Створити сімлінк".
    Далі перейдіть в директорію /public і вставте там сімлінк правою кнопкою миші.

    Повна інструкція: https://www.ukraine.com.ua/wiki/hosting/files/file-manager/symlink/
    verliber
    Дякуємо за інформацію, додали її до інструкції.