New-Thanasoft/DEPLOYMENT.md
2025-10-06 19:37:32 +03:00

220 lines
4.5 KiB
Markdown

# Thanasoft Deployment Guide
This guide explains how to build and deploy your Thanasoft application.
## Project Structure
```
/var/www/html/New-Thanasoft/
├── README.md
├── thanasoft-back/ # Laravel Backend
│ ├── app/
│ ├── routes/
│ ├── public/
│ │ ├── index.php # Laravel entry point
│ │ └── build/ # Vue.js build output (auto-generated)
│ └── ...
└── thanasoft-front/ # Vue.js Frontend
├── src/
├── public/
├── vue.config.js # Build configuration
└── package.json
```
## Development Workflow
### Frontend Development
1. **Start the Vue dev server:**
```bash
cd thanasoft-front
npm run serve
```
- Frontend runs on: http://localhost:8080
- API calls to `/api/*` are proxied to Laravel backend
2. **Start the Laravel backend (in another terminal):**
```bash
cd thanasoft-back
php artisan serve
```
- Backend runs on: http://localhost:8000
### Building for Production
The Vue.js frontend is configured to build directly into `thanasoft-back/public/build/`:
```bash
cd thanasoft-front
npm run build
```
This will:
- Build optimized production files
- Output to `../thanasoft-back/public/build/`
- Create `index.html`, `css/`, `js/`, `img/`, etc.
## Deployment to Server
### Option 1: Automated Deployment (Recommended)
Use the deployment script:
```bash
cd "/media/creator/6226b912-8ba7-45dc-88a2-4b10d3dd1655/kandra/Thanasoft v2"
chmod +x deploy-to-server.sh
./deploy-to-server.sh
```
This script will:
1. Build the Vue.js frontend
2. Upload all files to the server
3. Set correct permissions
4. Clear and cache Laravel routes/config
5. Restart Apache
### Option 2: Manual Deployment
#### Step 1: Build Frontend Locally
```bash
cd thanasoft-front
npm run build
```
#### Step 2: Upload to Server
```bash
# Upload backend and frontend build
rsync -avz --progress \
--exclude 'node_modules' \
--exclude 'vendor' \
--exclude '.git' \
thanasoft-back/ root@78.138.58.60:/var/www/html/New-Thanasoft/thanasoft-back/
```
#### Step 3: Server Configuration
SSH into your server:
```bash
ssh root@78.138.58.60
cd /var/www/html/New-Thanasoft/thanasoft-back
```
Set permissions:
```bash
chown -R www-data:www-data storage bootstrap/cache public/build
chmod -R 775 storage bootstrap/cache
```
Clear and cache Laravel:
```bash
php artisan route:clear
php artisan cache:clear
php artisan config:clear
php artisan route:cache
php artisan config:cache
```
Restart Apache:
```bash
systemctl restart apache2
```
## How It Works
### Vue.js Configuration (`vue.config.js`)
```javascript
outputDir: path.resolve(__dirname, '../thanasoft-back/public/build')
publicPath: '/build/'
```
- Builds output to Laravel's `public/build/` directory
- Assets are served from `/build/` path
### Laravel Configuration (`routes/web.php`)
```php
Route::get('/{any}', function () {
return file_get_contents(public_path('build/index.html'));
})->where('any', '.*');
```
- Catch-all route serves Vue.js SPA
- API routes (`/api/*`) bypass this and go to Laravel controllers
### Apache Configuration
```apache
DocumentRoot /var/www/html/New-Thanasoft/thanasoft-back/public
```
- Points to Laravel's `public/` directory
- `.htaccess` handles routing
## URLs
- **Production**: http://78.138.58.60/
- **API**: http://78.138.58.60/api/
- **API Endpoints**:
- POST /api/auth/register
- POST /api/auth/login
- GET /api/auth/me (requires auth)
- POST /api/auth/logout (requires auth)
## Troubleshooting
### Frontend shows 404
1. Check if build files exist:
```bash
ls -la /var/www/html/New-Thanasoft/thanasoft-back/public/build/
```
2. Verify `routes/web.php` points to correct path:
```php
public_path('build/index.html') // Correct
```
3. Clear route cache:
```bash
php artisan route:clear
php artisan route:cache
```
### API returns 404
1. Check Apache mod_rewrite is enabled:
```bash
sudo a2enmod rewrite
sudo systemctl restart apache2
```
2. Verify `.htaccess` exists in `public/`
3. Check Apache virtual host has `AllowOverride All`
### Permission errors
```bash
cd /var/www/html/New-Thanasoft/thanasoft-back
sudo chown -R www-data:www-data storage bootstrap/cache public/build
sudo chmod -R 775 storage bootstrap/cache
```
## Quick Deploy
After making changes, just run:
```bash
cd "/media/creator/6226b912-8ba7-45dc-88a2-4b10d3dd1655/kandra/Thanasoft v2"
./deploy-to-server.sh
```
That's it! 🚀