How to Install PHP 8 on Slackware Linux
This article is a part of my Slackware article series. Previous article:
How Package Management Works in Slackware
Like another Linux distributions out there, Slackware has its own package manager, namely
removepkg for installing, upgrading and removing software packages.
makepkg can be used to create packages. For more details about
slackpkg you can check here and here.
Basically, here's how to install a package in Slackware:
Update Package Repository
In Ubuntu or Debian based distribution, before we install anything we must update our package repository first using apt or apt-get command. In Slackware, we'll use slackpkg command below:
$ slackpkg update
Search the Package
First, we need to figure whether the software we'd like to install is available. For example, if we're about to install PHP, we can search it using this slackpkg command:
$ slackpkg search php
It will respond with something like this:
Looking for php in package list. Please wait... DONE
The list below shows all packages with name matching "php".
[ Status ] [ Repository ] [ Package ]
uninstalled slackware64 kdev-php-5.6.1-x86_64-1
uninstalled slackware64 php-7.4.14-x86_64-1
uninstalled(masked) pasture php-5.6.40-x86_64-1
You can search specific files using "slackpkg file-search file".
From the result, we can figure out that PHP package is available and its version is 7.4.14. This is interesting because by the time of this writing (January 17, 2021), Slackware already has the latest PHP version. PHP 7.4.14 itself was released at January 7, 2021.
To continue with PHP 7.4.14 installation, we'll just need to enter this command:
$ slackpkg install php-7.4
It will respond with a screen like this:
In this screen dialog we can navigate using arrows and select item using "Space". Just press "Enter" on your keyboard to continue with PHP 7.4 installation.
Slackpkg will download the package file and the installation process will run automatically.
Once you have your shell back, the installation process is done.
To confirm whether we've successfully installed PHP 7.4.14 into our system, we can check it using this command:
$ php -v
It should respond with something like this:
PHP 7.4.14 (cli) (built: Jan 5 2021 21:30:31) ( ZTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
Congratulations, we've successfully installed PHP 7.4.14 into our Slackware Current.
To remove package, we'll use this command:
$ slackpkg remove php
slackpkg installation screen, we can navigate using arrows and using "Space" to select/de-select items. Just press "Enter" to continue with package removal.
Create Package using SlackBuild
Next, we'll try to install package which hasn't already available in any Slackware repository, but we already have the source code.
Let's use PHP 8 for example. On our previous slackpkg search command, we figured out that PHP 8 hasn't available just yet, but we can download the source code on PHP's download page.
Luckily, we're able to create our own package by using SlackBuild script. I've made a PHP 8 SlackBuild Script github repository for this purpose. You can also use this repository as a template if you like.
To use this repository, I've included a README too. Basically here's what you have to do:
- Clone the repository
$ git clone https://github.com/r00t4bl3/php8-SlackBuild.git
- Enter working directory
- Run the script
When the script finished, it should output line like below:
Slackware package /tmp/php-8.0.1-x86_64-1.txz created.
Next, we'll just run this command to install our newly created package.
$ installpkg /tmp/php-8.0.1-x86_64-1.txz
System will respond with:
Verifying package php-8.0.1-x86_64-1.txz.
Installing package php-8.0.1-x86_64-1.txz:
# php (HTML-embedded scripting language)
# PHP is an HTML-embedded scripting language. It shares syntax
# characteristics with C, Java, and Perl. The primary objective behind
# this language is to make a fast and easy-to-use scripting language
# for dynamic web sites.
# More information can be found online at http://www.php.net/
Executing install script for php-8.0.1-x86_64-1.txz.
Package php-8.0.1-x86_64-1.txz installed.
To verify our PHP 8.0.1 installation, we'll use this command:
$ php -v
PHP 8.0.1 (cli) (built: Jan 17 2021 13:11:13) ( ZTS )
Copyright (c) The PHP Group
Zend Engine v4.0.1, Copyright (c) Zend Technologies
Congratulations, we've successfully created PHP 8.0.1 package in our Slackware and install it.
I hope that you now know how package management works in Slackware. If you run into any issues or have any feedback feel free to drop a comment below.