To deploy a React/Laravel project, follow these steps:
- Build React App:
In your React project directory, run the command npm run build. This will create a production-ready build of your React app.
- Configure Laravel:
In your Laravel project directory, configure your database credentials in the .env file.
Generate a unique application key by running the command php artisan key:generate.
- Set up Database:
Create a new database on your hosting server or local environment and configure the database credentials in the .env file.
- Configure Laravel Application URL:
Update APP_URL in the .env file to match the URL of your deployed Laravel app.
- Configure Web Server:
Set up your web server (Apache, Nginx, etc.) to point to the public directory inside your Laravel project.
- Upload Files:
Upload all the files and directories from the Laravel project to your server, excluding the node_modules and public directories.
Also, upload the contents of the React build created in step 1 to the public directory of the Laravel project.
- Install Composer Dependencies:
Navigate to your Laravel project directory on the server and run composer install --no-dev.
- Run Migrations:
Run the necessary migrations by executing the command php artisan migrate.
- Install Node Dependencies:
Finally, navigate to your Laravel project directory on the server and run npm install --production.
- Start the Application:
After completing the above steps, your React/Laravel app should be ready to run. You can start the application by running php artisan serve or using appropriate commands for your specific hosting environment.
Remember to set up appropriate environment variables and security measures for your production environment.