Skip to content

Commit f20b881

Browse files
authored
Merge pull request #591 from Laravel-Backpack/deploy-to-production
add deploy to production
2 parents 23bfaf3 + 5ad1206 commit f20b881

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

6.x/faq.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,127 @@ If you still can't figure it out, please [open a new discussion in our Community
110110
- mention the steps you have followed to get there (e.g. `composer require backpack/pro`, `php artisan backpack:require:pro` etc.);
111111
- include a screenshot of the console output, so we can understand what happened;
112112
- cross out any personal data (e.g. token username or password);
113+
114+
<a name="how-do-i-deploy-backpack-to-production"></a>
115+
### How do I deploy Backpack to production?
116+
117+
Deploying a Laravel+Backpack project to production isn't very different from deploying a normal Laravel project to production. You only need to account for Basset, the system in Backpack that publishes the CSS and JS assets your admin panel needs.
118+
119+
That being said, here's a detailed step-by-step guide to deploying a Backpack project to production, that should work for most production servers:
120+
121+
1. Local Preparations
122+
Before deploying your application, make sure your development environment is in order:
123+
- Update dependencies:
124+
```
125+
composer install --no-dev --optimize-autoloader
126+
npm install && npm run prod
127+
```
128+
- Configure your .env file for production. This file should not be included in version control (git), but make sure to have a copy with production settings.
129+
130+
2. Configure the Production Server
131+
Ensure your production server meets the following requirements:
132+
133+
Web Server: Nginx or Apache.
134+
PHP: Version compatible with your Laravel version.
135+
Database: MySQL, PostgreSQL, etc.
136+
Composer: Installed globally.
137+
Node.js and npm: If you are using asset compilation with Laravel Mix.
138+
139+
3. Deploy the Code
140+
There are several ways to deploy code to production, here’s one method using Git:
141+
- Clone your repository on the server:
142+
```
143+
git clone https://github.com/your_user/your_repository.git
144+
cd your_repository
145+
```
146+
- Copy your local .env file to the production environment and adjust the settings accordingly.
147+
```
148+
APP_ENV=production
149+
APP_URL=https://MY_DOMAIN.COM #This need to be correctly set for Basset
150+
```
151+
152+
4. Install Dependencies
153+
Install Composer and npm dependencies:
154+
```
155+
composer install --no-dev --optimize-autoloader
156+
npm install && npm run prod
157+
```
158+
159+
5. Configure the Application
160+
Make the necessary configurations for the application:
161+
- Generate the application key:
162+
```
163+
php artisan key:generate
164+
```
165+
- Set permissions:
166+
```
167+
sudo chown -R www-data:www-data storage
168+
sudo chown -R www-data:www-data bootstrap/cache
169+
sudo chmod -R 775 storage
170+
sudo chmod -R 775 bootstrap/cache
171+
```
172+
- Run database migrations:
173+
```
174+
php artisan migrate --force
175+
```
176+
- Optimize configuration:
177+
```
178+
php artisan basset:clear
179+
php artisan basset:cache
180+
php artisan optimize:clear
181+
php artisan optimize
182+
```
183+
184+
6. Configure the Web Server
185+
Set up your web server (Nginx or Apache) to point to the public directory of your Laravel application. Here’s an example Nginx configuration:
186+
```
187+
server {
188+
listen 80;
189+
server_name your_domain.com;
190+
root /path/to/your/project/public;
191+
192+
index index.php index.html;
193+
194+
location / {
195+
try_files $uri $uri/ /index.php?$query_string;
196+
}
197+
198+
location ~ \.php$ {
199+
include snippets/fastcgi-php.conf;
200+
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
201+
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
202+
include fastcgi_params;
203+
}
204+
205+
location ~ /\.ht {
206+
deny all;
207+
}
208+
}
209+
```
210+
211+
7. Configure Cron Jobs
212+
If your Laravel application uses scheduled tasks, add the following line to your crontab:
213+
```
214+
* * * * * cd /path/to/your/project && php artisan schedule:run >> /dev/null 2>&1
215+
```
216+
217+
8. Monitor and Maintain
218+
Monitor your application in production:
219+
- Logs: Check logs in storage/logs/laravel.log.
220+
- Services: Ensure services like queue workers are running properly.
221+
222+
9. Optimize for Production
223+
Perform additional optimizations if necessary:
224+
- Optimize Autoload:
225+
```
226+
composer dump-autoload --optimize
227+
```
228+
- Disable Debug in .env:
229+
```
230+
APP_DEBUG=false
231+
```
232+
- Clean & Set config cache
233+
```
234+
php artisan config:clear
235+
php artisan config:cache
236+
```

0 commit comments

Comments
 (0)