Introduction to PHP for web developers 2018
I recently stumbled upon a guide for coding PHP the right way. On this site they go through most aspects of the PHP language and history, from basic syntax all the way through testing and deployments. This tutorial is an introduction for programmers that might not be familiar with modern PHP.
At the simplest level we can run a PHP script by starting a web server.
php -S localhost:8000
This assumes that you have already installed PHP or have a version pre-installed on your machine. One of the latest versions is 7.2, 5.4 is another popular version. There is no PHP version 6.
Create a PHP file touch index.php with the contents:
Congratulations! You started a local PHP server and printed out some contents. You can view this text on http://localhost:8000. What’s nifty about PHP is that it was built for the web and has html in mind. Add HTML to your PHP file and watch it render properly in the browser.
$title = 'My first PHP website';
$whereItsGood = 'Hood';
<title><?php echo $title; ?></title>
<li><?php echo $whereItsGood; ?></li>
To start a project from scratch you can run
composer init which will create a composer.json file. Most developers choose to use a PHP Framework when building web applications. Personally I recommend building with Laravel!
Below are some community resources of popular PHP packages:
Our goal is to develop PHP packages of the highest quality possible, using modern tools, standards and practices to…thephpleague.com
The Components: How to Install and Use the Symfony Components The Asset Component The BrowserKit Component The Cache…symfony.com
Update 04/01/18: This is a great intro to building PHP without a framework