logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Other Software View previous topic :: View next topic
Reply to topic   Topic: Apache as a service randomly works serving PHP [SOLVED]
Author
TPXP



Joined: 13 Mar 2012
Posts: 5

PostPosted: Tue 13 Mar '12 18:34    Post subject: Apache as a service randomly works serving PHP [SOLVED] Reply with quote

Hi everyone,

I've just installed Apache HTTPD 2.4.1 for Win32 on my computer which runs under Windows 7 Ultimate 64-bit edition.

I've added the PHP extension, and virtualhosts so that I can host multiple websites on my computer without having a lot of directories and the trouble related Very Happy .

However, something very strange happens : When I launch Apache with the Command Prompt (as Administrator of course), everything runs right, but when I run Apache as a Service, it answers correctly on port 80 but it doesn't do so on port 81 and 82 when I ask ONLY a PHP file wich works correctly on port 80 and with the command prompt!!

Here's my httpd.conf :
Code:
AcceptFilter http none
EnableSendfile Off
EnableMMAP off

Listen 80
Listen 81
Listen 82

LoadModule php5_module "C:\Program Files (x86)\PHP\php5apache2_4.dll"

ServerAdmin admin@example.com
ServerName example.com

<Directory />
    AllowOverride All
    Require all denied
</Directory>

<IfModule dir_module>
    DirectoryIndex index.php index.html index.htm
</IfModule>

AddHandler application/x-httpd-php .php
PHPIniDir "C:/Program Files (x86)/PHP"

<VirtualHost *:80>
DocumentRoot "c:/www"
<Directory "c:/www">
allow from all
require all granted
</Directory>
</VirtualHost>

<VirtualHost *:81>
DocumentRoot "c:/www2/web"
<Directory "c:/www2/web">
allow from all
require all granted
</Directory>
</VirtualHost>

<VirtualHost *:82>
DocumentRoot "c:/www1"
AddHandler application/x-httpd-php .php
<Directory "c:/www1">
allow from all
require all granted
</Directory>
</VirtualHost>


And here's what I can see in the error log when I ask for a PHP file :
Code:
[Tue Mar 13 17:37:34.377738 2012] [mpm_winnt:notice] [pid 2092:tid 468] AH00428: Parent: child process exited with status 255 -- Restarting.
[Tue Mar 13 17:37:34.442741 2012] [mpm_winnt:notice] [pid 2092:tid 468] AH00455: Apache/2.4.1 (Win32) configured -- resuming normal operations
[Tue Mar 13 17:37:34.442741 2012] [mpm_winnt:notice] [pid 2092:tid 468] AH00456: Server built: Mar  5 2012 21:22:17
[Tue Mar 13 17:37:34.442741 2012] [core:notice] [pid 2092:tid 468] AH00094: Command line: 'C:\\Program Files (x86)\\Apache24\\bin\\httpd.exe -d C:/Program Files (x86)/Apache24'
[Tue Mar 13 17:37:34.482744 2012] [mpm_winnt:notice] [pid 2092:tid 468] AH00418: Parent: Created child process 4108
[Tue Mar 13 17:37:35.641810 2012] [mpm_winnt:notice] [pid 4108:tid 364] AH00354: Child: Starting 64 worker threads.


So, here's the problem, thank you for your help!

TPXP

PS : Sorry for my bad English, I'm french


Last edited by TPXP on Sat 17 Mar '12 11:02; edited 3 times in total
Back to top
glsmith
Moderator


Joined: 16 Oct 2007
Posts: 2268
Location: Sun Diego, USA

PostPosted: Wed 14 Mar '12 7:17    Post subject: Reply with quote

Well, I find it odd things work from command line and not service. I would think they would fail on both looking at that config.

There's Name based and IP based Virtual Hosts, not Port based.
Back to top
TPXP



Joined: 13 Mar 2012
Posts: 5

PostPosted: Wed 14 Mar '12 9:42    Post subject: Reply with quote

Yes, exactly, that's why it's very strange...

As you see, I wrote in my config file
Code:
Listen 80
Listen 81
Listen 82


So, I think that my Apache listens on ports 80,81 and 82 and I redirect the requests to differents directory using the virtualhosts, I don't think to be wrong saying "My Apache hosts websites on different ports".
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3092
Location: Hilversum, NL, EU

PostPosted: Wed 14 Mar '12 12:26    Post subject: Reply with quote

The subject of your post is: Apache as a service with PHP randomly works..
It works with html ?

When I understand you wright:

All is fine when you run Apache from the command line ?
http://xxx.com:80/ ok, serves c:/www
http://xxx.com:81/ ok, serves c:/www2/web
http://xxx.com:82/ ok, serves c:/www1

And when you run as service:
http://xxx.com:80/ ok, serves c:/www
http://xxx.com:81/ not_ok, what error do you get ?
http://xxx.com:82/ not_ok, what error do you get ?

What I miss is a default host as first vhost. Using a default vhost with a wildcard port effectively prevents any request going to the main server.

<VirtualHost _default_:*>
DocumentRoot c:/www/default (put there an index.html)
</VirtualHost>


You can remove: allow from all, Require all granted is enough.

