Steps to move laravel project from localhost to production server

Created At: 2020-11-04 18:21:35 Updated At: 2022-06-30 09:01:09

Moving laravel from localhost to a live server you should follow the three steps

1. Configure your .env file

2. Execute the artisan commands

3. Permission command if you have 403 error

1. Configure your .env file

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:J7lE5o1vez3Z7oypDuB9KENMn7azHatg7qMhOfX8/tg=
APP_DEBUG=true
APP_URL=http://www.example.com/

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=xxxxxxxxxxx

In the above, you need to make sure, you have write your correct url name, database name and password and user name.

2. Execute the artisan commands

Run the below commands in your linux terminal

1. composer install

2. php artisan key:generate 

3. php artisan cache:clear

4. php artisan migrate

5. chmod -R 775 storage/

6. composer dump-autoload

7. sudo chown -R apache storage

8. sudo chown -R apache bootstrap/cache

9. chmod -R 775 storage

10. chmod -R 775 bootstrap/cache

The above commands should be use for Linux or Mac user.

Three commands I often run, these are very useful

php artisan config:clear
php artisan cache:clear
php artisan optimize

Windows users

For windows follow the below command

1. Go to the root of your Laravel installation

(where composer.json and artisan live).

2. Change the owning user and group, where yourusername is your username:

sudo chown -R yourusername:www-data storage

This recursively (-R) sets the user:group owners to yourusername:www-data in all files and folders from storage onward.

3. Add the write permission for both you and the www-data group

sudo chmod -R ug+w storage
This recursively (-R) adds (+) the write flag (w) to the user (u) and group (g) that own the files and folders from app/storage onward.

4. Additionally, some suggest you may need to flush the application cache and regenerate the Laravel autoload files.

php artisan cache:clear

5. Finally, you may want to regenerate Composer’s autoload files

composer dump-autoload

 

3. Permission command if you have 403 error

Now if you see the below error or 403 error

pcfg_openfile: unable to check htaccess file

It means .htaccess file is not readable apache

chmod 644 /var/www/html/www.example.com/public/.htaccess 

Also the public directory needs to be executable and readable 

chmod 755 /var/www/html/www.example/public/ 

Solutions for Laravel Admin Panel

Share hosting Laravel

https://www.dbestech.com/tutorials/deploy-laravel-web-app-in-shared-host-hostgator-namecheap-bluehost

Comment

Add Reviews