DEV Community

Cover image for How to install PHP 8 from source on Debian
Given Ncube
Given Ncube

Posted on • Originally published at flixtechs.co.zw

3 2

How to install PHP 8 from source on Debian

I've seen a lot of tutorials on installing PHP 8 on Ubuntu, Debian, but none of them seem to work anymore maybe they do work on Ubuntu itself but other Debian distros I've tried didn't work. So I ended up compiling it myself and that's what I'm going to show you in this guide.

Setting up the environment

Make sure you have gcc installed which comes pre-installed in almost any Linux distro out there. The next thing is to install build tools.

sudo apt-get install build-essential autoconf re2c bison
Enter fullscreen mode Exit fullscreen mode

This may not be everything we are going to need but if you find an error that says package 'package-name' not found just install it by running apt-get install lib<package-name>-dev. If you're unsure of the package name type lib followed by incomplete package name, then hit tab to autocomplete.

Getting PHP

Go to php.net and download the latest release. Once downloaded extract by

tar -xzf php-8.0.3.tar.gz
Enter fullscreen mode Exit fullscreen mode
cd php-8.0.3
Enter fullscreen mode Exit fullscreen mode

Configure

The next step is to configure, tell gcc which extension we want to include

./configure --with-openssl\
--enable-mbstring\
--with-curl\
--enable-calendar\
--enable-bcmath\
--enable-exif\
--enable-gd\
--enable-ftp\
--enable-pcntl\
--enable-sockets\
--with-sodium\
--with-zip\
--with-pear\
--enable-mysqlnd\
--with-pdo-mysql\
--with-pgsql=/usr/bin/pg_config\
--with-pdo-pgsql=/usr/bin/pg_config\
--with-config-file-scan-dir=/etc/php/8.0\
--with-config-file-path=/etc/php/8.0/cli/php.ini\
--with-zlib
Enter fullscreen mode Exit fullscreen mode

If all goes well you should see this

+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.
Enter fullscreen mode Exit fullscreen mode

If not, it's probably because you have a library missing which you can install by running apt-get install lib<package-name>-dev

Building

Sometimes you may want to check how many cores your CPU has

nproc
Enter fullscreen mode Exit fullscreen mode

And then you can use that number to make builds faster with the -j flag.

make -j2
Enter fullscreen mode Exit fullscreen mode

This will use 2 cores to build. Be patient and after you see build complete on the console install the binaries in --prefix destination (provided during configuration)

sudo make install
Enter fullscreen mode Exit fullscreen mode

After it's done confirm by

php -v
PHP 8.0.3 (cli) (built: Mar  24 2021 15:37:13) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.3, Copyright (c) Zend Technologies
Enter fullscreen mode Exit fullscreen mode

Almost done, now depending on the environment copy the php.ini-production or php.ini-development to the --with-config-file-path you provided during configuration.

Now you have the latest version of PHP. I'll write another article on how to upgrade but in the meantime Happy Coding!

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

The Most Contextual AI Development Assistant

Pieces.app image

Our centralized storage agent works on-device, unifying various developer tools to proactively capture and enrich useful materials, streamline collaboration, and solve complex problems through a contextual understanding of your unique workflow.

👥 Ideal for solo developers, teams, and cross-company projects

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay