-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_symlink.php
More file actions
142 lines (118 loc) · 4.08 KB
/
verify_symlink.php
File metadata and controls
142 lines (118 loc) · 4.08 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
<?php
/**
* Symlink Verification Script
* This checks if the symlink is working correctly
*/
if (strpos($_SERVER['HTTP_HOST'], 'localhost') !== false) {
die('This script should only be run on production server!');
}
echo "<h2>Symlink Verification</h2>";
echo "<pre>";
$publicPath = '/home/eunixmac/public_html';
$storagePath = '/home/eunixmac/eunixmac_api/storage/app/public';
$symlinkPath = $publicPath . '/storage';
echo "Checking Symlink Status\n";
echo "=======================\n\n";
// Check if symlink exists
echo "1. Does symlink exist?\n";
if (file_exists($symlinkPath)) {
echo " ✅ YES - Something exists at: {$symlinkPath}\n";
// Check if it's a symlink
if (is_link($symlinkPath)) {
echo " ✅ It IS a symlink\n";
$target = readlink($symlinkPath);
echo " Target: {$target}\n";
// Check if target is correct
if ($target === $storagePath) {
echo " ✅ Target is CORRECT\n";
} else {
echo " ❌ Target is WRONG!\n";
echo " Expected: {$storagePath}\n";
echo " Got: {$target}\n";
}
} elseif (is_dir($symlinkPath)) {
echo " ❌ It's a DIRECTORY, not a symlink!\n";
echo " You need to DELETE this directory and create a symlink instead.\n";
} else {
echo " ❌ It's a FILE, not a symlink!\n";
}
} else {
echo " ❌ NO - Symlink does not exist at: {$symlinkPath}\n";
}
echo "\n";
// Check if storage path exists
echo "2. Does storage directory exist?\n";
if (is_dir($storagePath)) {
echo " ✅ YES - {$storagePath}\n";
} else {
echo " ❌ NO - {$storagePath}\n";
}
echo "\n";
// Check ads directory
$adsPath = $storagePath . '/ads';
echo "3. Does ads directory exist?\n";
if (is_dir($adsPath)) {
echo " ✅ YES - {$adsPath}\n";
// List images
$images = glob($adsPath . '/*.{jpg,jpeg,png,gif,webp}', GLOB_BRACE);
echo " Found {count($images)} images:\n";
foreach ($images as $img) {
$filename = basename($img);
$filesize = filesize($img);
$readable = is_readable($img) ? 'readable' : 'NOT readable';
echo " - {$filename} ({$filesize} bytes, {$readable})\n";
}
} else {
echo " ❌ NO - {$adsPath}\n";
}
echo "\n";
// Check if we can access through symlink
echo "4. Can we access ads through symlink?\n";
$symlinkAdsPath = $symlinkPath . '/ads';
if (is_dir($symlinkAdsPath)) {
echo " ✅ YES - {$symlinkAdsPath} is accessible\n";
// Try to list files through symlink
$symlinkImages = glob($symlinkAdsPath . '/*.{jpg,jpeg,png,gif,webp}', GLOB_BRACE);
echo " Can see {count($symlinkImages)} images through symlink\n";
} else {
echo " ❌ NO - Cannot access {$symlinkAdsPath}\n";
}
echo "\n";
// Check permissions
echo "5. Checking permissions:\n";
if (file_exists($symlinkPath)) {
$perms = substr(sprintf('%o', fileperms($symlinkPath)), -4);
echo " Symlink permissions: {$perms}\n";
}
if (is_dir($storagePath)) {
$perms = substr(sprintf('%o', fileperms($storagePath)), -4);
echo " Storage permissions: {$perms}\n";
}
if (is_dir($adsPath)) {
$perms = substr(sprintf('%o', fileperms($adsPath)), -4);
echo " Ads directory permissions: {$perms}\n";
}
echo "\n";
// Check web server user
echo "6. Server information:\n";
echo " PHP running as user: " . get_current_user() . "\n";
echo " PHP process owner: " . (function_exists('posix_geteuid') ? posix_getpwuid(posix_geteuid())['name'] : 'unknown') . "\n";
echo "\n";
echo "=======================\n";
echo "Test URLs:\n";
echo "=======================\n";
if (is_dir($adsPath)) {
$images = glob($adsPath . '/*.{jpg,jpeg,png,gif,webp}', GLOB_BRACE);
if (!empty($images)) {
echo "\nTry accessing these URLs in your browser:\n";
foreach (array_slice($images, 0, 3) as $img) {
$filename = basename($img);
echo "https://{$_SERVER['HTTP_HOST']}/storage/ads/{$filename}\n";
}
} else {
echo "\nNo images found to test.\n";
}
}
echo "\n</pre>";
echo "<p><strong>DELETE THIS FILE after viewing results!</strong></p>";
?>