PHP? What’s that? What’s the point?
PHP is a programming language. It is adapted to the realization of scripts (launched online order, in the background, or other tasks) but owes its notoriety above all to the ease it brings to the setting up of websites.
PHP is an interpreted language. There is no need to compile (or deploy) the code before you can run it. It is therefore particularly simple to implement once the interpreter is installed.
PHP can generate a bit of any kind of result. It is therefore possible to create any type of text document such as HTML, XML, JSON, JS, CSS, raw text, etc. but also any type of binary document such as JPEG images, PNG, etc. PDF documents, ZIP files, etc. PHP can interface with many applications. It is therefore possible to query and write in many types of databases (MySQL, PostgreSQL, Oracle, SQLite, etc.), LDAP servers, etc. It is possible to send emails, etc.
PHP for internet
This may seem difficult to imagine now, but it must be kept in mind that originally, the web was only composed of static pages written simply in HTML. Static pages are pages that do not change until no one changes the code. Under these conditions, it was, for example, impossible for the website to return a search result based on a request submitted by a visitor (impossible to view a database, impossible to send an email, etc.).
The server that hosts the websites had to evolve to offer more flexibility. To do this, they have integrated the ability to run scripts in order to generate an HTML document and send it back to the user (in other words to display the result in the user’s browser). This is called a dynamic web page. This was done first through a CGI protocol and then through modules that companies or enthusiasts were able to develop.
It is in this context that the PHP script language was born (also initially in a CGI form and now in the form of a module that integrates with the web server whether it is Apache, IIS, or other).
Operating principle
Before we start coding in PHP, let’s take a closer look at the operating principle that has been mentioned above. Keep in mind that when you type a URL (website address) from your browser (called customer) you actually ask a server (software usually running on a remote machine) to return a page. If it is an HTML page (or any static document like an image) then this page will be returned as it is (as written by the “programmer” or “web designer”). In the case of a PHP page, this is a bit more complex.
When a PHP script is called, it goes through the web server (Apache). If the file extension corresponds to what has been defined as the PHP extension (usually .php or .php5, .php4 …), the server asks the PHP interpreter to run the PHP code contained in the file. The execution of this PHP code will eventually result in an exchange of information with the database (or other systems). In the end, it’s (usually) an HTML page (possibly with Javascript, calls to Java applets… finally everything that browsers can understand) that is returned by the PHP script and returned to the web server (Apache). The result is sent to the browser. FIN of the course.
How to test the program
To test a piece of PHP script online, you’ll need to install a PHP interpreter and then launch the “PHP <nom of the php> script. In other words, type “PHP” followed by the name of the PHP script. You will then see the result of the PHP script appear in the console (if it displays something).
A PHP web page
From the previous paragraph, you normally deduced that you can’t read a PHP file (with an extension of the type .php) as simply as you can do with an HTML file. You can’t just use your browser’s “open file” option (or click-slide the script into your browser). Just like an online command script, you need a PHP interpreter. This time, however, it must be integrated into the webserver. You will then need to enter the address (the URL) corresponding to the location of that file on the server in a browser to get the result.
To have a web server, you have 3 great options:
- Go through your host’s web server, which requires no installation effort but is very cumbersome since you have to drop off the scripts to be tested via FTP and does not allow you all possible configurations
- Install a web server on your own computer, which is much more convenient to test and familiarize yourself with how PHP works
- Use the server built into the EXECUTable PHP (which can only be used as a test), which still requires the installation of the PHP environment on your machine and ultimately sometimes more complex than installing a complete server (for which installation kits exist)
Conclusion
Several languages exist and are used for different tasks: creating web pages, web development, software invention, video game creation, there is something for everyone. Among all these languages are Java, C, JavaScript, Python, HTML, and many others. And then there is the most famous PHP. The language is used by more than 70% of the current websites that use server-side scripting. WordPress uses PHP. WordPress is used by 64.5% of all the websites whose content management system we know. This is 40.5% of all websites.
If you want to learn web programming, there is no reason not to learn PHP. Not only that it is easy to learn, but it is also very popular and you could certainly learn a job as a web programmer after completing a PHP course. There are lots of free online resources to learn to code like Codecourse, Stone River eLearning, PHP Manual, PHP 101, Tutorials Point, Tizag, SitePoint, Hacking with PHP, Codeigniter, and many more. If you want more personalized training you could also buy courses at Udemy.