-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-cpanel.sh
More file actions
executable file
·290 lines (240 loc) · 10.5 KB
/
Copy pathdeploy-cpanel.sh
File metadata and controls
executable file
·290 lines (240 loc) · 10.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/bin/bash
# Mirhal Marketplace - cPanel Deployment Script
# This script builds the frontend and prepares files for cPanel upload
echo "🚀 Starting Mirhal Marketplace Deployment Build..."
echo "=================================================="
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m' # No Color
# Step 1: Clean previous builds
echo -e "${BLUE}📦 Step 1: Cleaning previous builds...${NC}"
rm -rf dist/
rm -rf cpanel-deploy/
echo -e "${GREEN}✓ Cleaned${NC}"
# Step 2: Build the frontend
echo -e "${BLUE}📦 Step 2: Building frontend...${NC}"
npm run build
if [ $? -ne 0 ]; then
echo -e "${RED}❌ Build failed! Please fix errors and try again.${NC}"
exit 1
fi
echo -e "${GREEN}✓ Frontend built successfully${NC}"
# Step 3: Create deployment directory
echo -e "${BLUE}📦 Step 3: Creating deployment package...${NC}"
mkdir -p cpanel-deploy/public_html
mkdir -p cpanel-deploy/server
# Step 4: Copy frontend files
echo -e "${BLUE}📦 Step 4: Copying frontend files...${NC}"
cp -r dist/* cpanel-deploy/public_html/
cp .htaccess cpanel-deploy/public_html/ 2>/dev/null || echo "No .htaccess found, creating one..."
# Create .htaccess if it doesn't exist
if [ ! -f cpanel-deploy/public_html/.htaccess ]; then
cat > cpanel-deploy/public_html/.htaccess << 'EOF'
# Enable Rewrite Engine
RewriteEngine On
# Force HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Handle React Router - send all requests to index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
# Enable GZIP Compression
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json
</IfModule>
# Browser Caching
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType image/webp "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/html "access plus 0 seconds"
</IfModule>
EOF
echo -e "${GREEN}✓ Created .htaccess${NC}"
fi
echo -e "${GREEN}✓ Frontend files copied${NC}"
# Step 5: Copy server files (if deploying backend to cPanel)
echo -e "${BLUE}📦 Step 5: Copying server files...${NC}"
cp -r server/* cpanel-deploy/server/
echo -e "${GREEN}✓ Server files copied${NC}"
# Step 6: Create deployment instructions
cat > cpanel-deploy/UPLOAD_INSTRUCTIONS.txt << 'EOF'
╔════════════════════════════════════════════════════════════════╗
║ MIRHAL MARKETPLACE - cPanel Upload Instructions ║
╚════════════════════════════════════════════════════════════════╝
📋 FRONTEND DEPLOYMENT (public_html folder)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
1. Login to your cPanel
2. Open "File Manager"
3. Navigate to public_html (or your domain's root directory)
4. Upload ALL files from the "cpanel-deploy/public_html" folder
5. Make sure .htaccess is uploaded (enable "Show Hidden Files" if needed)
📋 BACKEND DEPLOYMENT (server folder)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Option A: Deploy to cPanel Node.js App
1. In cPanel, go to "Setup Node.js App"
2. Create New Application:
- Node.js version: 18.x or higher
- Application mode: Production
- Application root: server
- Application URL: api.yourdomain.com (or subdomain)
- Application startup file: index.js
3. Upload all files from "cpanel-deploy/server" to the server directory
4. Click "Run NPM Install"
5. Set Environment Variables (see below)
6. Start the application
Option B: Deploy Backend Separately (Recommended)
- Use Render.com, Railway.app, or Heroku for the backend
- Update VITE_API_URL in your frontend environment variables
📋 ENVIRONMENT VARIABLES
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Backend (.env in server directory):
- MONGODB_URI=your_mongodb_connection_string
- JWT_SECRET=your_jwt_secret
- FRONTEND_URL=https://yourdomain.com
- STRIPE_SECRET_KEY=your_stripe_secret
- SENDGRID_API_KEY=your_sendgrid_key
- PORT=3001
Frontend (already built into the files):
- VITE_API_URL=https://api.yourdomain.com/api
- VITE_GOOGLE_MAPS_API_KEY=your_maps_key
- VITE_STRIPE_PUBLISHABLE_KEY=your_stripe_public_key
- VITE_AUTH0_DOMAIN=your_auth0_domain
- VITE_AUTH0_CLIENT_ID=your_auth0_client_id
📋 POST-DEPLOYMENT CHECKLIST
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✓ Verify .htaccess is working (test a route like /about)
✓ Check that images and assets load correctly
✓ Test API connection from frontend
✓ Verify SSL certificate is active (HTTPS)
✓ Test authentication flow
✓ Check mobile responsiveness
✓ Test payment processing (in test mode first!)
📋 TROUBLESHOOTING
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Issue: 404 errors on routes
→ Make sure .htaccess is uploaded and mod_rewrite is enabled
Issue: Assets not loading
→ Check file permissions (644 for files, 755 for directories)
Issue: API not connecting
→ Verify CORS settings in backend allow your domain
→ Check VITE_API_URL is correct in build
Issue: White screen
→ Check browser console for errors
→ Verify all environment variables are set correctly
Need help? Check the logs in cPanel or contact your hosting support.
EOF
# Step 7: Create a quick deployment checklist
cat > cpanel-deploy/DEPLOYMENT_CHECKLIST.md << 'EOF'
# 🚀 Deployment Checklist
## Before Deployment
- [ ] Update environment variables in `.env.local`
- [ ] Test application locally (`npm run dev`)
- [ ] Run build script (`./deploy-cpanel.sh`)
- [ ] Review build output for errors
## During Deployment
- [ ] Upload `public_html` contents to cPanel File Manager
- [ ] Upload `.htaccess` file (show hidden files)
- [ ] Set up Node.js app for backend (if using cPanel)
- [ ] Configure environment variables in cPanel
- [ ] Install dependencies (`npm install` in server)
## After Deployment
- [ ] Test homepage loads
- [ ] Test routing (navigate to different pages)
- [ ] Test API connectivity
- [ ] Test authentication
- [ ] Test image uploads
- [ ] Test search functionality
- [ ] Test on mobile devices
- [ ] Check SSL certificate
- [ ] Monitor error logs
## DNS & Domain Setup
- [ ] Point domain A record to server IP
- [ ] Set up SSL certificate (Let's Encrypt in cPanel)
- [ ] Configure subdomain for API if needed
- [ ] Update CORS settings with production domain
## External Services
- [ ] Update Auth0 callback URLs
- [ ] Update Stripe webhook URLs
- [ ] Update Google Maps API restrictions
- [ ] Update Firebase authorized domains
- [ ] Test email delivery (SendGrid)
## Performance
- [ ] Enable GZIP compression (check .htaccess)
- [ ] Enable browser caching (check .htaccess)
- [ ] Optimize images
- [ ] Test page load speed
- [ ] Check mobile performance
## Security
- [ ] Verify HTTPS is enforced
- [ ] Check environment variables are not exposed
- [ ] Review CORS settings
- [ ] Test rate limiting
- [ ] Review file permissions
EOF
# Step 8: Create environment template
cat > cpanel-deploy/.env.production.template << 'EOF'
# Backend Environment Variables (server/.env)
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/mirhal?retryWrites=true&w=majority
JWT_SECRET=your-super-secret-jwt-key-change-this
FRONTEND_URL=https://yourdomain.com
PORT=3001
# Stripe
STRIPE_SECRET_KEY=sk_live_your_stripe_secret_key
# SendGrid
SENDGRID_API_KEY=SG.your_sendgrid_api_key
# Firebase Admin (if using)
FIREBASE_PROJECT_ID=your-project-id
FIREBASE_CLIENT_EMAIL=your-service-account-email
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nYour private key\n-----END PRIVATE KEY-----\n"
# Frontend Environment Variables (already baked into build)
# These should be set in .env.local BEFORE running build
# VITE_API_URL=https://api.yourdomain.com/api
# VITE_GOOGLE_MAPS_API_KEY=your_google_maps_key
# VITE_STRIPE_PUBLISHABLE_KEY=pk_live_your_stripe_publishable_key
# VITE_AUTH0_DOMAIN=your-tenant.auth0.com
# VITE_AUTH0_CLIENT_ID=your_auth0_client_id
# VITE_AUTH0_AUDIENCE=https://api.yourdomain.com
EOF
# Step 9: Create ZIP archive for easy upload
echo -e "${BLUE}📦 Step 6: Creating ZIP archives...${NC}"
# Create the full deployment package (for root level deployment)
cd cpanel-deploy
zip -r ../mirhal-full-deployment.zip . -x "*.DS_Store"
cd ..
# Create a FRONTEND ONLY zip (flat) for uploading directly into public_html
cd dist
zip -r ../mirhal-frontend.zip . -x "*.DS_Store"
cd ..
echo -e "${GREEN}✓ ZIP archive created: mirhal-full-deployment.zip (Full Server + Client)${NC}"
echo -e "${GREEN}✓ ZIP archive created: mirhal-frontend.zip (Frontend Files ONLY - Upload to public_html)${NC}"
# Final summary
echo ""
echo -e "${GREEN}=================================================="
echo -e "✅ Deployment packages ready!"
echo -e "==================================================${NC}"
echo ""
echo -e "${BLUE}📦 Option A (Frontend Only): ${NC}mirhal-frontend.zip"
echo -e " -> Upload this INSIDE public_html and extract. No nested folders."
echo ""
echo -e "${BLUE}📦 Option B (Full Project): ${NC}mirhal-full-deployment.zip"
echo -e " -> Upload this to root directory (above public_html)."
echo ""
echo ""
echo -e "${BLUE}Next steps:${NC}"
echo "1. Review UPLOAD_INSTRUCTIONS.txt"
echo "2. Upload files to cPanel"
echo "3. Configure environment variables"
echo "4. Test your deployment"
echo ""
echo -e "${GREEN}Good luck with your deployment! 🚀${NC}"