Installing the PHP UI Extension and Running a Snake Game Example

This tutorial explains how to install the PHP UI (ui) extension on Linux, configure it on Windows, and use it to run a simple Snake game written in PHP, providing step‑by‑step commands, required libraries, and testing instructions.

php Courses
php Courses
php Courses
Installing the PHP UI Extension and Running a Snake Game Example

The article introduces the PHP UI (ui) extension, a graphical user interface library for PHP 7, and demonstrates its use by running a classic Snake game.

Installation requirements

Requirements:
    PHP 7
    libui (use current master)
    Windows/MacOSX/Linux (GTK-3)

Linux installation steps

sudo apt install re2c

git clone https://github.com/andlabs/libui.git
cd libui
sudo cp *.h /usr/local/include/
cmake .
cd out
sudo cp * /usr/lib/

Installing the UI extension

Method one: use pecl
    sudo pecl install channel://pecl.php.net/ui-2.0.0

Method two: build from source
    git clone https://github.com/krakjoe/ui.git
    cd ui
    phpize
    make
    sudo make install

Enable the extension

sudo echo 'extension=ui.so' > /etc/php/7.0/mods-available/ui.ini
sudo ln -s /etc/php/7.0/mods-available/ui.ini 20-ui.ini

Verify the installation with php -m and ensure ui appears in the module list.

Windows setup

Download the appropriate php_ui.dll for PHP 7 (nts, 64‑bit) and place it in the ext directory, then add extension=php_ui.dll to php.ini. Copy pthreadVC2.dll and libui.dll to the same folder as php.exe.

Testing the Snake game

After installing, navigate to the ui extension’s examples folder and run: php snake.php The script launches a graphical Snake game. Another example, starfield.php, demonstrates a particle effect.

These steps provide a complete guide to setting up the PHP UI extension and creating simple GUI applications with PHP.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

GUISnake GameUI extension
php Courses
Written by

php Courses

php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.