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.new

PHP and the Laravel Installer

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.

XAMPP

Database setup

SQLite is a great option and is installed with just one command (Linux).

SQLite

sudo apt install sqlite3

If you want a GUI for sqlite you can use sqlitebrowser.

DB Browser for SQLite

Another great option is to use Docker, which allows you to run a database management system like PostgreSQL in seconds.

Docker

PostgreSQL

Run Postgres in a Docker Container

To interact with the database running inside the container you can use DBeaver Community.

DBeaver Community

Code editors

Recommended code editors for programming in PHP.

Personally I use Visual Studio Code and Neovim.

PhpStorm

Sublime Text

NvChad - Neovim config

Visual Studio Code

VS Code extensions for PHP

PHP Intelephense

Laravel

Themes and icons

Catppuccin for VSCode

Catppuccin Icons for VSCode

Fonts

JetBrains Mono

Nerd 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

php server

php server