PHP basics - 01
This is a tutorial on how to install and start programming in PHP
Installation
This command will install PHP, Composer, and the Laravel installer on macOS, Windows, or Linux.
php --version
PHP 8.4.1 (cli) (built: Nov 21 2024 08:58:25) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.1, Copyright (c) Zend Technologies
---
composer --version
Composer version 2.8.3 2024-11-17 13:13:04
PHP version 8.4.1 (/home/$USER/.config/herd-lite/bin/php)
Run the "diagnose" command to get more detailed diagnostics output.
---
laravel --version
Laravel Installer 5.14.0
You can also use XAMPP, which includes Apache, MariaDB, and PHP.
Database setup
SQLite is a great option and is installed with just one command (Linux).
sudo apt install sqlite3
If you want a GUI for sqlite you can use sqlitebrowser.
Another great option is to use Docker, which allows you to run a database management system like PostgreSQL in seconds.
Run Postgres in a Docker Container
To interact with the database running inside the container you can use DBeaver Community.
Code editors
Recommended code editors for programming in PHP.
Personally I use Visual Studio Code and Neovim.
VS Code extensions for PHP
Themes and icons
Fonts
First Program
Create a file called index.php in any code editor of your choice.
Each block of PHP code must go inside <?php ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>PHP - Hello, World!</title>
</head>
<body>
<h1>
<?php echo 'Hello, World!'; ?>
</h1>
</body>
</html>
Now start the server
php -S localhost:8080