navbeacon Posted December 4, 2007 Share Posted December 4, 2007 I've struggled with this the past few days. I'm using system(); to run a .bat-file which restarts the apache2 server. It works when i execute the .bat-file from the desktop, but when I tell PHP to do it, it reports success but the server does not restart. The apache error.log tells me: httpd: illegal option -- k The .bat im using contains: c:\apache\bin\httpd -k restart What's wrong? Do I have to set permissions for PHP somewhere? I'm using Windows Server 2008. Quote Link to comment https://forums.phpfreaks.com/topic/80147-restarting-apache-through-php/ Share on other sites More sharing options...
steviewdr Posted December 5, 2007 Share Posted December 5, 2007 system() or shell_exec() do not return whether or not a command is carried out fully. I.e. there is no kill option with these commands. I suspect you will need some other httpd option, e.g.: c:\apache\bin\httpd -k -E httpd.conf restart This might help: HTTPD( httpd HTTPD( NAME httpd - Apache Hypertext Transfer Protocol Server SYNOPSIS httpd [ -d serverroot ] [ -f config ] [ -C directive ] [ -c directive ] [ -D parameter ] [ -e level ] [ -E file ] [ -k start|restart|graceful|stop|graceful-stop ] [ -R directory ] [ -h ] [ -l ] [ -L ] [ -S ] [ -t ] [ -v ] [ -V ] [ -X ] [ -M ] On Windows systems, the following additional arguments are available: httpd [ -k install|config|uninstall ] [ -n name ] [ -w ] SUMMARY httpd is the Apache HyperText Transfer Protocol (HTTP) server program. It is designed to be run as a standalone daemon process. When used like this it will create a pool of child processes or threads to handle requests. In general, httpd should not be invoked directly, but rather should be invoked via apachectl on Unix-based systems or as a service on Windows NT, 2000 and XP and as a console application on Windows 9x and ME. -steve Quote Link to comment https://forums.phpfreaks.com/topic/80147-restarting-apache-through-php/#findComment-406501 Share on other sites More sharing options...
navbeacon Posted December 5, 2007 Author Share Posted December 5, 2007 Nope, that didnt work. Wierd thing is that if i run "C:\apache\bin\httpd.exe" -k restart from the windows command line it works. But it just will not work from php. Errors fron the command line seems to log directly to error.log. Here's what is says: Usage: C:\\apache\\bin\\httpd.exe [-D name] [-d directory] [-f file] [-C "directive"] [-c "directive"] [-w] [-k start|restart|stop|shutdown] [-k install|config|uninstall] [-n service_name] [-v] [-V] [-h] [-l] [-L] [-t] [-S] Options: -D name : define a name for use in <IfDefine name> directives -d directory : specify an alternate initial ServerRoot -f file : specify an alternate ServerConfigFile -C "directive" : process directive before reading config files -c "directive" : process directive after reading config files -n name : set service name and use its ServerConfigFile -k start : tell Apache to start -k restart : tell running Apache to do a graceful restart -k stop|shutdown : tell running Apache to shutdown -k install : install an Apache service -k config : change startup Options of an Apache service -k uninstall : uninstall an Apache service -w : hold open the console window on error -e level : show startup errors of level (see LogLevel) -E file : log startup errors to file -v : show version number -V : show compile settings -h : list available command line options (this page) -l : list compiled in modules -L : list available configuration directives -t -D DUMP_VHOSTS : show parsed settings (currently only vhost settings) -S : a synonym for -t -D DUMP_VHOSTS -t -D DUMP_MODULES : show all loaded modules -M : a synonym for -t -D DUMP_MODULES -t : run syntax check for config files httpd.exe: illegal option -- k ... which leaves me looking like a ???. Quote Link to comment https://forums.phpfreaks.com/topic/80147-restarting-apache-through-php/#findComment-407107 Share on other sites More sharing options...
DK_Sun Posted December 5, 2007 Share Posted December 5, 2007 What you need to do is make sure that Apache is running as a Service, and once you've done that, just make the batch script run the net command. Here's an example of one I use... @echo off net stop Apache2 && net start Apache2 Hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/80147-restarting-apache-through-php/#findComment-407248 Share on other sites More sharing options...
navbeacon Posted December 5, 2007 Author Share Posted December 5, 2007 Yes! That worked. Thanks! Now, is there a way to run that from a .php-file and display "Success!" when the server have restarted, instead of it timimg out? Quote Link to comment https://forums.phpfreaks.com/topic/80147-restarting-apache-through-php/#findComment-407295 Share on other sites More sharing options...
navbeacon Posted December 5, 2007 Author Share Posted December 5, 2007 Here's an example of one I use... @echo off net stop Apache2 && net start Apache2 Hope that helps. Is it possible to do a graceful restart through this method? Quote Link to comment https://forums.phpfreaks.com/topic/80147-restarting-apache-through-php/#findComment-407365 Share on other sites More sharing options...
DK_Sun Posted December 7, 2007 Share Posted December 7, 2007 Yup. What that does is a graceful shut down of Apache, and then just restarts it as normal. Quote Link to comment https://forums.phpfreaks.com/topic/80147-restarting-apache-through-php/#findComment-408672 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.