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.
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
<code>Requirements:
PHP 7
libui (use current master)
Windows/MacOSX/Linux (GTK-3)
</code>Linux installation steps
<code>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/
</code>Installing the UI extension
<code>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
</code>Enable the extension
<code>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
</code>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:
<code>php snake.php</code>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.
php中文网 Courses
php中文网's platform for the latest courses and technical articles, helping PHP learners advance quickly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.