PHP on Ubuntu: Installation, Setup, and First Steps

Prerequisites – installation of Homebrew and asdf on Ubuntu

📘 Official Documentation

PHP – Docs
PHP – On DevDocs.io

⭐ Popular Frameworks

(ordered from lowest to highest learning curve)

CodeIgniter — https://c…


This content originally appeared on DEV Community and was authored by Javier Jimenez

PHP - Logo

Prerequisites – installation of Homebrew and asdf on Ubuntu

📘 Official Documentation

⭐ Popular Frameworks

(ordered from lowest to highest learning curve)

🛠️ Installation on Ubuntu

sudo apt update
sudo apt install php php-cli php-common php-mbstring php-xml php-curl php-zip

🍺 Installation with Homebrew

brew install php

📦 Standard package manager: Composer

Installation:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
sudo mv composer.phar /usr/local/bin/composer

Verify:

composer --version

🔧 Install different versions with ASDF

Dependencies:

sudo apt update
sudo apt install autoconf bison build-essential libxml2-dev libssl-dev \
libcurl4-openssl-dev pkg-config re2c libsqlite3-dev

Plugin + version:

asdf plugin add php
asdf install php 8.2.12
asdf global php 8.2.12

📄 Example .tool-versions

php 8.2.12

📝▶️ Create and run a PHP file

Create file: touch hola.php

Content of hola.php:

<?php
echo "Hola Mundo PHP\n";

PHP can be run in 2 ways: as a system file, which makes it useful for local scripts—you could replace bash scripts, for example—and in a web server. PHP already comes with an embedded server, but it’s more common to use it with Apache or Nginx.

Run locally:

php hola.php

Embedded server:

php -S localhost:8000

🟦 Basic example in PHP

What it does:

  1. Defines the name of the query parameter.
  2. Gets the query parameter value from the URL.
    • $_GET is used to access query parameters.
    • htmlspecialchars is used for security, to prevent XSS attacks by converting special characters like < and > into HTML entities.
  3. It draws the value received through the query parameter inside the <h1> tag.

📝 Create file: touch index.php

▶️ Content of index.php:

<?php
$paramName = 'username';
$textoRecibido = isset($_GET[$paramName])
    ? htmlspecialchars($_GET[$paramName])
    : "No se ha proporcionado un nombre.";
?>
<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <title>Mensaje Recibido</title>
</head>
<body style="text-align: center">
    <h1>Nombre de usuario en la URL: "<?php echo $textoRecibido; ?>"</h1>
    <p>Prueba a cambiar el valor de `texto` en la barra de direcciones.</p>
    <b><a href="/test.php?texto=cambiado%20en%20url">Click para cambio en url</a></b>
</body>
</html>

run the project / start the server

php -S localhost:8000

👉 visit:
http://localhost:8000/?username=Homero

Installation and configuration on Ubuntu of:


This content originally appeared on DEV Community and was authored by Javier Jimenez


Print Share Comment Cite Upload Translate Updates
APA

Javier Jimenez | Sciencx (2025-11-21T16:17:23+00:00) PHP on Ubuntu: Installation, Setup, and First Steps. Retrieved from https://www.scien.cx/2025/11/21/php-on-ubuntu-installation-setup-and-first-steps/

MLA
" » PHP on Ubuntu: Installation, Setup, and First Steps." Javier Jimenez | Sciencx - Friday November 21, 2025, https://www.scien.cx/2025/11/21/php-on-ubuntu-installation-setup-and-first-steps/
HARVARD
Javier Jimenez | Sciencx Friday November 21, 2025 » PHP on Ubuntu: Installation, Setup, and First Steps., viewed ,<https://www.scien.cx/2025/11/21/php-on-ubuntu-installation-setup-and-first-steps/>
VANCOUVER
Javier Jimenez | Sciencx - » PHP on Ubuntu: Installation, Setup, and First Steps. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/11/21/php-on-ubuntu-installation-setup-and-first-steps/
CHICAGO
" » PHP on Ubuntu: Installation, Setup, and First Steps." Javier Jimenez | Sciencx - Accessed . https://www.scien.cx/2025/11/21/php-on-ubuntu-installation-setup-and-first-steps/
IEEE
" » PHP on Ubuntu: Installation, Setup, and First Steps." Javier Jimenez | Sciencx [Online]. Available: https://www.scien.cx/2025/11/21/php-on-ubuntu-installation-setup-and-first-steps/. [Accessed: ]
rf:citation
» PHP on Ubuntu: Installation, Setup, and First Steps | Javier Jimenez | Sciencx | https://www.scien.cx/2025/11/21/php-on-ubuntu-installation-setup-and-first-steps/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.