
Download the .tar.gz or tar.bz2 file for the version of PHP that you want to compile (install) from source from https://www.php.net/downloads.php. For example, let's say I download php-8.2.8.tar.gz. Place the TAR file on your Linux server. Create a temporary directory.
mkdir /tmp/php
Use the tar extract command to extract the TAR file to the directory you just created.
tar -zxpf php-8.2.8.tar.gz --directory /tmp/php
Move into the extracted directory.
cd /tmp/php/php-8.2.8/
The README.md file suggests installing the following packages on a Debian distribution (Ubuntu, Mint) using apt install.
sudo apt install -y pkg-config build-essential autoconf bison re2c libxml2-dev libsqlite3-dev
Or these packages on a Red Hat distribution (CentOS, Fedora, Red Hat) using dnf install or yum install.
sudo dnf install re2c bison autoconf make libtool ccache libxml2-devel sqlite-devel
It's probably a good idea to create a diretory that will contain the files created by the make install command, so that you can easily remove the directory without messing with a shared directory such as /usr/local/bin.
mkdir /tmp/makeinstall
Run the ./configure command. The --disable-fileinfo option is not required and only used to prevent errors from being returned on a system with limit memory, such as an Amazon Web Services micro instance.
./configure --prefix=/tmp/makeinstall --disable-fileinfo
Optionally, you can configure with additional features, such as OpenSSL and curl. You'll probably need to ensure you have the devel packages installed.
sudo dnf install openssl-devel libcurl-devel
And then configure with the additional --with-<package> flags.
./configure --prefix=/tmp/makeinstall --disable-fileinfo --with-openssl --with-curl --with-mysqli
If configure was successful, the following should be displayed at the end of the output.
Thank you for using PHP.
Run make.
sudo make
If make was successful, something like this should be displayed.
Build complete.
Don't forget to run 'make test'.
Run make install.
sudo make install
If make install was successful, something like this should be displayed.
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20220829/
Installing PHP CLI binary: /usr/local/bin/
Installing PHP CLI man page: /usr/local/php/man/man1/
Installing phpdbg binary: /usr/local/bin/
Installing phpdbg man page: /usr/local/php/man/man1/
Installing PHP CGI binary: /usr/local/bin/
Installing PHP CGI man page: /usr/local/php/man/man1/
Installing build environment: /usr/local/lib/php/build/
Installing header files: /usr/local/include/php/
Installing helper programs: /usr/local/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php/man/man1/
page: phpize.1
page: php-config.1
Installing PDO headers: /usr/local/include/php/ext/pdo/
The which command should return the absolute path to the php CLI.
]$ which php
/usr/local/bin/php
And the php --version command show show the version of PHP you installed.
]$ php --version
PHP 8.2.8 (cli) (built: Jul 21 2023 10:57:04) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.8, Copyright (c) Zend Technologies
Did you find this article helpful?
If so, consider buying me a coffee over at