Skip to content

Commit 600290c

Browse files
committed
add deploy to production
1 parent fd79003 commit 600290c

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

6.x/faq.md

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

0 commit comments

Comments
 (0)