Laravel Setup For Rest API


Create Project
composer create-project laravel/laravel example-app

or if using sqlite
composer create-project --prefer-dist laravel/laravel project-name


Run On Localhost
php artisan serve

Error Setup :
  • error autoload.php
    • composer install
  • error generated key
    • php artisan key:generate
    • php artisan config:cache
  • Create public storage (For Upload Image)
    • php artisan storage:link

Setup database on .env file
DB_DATABASE=laravel_api
DB_USERNAME=root
DB_PASSWORD=

Install XAMPP
Run XAMPP
sudo /opt/lampp/manager-linux-x64.run

error laravel could not find driver Connection: mysql
sudo apt install php-mysql

Restart your server:
# apache
sudo systemctl restart apache2
# nginx
sudo systemctl restart nginx

WARN  The database 'laravel' does not exist on the 'mysql' connection
If we change something in .env we need to clear cache and config first before run something (ex : migration)
php artisan config:clear
php artisan cache:clear

Delete generated model and migration by laravel when initiate project

# Deploy to shared hosting

Archive to zip and upload the project

Create your database

Change your .env
APP_NAME=YourAppName
APP_ENV=production
APP_KEY=base64:YourGeneratedAppKeyHere
APP_DEBUG=false
APP_URL=https://www.example.com/example_app

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=your_database_host
DB_PORT=3306
DB_DATABASE=your_database_name
DB_USERNAME=your_database_username
DB_PASSWORD=your_database_password

FILESYSTEM_DISK=public

Ganti CHMOD / permission untuk menampilkan image
https://www.rumahweb.com/journal/chmod-adalah/#Ubah_CHMOD_secara_Manual

Create symlink

Reference :

Komentar