Jump to content

Restarting Apache through PHP!


navbeacon

Recommended Posts

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.

Link to comment
Share on other sites

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(8)                            httpd                            HTTPD(8)

 

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

Link to comment
Share on other sites

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 ???.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.