Home > PHP Framework > Laravel > body text

How to publish laravel project online (detailed steps)

PHPz
Release: 2023-04-13 18:13:16
Original
953 people have browsed it

After the Laravel application is developed, publishing it online is a necessary step. Before publishing your application to an online server, you must ensure that your server meets all the necessary conditions for your Laravel application to run. Once you confirm that the server has the necessary configuration required, you can follow the steps below to publish your Laravel application to the online server.

Step 1: Copy the application code to the online server

You need to copy your application code from the local computer to the online server. You can use SCP or FTP tools. to accomplish this. Copy all application files to the Web directory of the online server.

Step 2: Set application directory permissions

In order to ensure that the application can run on the online server, you need to set the correct directory and file permissions.

You can use the following command to change permissions:

sudo chgrp -R www-data /path/to/your/laravel/root/directory
sudo chmod -R 775 /path/to/your/laravel/root/directory/storage
Copy after login

Step 3: Configure the Web server

You need to configure the Web server according to the type of Web server on the online server. configuration. If you are using an Apache server, please make sure to add the following content in the configuration file:

<VirtualHost *:80>
    ServerName your_domain_name.com
    DocumentRoot /path/to/your/laravel/root/directory/public
    <Directory /path/to/your/laravel/root/directory/public>
        AllowOverride All
        Options FollowSymLinks
        Require all granted
    </Directory>
</VirtualHost>
Copy after login

If you are using an Nginx server, please edit the default file and add the following content:

server {
    listen 80;
    listen [::]:80;

    root /path/to/your/laravel/root/directory/public;
    index index.php index.html index.htm;

    server_name your_domain_name.com;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    }
}
Copy after login

Step 4: Configure the application environment

You need to configure the environment variables of your application according to your deployment environment. Open the .env file and modify the database connection string, key and other configuration information.

Step Five: Run Migration

Before deploying the application, you need to run the migration command to create the required database tables. Use the following command in the command line to run the migration:

php artisan migrate
Copy after login

Step 6: Modify the storage path

You need to modify the default storage path in the config/filesystems.php file. Change the default option to public and store the uploaded files in the public storage path:

'default' => 'public',
...
'public' => [
    'driver' => 'local',
    'root' => storage_path('app/public'),
    'url' => env('APP_URL') . '/storage',
    'visibility' => 'public',
],
Copy after login

Step 7: Add queue configuration

If your application uses queues, you need to Queue configuration application. Set up the queue driver in the config/queue.php file.

'default' => env('QUEUE_DRIVER', 'sync'),
...
'connections' => [
    ...
    'redis' => [
        'driver' => 'redis',
        'connection' => 'rediska',
        'queue' => 'default',
        'retry_after' => 90,
        'block_for' => null,
    ],
    ...
],
Copy after login

Step Eight: Restart the Web Server

After completing the configuration of the Laravel application, you need to restart the web server to load all configurations and changes. Restart the web server using the following command on the command line:

sudo service apache2 restart
Copy after login

or

sudo service nginx restart
Copy after login

The above is the basic process of deploying a Laravel application on a Linux server. Of course, the exact deployment method may vary depending on the needs of the project, but this should be a good starting point and I hope it helps.

The above is the detailed content of How to publish laravel project online (detailed steps). For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template