Why do we really need apache + php if php can run as web server?
Solution 1
As someone mentioned already, the server built into the command line interface of PHP is a development only server, it is not fully featured. It exists so that we can internally test things that require a webserver, primarily; it is useful for internals developers. It is useful for PHP programmers to test during development, but it is not intended for deployment of any kind.
The best way we have of serving PHP is to use FCGI; the php-fpm SAPI allows PHP to spool a pool of processes, and for those processes to be isolated from the infrastructure of the server you use for static content.
The server you use for static content should ideally be event driven, such as nginx. The reason is that the majority of requests do not require an interpreter context, the responses (images, css, javascript etc) can be served using non-blocking I/O without initializing an interpreter context.
There is a lot of nonsense in other answers about the abilities of PHP; ignore it, it is nonsense.
Solution 2
PHP's internal webserver is aimed at development. When you publish your app, you need to use a "real" webserver to handle it.
Apache is better in a lot of ways : concurrent users, resources optimization, etc. Even for a small website, its configuration possibilities are far from PHP webserver. Apache is primarly aimed at serving static files; so your styles, images, javascripts (as you're using jQuery, you have some) will be handled in a better way.
Related videos on Youtube
thclpr
Updated on September 18, 2022Comments
-
thclpr over 1 year
A few months ago i did an experiment that kinda went out very well, today we have an intranet portal using the following technologies:
So, based on our tests why do we need to use apache?
PS: I'm not invalidating apache, this question is just for curiosity
: EDIT
When i mean "we", i mean "we" as small teams using small web applications
-
user1906202 over 9 yearsThe question wasn't on PHP quality as a language.
-
peterh over 9 years@Pierre-YvesGillier Yes, but the quality of the php have an important indirect effect to the answer of the question. And I answered about other topics, too, although the quality of the php had a really important part in that.
-
thclpr over 9 yearsGood point, i never questioned about the quality as a language =)
-
peterh over 9 yearsO.k. I think it is the situation with all static data. It were an interesting thing to use php throug some type of a php->java compiler.
-
user1906202 over 9 yearsIBM tried with Project Zero... Not their best idea, for Java & PHP.
-
peterh over 9 yearsI checked after that and it seems for me good! Okay, websphere normally isn't the best solution. Imho, a php-to-java compiler were a better idea.
-
Joe Watkins over 9 yearsdoesn't have a working multithreaded garbage collector this is wrong ...
-
Joe Watkins over 9 yearsIt can't work even in multithreaded environment. this is wrong
-
thclpr over 9 yearsAccepted your answer mainly because i think it's important to point out that having a server running using the command line is only for helping in development. Thanks for everyone for the answers! ( I switched back to apache btw :) )
-
peterh over 9 years@JoeWatkins No, you are wrong. Or can you use the libphp5 apache module with a worker (multithreaded) mpm? No, you can't. Is there any garbage collection in php out of a primitive reference counting? No, there is none. If you are yet here, I will show you in the source code, that there isn't any existing. Your downvotes were unfair, php has its place but it is nowhere anything which is professional.