@@ -41,8 +41,21 @@ fn get_installation_path() -> PathBuf {
4141 // First, try to get the path from the installed location
4242 if let Ok ( exe_path) = env:: current_exe ( ) {
4343 if let Some ( parent) = exe_path. parent ( ) {
44- // Check if we're in the installed directory (C:\dsb\)
45- if parent. to_string_lossy ( ) . contains ( "dsb" ) || parent. to_string_lossy ( ) . contains ( "DevStackBox" ) {
44+ // Check if we're in any installation directory
45+ let parent_str = parent. to_string_lossy ( ) ;
46+
47+ // Check for C:\dsb\ installation
48+ if parent_str. contains ( "dsb" ) {
49+ return parent. to_path_buf ( ) ;
50+ }
51+
52+ // Check for Program Files installation
53+ if parent_str. contains ( "DevStackBox" ) {
54+ return parent. to_path_buf ( ) ;
55+ }
56+
57+ // Check if this directory actually has our server components
58+ if parent. join ( "apache" ) . join ( "bin" ) . join ( "httpd.exe" ) . exists ( ) {
4659 return parent. to_path_buf ( ) ;
4760 }
4861 }
@@ -63,7 +76,7 @@ fn get_installation_path() -> PathBuf {
6376 }
6477 }
6578
66- // Final fallback - try common installation paths
79+ // Try common installation paths in order of preference
6780 let possible_paths = [
6881 PathBuf :: from ( "C:\\ dsb" ) ,
6982 PathBuf :: from ( "C:\\ Program Files\\ DevStackBox" ) ,
@@ -171,16 +184,40 @@ async fn debug_installation() -> Result<HashMap<String, String>, String> {
171184 let install_path = get_installation_path ( ) ;
172185 debug_info. insert ( "detected_install_path" . to_string ( ) , install_path. display ( ) . to_string ( ) ) ;
173186
174- // Check if server components exist
175- let apache_exists = install_path. join ( "apache" ) . join ( "bin" ) . join ( "httpd.exe" ) . exists ( ) ;
176- let mysql_exists = install_path. join ( "mysql" ) . join ( "bin" ) . join ( "mysqld.exe" ) . exists ( ) ;
177- let php_exists = install_path. join ( "php" ) . join ( "8.2" ) . join ( "php.exe" ) . exists ( ) ;
178- let phpmyadmin_exists = install_path. join ( "phpmyadmin" ) . join ( "index.php" ) . exists ( ) ;
187+ // Check if server components exist with detailed paths
188+ let apache_bin = install_path. join ( "apache" ) . join ( "bin" ) . join ( "httpd.exe" ) ;
189+ let mysql_bin = install_path. join ( "mysql" ) . join ( "bin" ) . join ( "mysqld.exe" ) ;
190+ let php_bin = install_path. join ( "php" ) . join ( "8.2" ) . join ( "php.exe" ) ;
191+ let phpmyadmin_index = install_path. join ( "phpmyadmin" ) . join ( "index.php" ) ;
192+
193+ debug_info. insert ( "apache_bin_path" . to_string ( ) , apache_bin. display ( ) . to_string ( ) ) ;
194+ debug_info. insert ( "apache_exists" . to_string ( ) , apache_bin. exists ( ) . to_string ( ) ) ;
195+
196+ debug_info. insert ( "mysql_bin_path" . to_string ( ) , mysql_bin. display ( ) . to_string ( ) ) ;
197+ debug_info. insert ( "mysql_exists" . to_string ( ) , mysql_bin. exists ( ) . to_string ( ) ) ;
198+
199+ debug_info. insert ( "php_bin_path" . to_string ( ) , php_bin. display ( ) . to_string ( ) ) ;
200+ debug_info. insert ( "php_exists" . to_string ( ) , php_bin. exists ( ) . to_string ( ) ) ;
179201
180- debug_info. insert ( "apache_exists" . to_string ( ) , apache_exists. to_string ( ) ) ;
181- debug_info. insert ( "mysql_exists" . to_string ( ) , mysql_exists. to_string ( ) ) ;
182- debug_info. insert ( "php_exists" . to_string ( ) , php_exists. to_string ( ) ) ;
183- debug_info. insert ( "phpmyadmin_exists" . to_string ( ) , phpmyadmin_exists. to_string ( ) ) ;
202+ debug_info. insert ( "phpmyadmin_path" . to_string ( ) , phpmyadmin_index. display ( ) . to_string ( ) ) ;
203+ debug_info. insert ( "phpmyadmin_exists" . to_string ( ) , phpmyadmin_index. exists ( ) . to_string ( ) ) ;
204+
205+ // Check config files
206+ let apache_config = install_path. join ( "config" ) . join ( "httpd.conf" ) ;
207+ let mysql_config = install_path. join ( "config" ) . join ( "my.cnf" ) ;
208+
209+ debug_info. insert ( "apache_config_path" . to_string ( ) , apache_config. display ( ) . to_string ( ) ) ;
210+ debug_info. insert ( "apache_config_exists" . to_string ( ) , apache_config. exists ( ) . to_string ( ) ) ;
211+
212+ debug_info. insert ( "mysql_config_path" . to_string ( ) , mysql_config. display ( ) . to_string ( ) ) ;
213+ debug_info. insert ( "mysql_config_exists" . to_string ( ) , mysql_config. exists ( ) . to_string ( ) ) ;
214+
215+ // Check permissions by trying to access directories
216+ let apache_dir_readable = install_path. join ( "apache" ) . exists ( ) ;
217+ let mysql_dir_readable = install_path. join ( "mysql" ) . exists ( ) ;
218+
219+ debug_info. insert ( "apache_dir_readable" . to_string ( ) , apache_dir_readable. to_string ( ) ) ;
220+ debug_info. insert ( "mysql_dir_readable" . to_string ( ) , mysql_dir_readable. to_string ( ) ) ;
184221
185222 // Check common installation paths
186223 let common_paths = [
@@ -194,11 +231,16 @@ async fn debug_installation() -> Result<HashMap<String, String>, String> {
194231 let exists = path_buf. exists ( ) ;
195232 let apache_in_path = path_buf. join ( "apache" ) . join ( "bin" ) . join ( "httpd.exe" ) . exists ( ) ;
196233 debug_info. insert (
197- format ! ( "path_{}_exists " , path. replace( "\\ " , "_" ) . replace( ":" , "" ) ) ,
198- format ! ( "dir : {}, apache : {}" , exists, apache_in_path)
234+ format ! ( "path_{}_status " , path. replace( "\\ " , "_" ) . replace( ":" , "" ) ) ,
235+ format ! ( "dir_exists : {}, apache_exists : {}" , exists, apache_in_path)
199236 ) ;
200237 }
201238
239+ // Check current working directory
240+ if let Ok ( cwd) = env:: current_dir ( ) {
241+ debug_info. insert ( "current_working_dir" . to_string ( ) , cwd. display ( ) . to_string ( ) ) ;
242+ }
243+
202244 Ok ( debug_info)
203245}
204246
@@ -221,6 +263,43 @@ async fn stop_all_services() -> Result<String, String> {
221263 Ok ( results. join ( "; " ) )
222264}
223265
266+ #[ tauri:: command]
267+ async fn test_apache_config ( ) -> Result < String , String > {
268+ let base_path = get_installation_path ( ) ;
269+ let apache_path = base_path. join ( "apache" ) . join ( "bin" ) . join ( "httpd.exe" ) ;
270+ let config_path = base_path. join ( "config" ) . join ( "httpd.conf" ) ;
271+
272+ if !apache_path. exists ( ) {
273+ return Err ( format ! ( "Apache binary not found at: {}" , apache_path. display( ) ) ) ;
274+ }
275+
276+ if !config_path. exists ( ) {
277+ return Err ( format ! ( "Apache config not found at: {}" , config_path. display( ) ) ) ;
278+ }
279+
280+ // Test Apache configuration
281+ let mut test_cmd = create_hidden_command ( & apache_path. to_string_lossy ( ) ) ;
282+ test_cmd. arg ( "-f" )
283+ . arg ( & config_path)
284+ . arg ( "-t" )
285+ . stdout ( std:: process:: Stdio :: piped ( ) )
286+ . stderr ( std:: process:: Stdio :: piped ( ) ) ;
287+
288+ match test_cmd. output ( ) {
289+ Ok ( output) => {
290+ let stdout = String :: from_utf8_lossy ( & output. stdout ) ;
291+ let stderr = String :: from_utf8_lossy ( & output. stderr ) ;
292+
293+ if output. status . success ( ) {
294+ Ok ( format ! ( "Apache config test PASSED\n Output: {}\n Path used: {}" , stdout, apache_path. display( ) ) )
295+ } else {
296+ Err ( format ! ( "Apache config test FAILED\n Error: {}\n Output: {}\n Path used: {}" , stderr, stdout, apache_path. display( ) ) )
297+ }
298+ }
299+ Err ( e) => Err ( format ! ( "Failed to run Apache config test: {}\n Path: {}" , e, apache_path. display( ) ) ) ,
300+ }
301+ }
302+
224303#[ tauri:: command]
225304async fn get_mysql_status ( ) -> Result < ServiceInfo , String > {
226305 let running = {
@@ -1117,6 +1196,7 @@ pub fn run() {
11171196 debug_paths,
11181197 debug_installation,
11191198 stop_all_services,
1199+ test_apache_config,
11201200 get_mysql_status,
11211201 get_php_status,
11221202 get_apache_status,
0 commit comments