0

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.

Marwan
  • 25
  • 1
  • 5
  • Look at this image, simple but clear: http://alanhou.com/homepage/wp-content/uploads/2014/01/php-operational-trail.jpg – JP. Aulet Apr 01 '16 at 00:52

3 Answers3

3

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.

  • it seems clear but it is mandatory that whenever I use php I must use the apache? And how can I configure them to work together? please if we can go in more details because I want to finish this topic and understand them well or if you know any tutorials for explaining concepts. Thanks – Marwan Mar 31 '16 at 22:17
  • it is not required you use apache. you can use any webserver that supports PHP (i.e. IIS) If you are having trouble configuring them just WAMP? Or here's a tutorial: http://php.net/manual/en/install.windows.apache2.php – user2162942 Mar 31 '16 at 22:24
2

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.

omnichad
  • 1,635
  • 1
  • 11
  • 10
  • Do you have any tutorials that can help me with understanding these concepts? – Marwan Mar 31 '16 at 22:33
  • I don't. I would recommend installing WampServer and trying to place files into the web root and see if that will help. I don't know what you're trying to do in your project, so I can't say if this is the best tool but it's certainly a flexible place to start. – omnichad Mar 31 '16 at 23:19
  • I want to learn concepts about the role of these tools apache, php with MySQL and with websites and mobile app. – Marwan Apr 01 '16 at 00:57
  • 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?? – Marwan Apr 01 '16 at 00:59
  • PHP is used on web sites, but does not necessarily have to output HTML. HTTP is a useful protocol for App-server communication and you can send/receive XML or JSON or any format you wish. – omnichad Apr 01 '16 at 13:47
0

(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

Community
  • 1
  • 1
gmfm
  • 659
  • 8
  • 21