Introduction
About PHP
- PHP is a popular server-side scripting language especially suited to web development
- PHP scripts are executed on a web server, in contrast to client-side scripting languages as JavaScript, jQuery, ...
- PHP runs on multiple platforms (Linux, Windows, macOS) and is supported by most web server technologies (Apache, Nginx, IIS)
- PHP is free to use and to host
- A lot of software is written in PHP like Joomla, Drupal, Magento, ...
- There are lots of available PHP frameworks like Symfony, Laravel, Zend, CodeIgniter, ...
- PHP was originally created by Rasmus Lerdorf in 1994 and stood for "Personal Home Page". Nowadays it's a (recursive) acronym for "PHP: Hypertext Preprocessor".
- PHP syntax has a lot of similarities with the C style (C, C#, Java, JavaScript, ...) syntax
- Current stable version: 8.0.10 (but we use the 7.4.x version in this course; see Config > Work environment)
How does it work
- A client calls a PHP page (containing HTML and PHP scripts) in his browser: https://jkwadraat.sinners.be/hello_world.php
- The client's browser contacts the web server
- The web server executes the PHP scripts in hello_world.php (and communicates with the database if necessary), and translates them to HTML code
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello world</title>
</head>
<body>
<h1><?php echo 'Hello world'; ?></h1>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
- The result (plain HTML) is sent to the client's browser
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello world</title>
</head>
<body>
<h1>Hello world</h1>
</body>
</html>
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
A local webserver
- During development, it's easier to work with a local webserver (in order to avoid uploading files after every change)
- Most popular are the so-called XAMP implementations (for example Ampps), where
- X stands for W(indows) -> WAMP, L(inux) -> LAMP or M(acOS) -> MAMP
- A stands for Apache
- M stands for MySQL
- P stands for PHP
- In this course, we will use Homestead, which is a virtual web server environment (including Nginx, MySQL, PHP, ...) that runs on Windows, Linux and MacOS
- Part of Laravel, but can be used for classic PHP web applications as well
Links
- Official website of the PHP language
https://php.net/ - TutorialsPoint PHP tutorial
https://www.tutorialspoint.com/php/ - TutorialRepublic PHP tutorial
https://www.tutorialrepublic.com/php-tutorial/ - W3schools PHP tutorial
https://www.w3schools.com/php/ - W3schools PHP exercises
https://www.w3schools.com/php/exercise.asp - PHP Notes for Professionals (Free PDF book based on StackOverflow documentation)
https://goalkicker.com/PHPBook/