Skip to content

Commit 7609556

Browse files
committed
PHP 'Hello World' Tutorial added
1 parent 8655097 commit 7609556

2 files changed

Lines changed: 84 additions & 0 deletions

File tree

127 KB
Loading

php/lesson1/tutorial.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
---
2+
layout: page
3+
title: Introduction to PHP
4+
---
5+
6+
##### Requirements
7+
8+
* 15 minutes
9+
* PHP installed - this is by default on most Operating Systems
10+
11+
##### Achievements
12+
13+
By the end of this tutorial you will be able to:
14+
15+
* write a **Hello World** Application that outputs on the:
16+
* Command Line (CLI)
17+
* Browser
18+
19+
---
20+
21+
## What is PHP?
22+
23+
From the **PHP** [website](http://php.net/manual/en/intro-whatis.php)
24+
25+
> PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML.
26+
27+
Well what does this mean? It is very easy to build dynamic websites using **PHP** as the server-side language, which generates **html**.
28+
29+
## What does PHP look like?
30+
31+
A simple help world application would look like the following:
32+
33+
*File: index.php*
34+
```php
35+
<?php
36+
echo "Hello World";
37+
```
38+
39+
1. The file must end with the extension `.php`
40+
2. The file must begin with the opening tag `<?php`
41+
3. `"` are used to Open/Close a string
42+
4. 'echo' Outputs the string [echo on php website](http://php.net/manual/en/function.echo.php)
43+
44+
## How to run the script?
45+
46+
On the Command Line (CLI), type:
47+
48+
```php
49+
php index.php
50+
```
51+
52+
And the out will be:
53+
54+
```bash
55+
$ php index.php
56+
Hello World
57+
```
58+
59+
*Note: `$` implies the Command Line shell, you did not need to type this.*
60+
61+
## How to the output in the browser?
62+
63+
Seeing it on the Command Line is great, but what about the browser? We will need to get a WebServer running, the easiest way is to use the buil-in PHP WebServer.
64+
65+
*Note: Built-in PHP WebServer is great for Development, but **NOT** Production.*
66+
67+
Go to the directory where you created the `index.php` file and run the following command:
68+
69+
```bash
70+
$ php -S 0.0.0.0:8080
71+
```
72+
73+
1. You are already familiar with the `php` command from before
74+
2. `-S` means built-in WebServer
75+
3. `0.0.0.0` is the IP that the WebServer should listen on. By using `0` it will listen on everything - fine for development
76+
4. `8080` is the port to listen on - fine for development but in production the default port is `80` and therefore not required when accessing a URL
77+
78+
Lets see the script output in the browser, in your browser (ideally **Firefox** or **Chrome**) navigate to ` http://localhost:8090/` and you should see:
79+
80+
![Hello World](assets/images/helloworld.png)
81+
82+
## Conclusion
83+
84+
**PHP** is very easy to learn and developer Dynamic Websites and Web Applications with.

0 commit comments

Comments
 (0)