Marwan
Marwan

Reputation: 25

Php, Apache and MySQL

I have conflict with the concept of communication with database.

If I have a website I can't access MySQL directly, I need a web server which is PHP to communicate with MySQL, and PHP will communicate with the website using HTML right? What about the role of Apache? And why do we need WampServer if we have these tools? We can create our own server and let the software run on it.

I'm doing a senior project to my university but I don't know what tool I want to use due to the miss understanding of these concepts.

Upvotes: 0

Views: 556

Answers (3)

gmfm
gmfm

Reputation: 669

(this was going to be a comment in response to @marwan s comment "My project is android app that contains a large database, so if I want to use the server do I need to use php? And php is only used for websites, so what I can use for android app?", but ran out of characters)

@Marwan you could directly connect your android app to to a database, though this isn't recommended, Why don't connect android to database directly? , There are many reasons not to, security being a major one. Php is used for web services which may or may not be presented as human readable web pages. Many web services are used to create output which is meant to be consumed by other programs. An android app would use one of these services, Like a RESTful api (http://www.drdobbs.com/web-development/restful-web-services-a-tutorial/240169069) to retrieve data from or database or offload processing from the client (android app) to the server.

There are more languages and more servers that could be used other than just php and apache, but this is a very common setup (my personal favorite).

If you'd like to learn about apache and and php I suggest setting up a LAMP server over a WAMP server, the software is open source and therefore makes a great learning tool (https://www.atlantic.net/blog/why-startups-prefer-lamp-to-wamp/). If you don't have a linux machine you could run a LAMP stack on a VM, https://www.virtualbox.org/, https://www.vmware.com/products/player, possibly even a rasberry pi https://www.element14.com/community/community/raspberry-pi/raspberrypi_projects/blog/2014/02/24/raspberry-pi-as-a-lamp-server/. There's plenty of how-to's out there for intalling a LAMP stack on linux (https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-14-04, unbuntu 14.04).

Php is pretty well documented with plenty of tutorials, and lots of Q&A on SO. http://php.net/manual/en/index.php

http://php.net/manual/en/tutorial.php

http://www.w3schools.com/php/

https://stackoverflow.com/questions/tagged/php

Upvotes: 0

omnichad
omnichad

Reputation: 1655

Apache is a web server, it takes requests via the HTTP protocol and responds with either a file's contents or the result of a script.

PHP is a server-side scripting language (in this context). When Apache receives a request for this type of file, it responds with the output of running it as a program.

PHP can interact with a database such as MySQL to store and retrieve data.

WampServer is a prepackaged collection of all these that can help you get a development environment up and running quickly.

Upvotes: 2

user2162942
user2162942

Reputation: 74

PHP is not a web server, it is merely a language that runs on top of a web server. Apache is the web server. PHP runs on top of Apache. The reason for tools such as WampSever/XAMP/LAMP, are just to bundle these softwares together. Installing PHP, Apache, MySQL, etc, and configuring them to work together can take a while. WAMP/XAMP/LAMP makes it easier to quickly deploy these software packages.

Upvotes: 3

Related Questions