INTERNET AND HTTP PROTOCOL

php logoBefore talking about the PHP language, it is good to make some premises on the web. We can consider the Internet as a series of interconnected devices. Generally these devices on the internet are called hosts or peripheral systems. Hosts are connected to each other via a series of links (wi-fi, fiber) and routers. In order for hosts to communicate properly, it is necessary to have rules for exchanging data. These rules are called protocols. When we open a browser and enter an address to visit a website, technically a communication has taken place between our device (PC, smartphone, tablet and so on) and the device that hosts the website. In this type of communication, our device is called the client while the other server. It is the client server model that we know well as it has been treated several times. More information on the http protocol can be found at this address: https://www.marcoalbasini.com/2021/07/livello-applicazione-il-protocollo-http/

model client server.

MAKE A REQUEST

The http protocol is implemented both on the client side and on the server side, client side in the web browser, server side within an application called web server. A server is a device that hosts and provides resources within the internet, resources that can be reached via URL (Universal Resource Locator). Let’s suppose that the client requests the php documentation, via HTTPS protocol which is essentially http but with an additional security level, the encryption of the exchanged data. But how do we know the address of the server hosting the PHP documentation? Just as every home is equipped with a house number, post code, address so that if we want to write a letter to a friend of ours we know how to reach him, even the devices connected to the Internet have a unique address called IP (Internet Protocol). When the client makes the request to the server, in addition to information on the content sought, it also sends its IP address. We said that on the server side the http protocol is implemented in the web server; therefore, the exchange of data takes place between the browser and the web server.

Request

LANGUAGES ON THE SERVER SIDE AND THE CLIENT SIDE. THE DNS

When a client enters a URL address via a browser, the domain name is transformed via the DNS server into the IP address of the host on which the requested resource resides. DNS servers are servers present in the network whose task is to associate the IPs with the corresponding domains. When a request is made, for example, to google.com, this mnemonic name is transformed into the IP address of the Google server. The request can be a multimedia file, but also an html page or a PHP script. PHP language is a scripting language that runs on the server (Apache or Nginx).

DNS

There are two types of languages, those compiled and those interpreted. Let’s see a figure.

Languages

But let’s go back to our client-server model, when a client makes a request for a PHP script, the web server is not able to immediately return the answer, this is because as we said the PHP language or rather the language code must first be interpreted. 

Request script PHP

Since the browser is not able to understand the PHP code, on the web server side the interpreted code is transformed into an HTML page understandable by the browser.

Response script PHP

PREPARE THE ENVIRONMENT

In order for us to develop and test our PHP applications, we need to configure the device as both a client and a server. As a client it is already able to operate as we have a web browser, as a server we need a web server capable of taking charge and managing requests. The two most used web servers are Apache and Nginx, each has pros and cons. The software to be installed on the server side, in addition to the web server, are PHP and MySQL. In fact, the data of our PHP applications could be dynamic, hence the need to store them in a MySQL database. In these posts we will use XAMPP as a software environment, it already has all the components we need in it, also as a development environment we will use Visual Studio Code.

Predisposition

INSTALL XAMPP ON WINDOWS AND V.S CODE

As regards XAMPP, the application can be found at the following address: https://www.apachefriends.org/ choose the version for your operating system. Download and install the program, the default directory is fine ie c: \ xampp under Windows. Obviously, install Apache web server, MySQL and phpMyAdmin to manage the database.

Il linguaggio PHP. XAMPP

Apache connects on port 80 for http connections and on port 443 for https connections. If you have these ports busy, Apache will not start unless you manipulate the configuration files. The advice at the moment is to free the ports in use. Once XAMPP is installed, type http: // localhost to verify that the installation was successful. As regards V.S Code, the address is as follows: https://code.visualstudio.com/ Download and install the version for your operating system, and add extensions for PHP.

Il Linguaggio PHP, Extension V.S Code