Why you have at the 82 vhost again: AddHandler application/x-httpd-php .php ?

Give every vhost a ServerName.


Steffen
Back to top
TPXP



Joined: 13 Mar 2012
Posts: 5

PostPosted: Wed 14 Mar '12 16:53    Post subject: Reply with quote

Hi Steffen,

Here's my new httpd.conf

Code:
Listen 80
Listen 81
Listen 82


LoadModule php5_module "C:\Program Files (x86)\PHP\php5apache2_4.dll"

ServerAdmin tpxp@live.fr
ServerName tpxp.dyndns.org

<Directory />
    AllowOverride All
    Require all denied
</Directory>

DocumentRoot "c:/www"
<Directory "c:/www">
require all granted
</Directory>

<IfModule dir_module>
    DirectoryIndex index.php index.html index.htm
</IfModule>

AddHandler application/x-httpd-php .php
PHPIniDir "C:/Program Files (x86)/PHP"

<VirtualHost *:81>
DocumentRoot "c:/www1"
Servername tpxp.dyndns.org:81
<Directory "c:/www1">
require all granted
</Directory>
</VirtualHost>


<VirtualHost *:82>
DocumentRoot "c:/www2/web"
Servername tpxp.dyndns.org:82
<Directory "c:/www2/web">
require all granted
</Directory>
</VirtualHost>


When I ask for a PHP file while running apache as a service for the two virtualhosts, I can read in the error log :


And the browser says error 324 (ERR_EMPTY_RESPONSE)
Code:
[Wed Mar 14 15:52:11.740297 2012] [mpm_winnt:notice] [pid 6168:tid 468] AH00428: Parent: child process exited with status 255 -- Restarting.
[Wed Mar 14 15:52:11.813301 2012] [mpm_winnt:notice] [pid 6168:tid 468] AH00455: Apache/2.4.1 (Win32) configured -- resuming normal operations
[Wed Mar 14 15:52:11.813301 2012] [mpm_winnt:notice] [pid 6168:tid 468] AH00456: Server built: Mar  5 2012 21:22:17
[Wed Mar 14 15:52:11.813301 2012] [core:notice] [pid 6168:tid 468] AH00094: Command line: 'C:\\Program Files (x86)\\Apache24\\bin\\httpd.exe -d C:/Program Files (x86)/Apache24'
[Wed Mar 14 15:52:11.847303 2012] [mpm_winnt:notice] [pid 6168:tid 468] AH00418: Parent: Created child process 3084
[Wed Mar 14 15:52:12.831359 2012] [mpm_winnt:notice] [pid 3084:tid 360] AH00354: Child: Starting 64 worker threads.


I totally agree with you, this is very strange, that's why I need help Smile

TPXP
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3092
Location: Hilversum, NL, EU

PostPosted: Wed 14 Mar '12 17:06    Post subject: Reply with quote

You did not answers my questions and added not all the suggestions.

Please do not post you http.conf, see forum rules. I shall shorten it.

Steffen
Back to top
TPXP



Joined: 13 Mar 2012
Posts: 5

PostPosted: Thu 15 Mar '12 16:09    Post subject: Reply with quote

So, I tried to add the following to my httpd.conf :
Code:
<VirtualHost _default_:*>
DocumentRoot c:/www/default
</VirtualHost>


By doing this, the server serves an empty file (the content of the index.html) on port 80.

Let me re-explain : When I run Apache as a service, it can serve any file (including PHP files) on port 80, but on port 81 and 82 it can serve every file except PHP, while when I run it using command prompt, it works great for every file on every port!

I hope everything is now clear for everyone Smile
Back to top
tdonovan
Moderator


Joined: 17 Dec 2005
Posts: 611
Location: Milford, MA, USA

PostPosted: Thu 15 Mar '12 23:05    Post subject: Reply with quote

The problem could be the user-name that Apache is running as, and the file permissions.

When you run from the command line, Apache is running as your user-name, which probably is 'Administrator', or else an account which is a member of the 'Administrators' group.

When you run as a service, the service runs as user: 'Local System' by default.

It could be that Apache running as a service cannot read or execute one of the PHP shareable libraries, or maybe it cannot read the contents of C:\www2\web or C:\www1.
You could check the access permissions for files in these directories.

Another test you could try is to change the service to use your own user-name instead of 'Local System'.
To do this - find the Apache service in [Control Panel] [Administrative Tools] [Services], right-click on it, and choose [Properties], then the [Log On] tab.

It would also be interesting to check your logs\access.log file to see if any entry is made for the failed requests.

-tom-
Back to top
TPXP



Joined: 13 Mar 2012
Posts: 5

PostPosted: Sat 17 Mar '12 11:01    Post subject: Reply with quote

Hi tdonovan,

I checked the permissions, they are the same for each directory, so I tried changing the service's parameters, and IT WORKS!.

In fact, I changed the parameters so that the service runs as my username, and it works Smile .

Thank you very much for your help!
Back to top


Reply to topic   Topic: Apache as a service randomly works serving PHP [SOLVED] View previous topic :: View next topic
Post new topic   Forum Index -> Other Software