-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver-setup.php
More file actions
273 lines (239 loc) Β· 8.01 KB
/
server-setup.php
File metadata and controls
273 lines (239 loc) Β· 8.01 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
<?php
/**
* WeGenius Server Setup Script
* Run this ONCE after uploading deployment package
* Access: https://wegenius.fahmidsroadmap.com/server-setup.php
*/
set_time_limit(300); // 5 minutes max
$output = [];
$errors = [];
// Helper function to execute commands
function executeCommand($command, $description) {
global $output, $errors;
$output[] = "<strong>β {$description}</strong>";
$result = shell_exec($command . " 2>&1");
if (empty($result)) {
$output[] = "β Completed";
} else {
$output[] = "<pre style='margin: 5px 0; padding: 10px; background: #f5f5f5; border-radius: 4px;'>" . htmlspecialchars($result) . "</pre>";
}
return $result;
}
// Start output
?>
<!DOCTYPE html>
<html>
<head>
<title>WeGenius Server Setup</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
max-width: 900px;
margin: 50px auto;
padding: 20px;
background: #f8f9fa;
}
.container {
background: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
h1 {
color: #2563eb;
margin-bottom: 10px;
}
.step {
margin: 20px 0;
padding: 15px;
background: #f8fafc;
border-left: 4px solid #2563eb;
border-radius: 4px;
}
.success {
color: #059669;
font-weight: bold;
}
.error {
color: #dc2626;
font-weight: bold;
}
.warning {
color: #d97706;
font-weight: bold;
}
pre {
background: #1e293b;
color: #e2e8f0;
padding: 15px;
border-radius: 6px;
overflow-x: auto;
font-size: 13px;
}
.button {
display: inline-block;
padding: 12px 24px;
background: #2563eb;
color: white;
text-decoration: none;
border-radius: 6px;
margin-top: 20px;
font-weight: 600;
}
.button:hover {
background: #1d4ed8;
}
</style>
</head>
<body>
<div class="container">
<h1>π WeGenius Server Setup</h1>
<p>Setting up your Laravel application...</p>
<hr>
<?php
// Step 1: Check if deployment package exists
echo "<div class='step'>";
echo "<h3>Step 1: Extract Deployment Package</h3>";
$zipFile = 'wegenius-deploy.zip';
if (file_exists($zipFile)) {
$output[] = "Found deployment package: " . round(filesize($zipFile) / 1024 / 1024, 2) . " MB";
$zip = new ZipArchive;
if ($zip->open($zipFile) === TRUE) {
$zip->extractTo('./');
$zip->close();
$output[] = "<span class='success'>β Package extracted successfully</span>";
} else {
$errors[] = "Failed to extract package";
}
} else {
$output[] = "<span class='warning'>β Package not found (files may already be extracted)</span>";
}
foreach ($output as $line) {
echo "<div>{$line}</div>";
}
echo "</div>";
$output = [];
// Step 2: Setup Environment
echo "<div class='step'>";
echo "<h3>Step 2: Configure Environment</h3>";
if (file_exists('.env.production')) {
copy('.env.production', '.env');
$output[] = "<span class='success'>β Production environment configured</span>";
} elseif (!file_exists('.env')) {
$errors[] = ".env file not found";
$output[] = "<span class='error'>β Missing environment file</span>";
} else {
$output[] = "<span class='success'>β Using existing .env</span>";
}
foreach ($output as $line) {
echo "<div>{$line}</div>";
}
echo "</div>";
$output = [];
// Step 3: Set Permissions
echo "<div class='step'>";
echo "<h3>Step 3: Set Directory Permissions</h3>";
$dirs = ['storage', 'bootstrap/cache'];
foreach ($dirs as $dir) {
if (is_dir($dir)) {
executeCommand("chmod -R 775 {$dir}", "Setting permissions for {$dir}");
}
}
foreach ($output as $line) {
echo "<div>{$line}</div>";
}
echo "</div>";
$output = [];
// Step 4: Generate Application Key
echo "<div class='step'>";
echo "<h3>Step 4: Generate Application Key</h3>";
// Check if key exists
$envContent = file_get_contents('.env');
if (strpos($envContent, 'APP_KEY=base64:') === false || preg_match('/APP_KEY=base64:.{40,}/', $envContent) === 0) {
executeCommand("php artisan key:generate --force", "Generating application key");
} else {
$output[] = "<span class='success'>β Application key already exists</span>";
}
foreach ($output as $line) {
echo "<div>{$line}</div>";
}
echo "</div>";
$output = [];
// Step 5: Create Storage Link
echo "<div class='step'>";
echo "<h3>Step 5: Create Storage Symlink</h3>";
if (!file_exists('public/storage')) {
executeCommand("php artisan storage:link", "Creating storage symlink");
} else {
$output[] = "<span class='success'>β Storage link already exists</span>";
}
foreach ($output as $line) {
echo "<div>{$line}</div>";
}
echo "</div>";
$output = [];
// Step 6: Run Database Migrations
echo "<div class='step'>";
echo "<h3>Step 6: Run Database Migrations</h3>";
executeCommand("php artisan migrate --force", "Running database migrations");
foreach ($output as $line) {
echo "<div>{$line}</div>";
}
echo "</div>";
$output = [];
// Step 7: Optimize Application
echo "<div class='step'>";
echo "<h3>Step 7: Optimize Application</h3>";
// Clear all caches first to avoid conflicts
executeCommand("php artisan config:clear", "Clearing config cache");
executeCommand("php artisan route:clear", "Clearing route cache");
executeCommand("php artisan view:clear", "Clearing view cache");
// Only cache config and views (skip routes due to conflicts)
executeCommand("php artisan config:cache", "Caching configuration");
executeCommand("php artisan view:cache", "Caching views");
foreach ($output as $line) {
echo "<div>{$line}</div>";
}
echo "</div>";
$output = [];
// Step 8: Verify Setup
echo "<div class='step'>";
echo "<h3>Step 8: Verify Installation</h3>";
$checks = [
'.env file' => file_exists('.env'),
'vendor directory' => is_dir('vendor'),
'public directory' => is_dir('public'),
'storage writable' => is_writable('storage'),
'bootstrap/cache writable' => is_writable('bootstrap/cache'),
'APP_KEY set' => preg_match('/APP_KEY=base64:.{40,}/', file_get_contents('.env')) === 1,
];
foreach ($checks as $check => $result) {
if ($result) {
echo "<div><span class='success'>β</span> {$check}</div>";
} else {
echo "<div><span class='error'>β</span> {$check}</div>";
$errors[] = $check . " failed";
}
}
echo "</div>";
// Final Status
echo "<hr>";
if (empty($errors)) {
echo "<h2 class='success'>β Setup Completed Successfully!</h2>";
echo "<p>Your WeGenius application is now ready to use.</p>";
echo "<a href='/' class='button'>Launch Application</a>";
echo "<br><br>";
echo "<p><small class='warning'>β Important: Delete this file (server-setup.php) for security!</small></p>";
} else {
echo "<h2 class='error'>β Setup Completed with Errors</h2>";
echo "<p>Please review the errors above and fix them manually.</p>";
echo "<ul>";
foreach ($errors as $error) {
echo "<li class='error'>{$error}</li>";
}
echo "</ul>";
}
?>
</div>
</body>
</html>