r/PHPhelp • u/hungryaf2 • Jul 29 '22
Solved What is the relation between PHP and Apache
Apache need PHP to work, or could be any other language?
2
u/dabenu Jul 29 '22
It might be fair to say there's no relation at all. Not from a technical point of view anyway. They're both very different pieces of software serving very different purposes. Neither depends on the other.
The only real relationship is that it happens to be a popular combination to run on a webserver.
1
5
u/ZLegacy Jul 29 '22
Apache is handling the http piping. It grabs the file, sends it off to php to process, then sends it back to the user.
3
u/ontelo Jul 29 '22
Apache is webserver, php is scripting language.
PHP does not need apache but can work "under" it
2
u/McUsrII Jul 29 '22
Php has a development server, it can work with serving one client which is very useful for having a private lightweight server locally.
A webserver can fork one instance of php for each client, and it can setup access privileges.
Comparing a webserver to php, is akin to comparing MySql and sqlite.
1
u/olefart75 Jul 31 '22
Apache is a server. It translates and generates web (HTTP) languages and displays the content the web code creates in a web browser. PHP needs Apache, Apache does not need PHP.
PHP is one of the many languages Apache translates into web content.
14
u/gordonv Jul 29 '22
Apache is a program, or daemon, that has 1 job. To serve websites in the HTTP and HTTPS protocols. Commonly known as a web server.
Take static files and push them through the protocols
Take requests from clients and run small programs that produce output, and forward that output to the client.
PHP is an interpreted scripting language. The code is read from a plain text file and then interpreted as instructions. These instructions can do many things.
PHP can:
Run from the command line
Call other programs
Do network and process communication
Output text data so other programs (like Apache) can pick it up.
The relationship of Apache and PHP, is that Apache acts like a broadcaster. It gives out information. PHP acts like a brain. It can take data input, "think" about it, and output data as a response.
For example:
A user wants to know how many bananas are in the database.
User goes to a website.
Apache serves the website.
User clicks the banana count link.
The signal is sent/interpreted by Apache, and Apache points to the PHP code that pulls the number of bananas from a database.
PHP returns the answer to Apache
Apache serves the answer to the user