PHP 8 - Installation and Configuration on Ubuntu 20.04 and Windows

Ronaldo B.July 27, 20223 min read

In this article

At the beginning of this month, Microsoft made an announcement that left many PHP developers concerned. The company announced that it will not support PHP version 8, scheduled to be released on November 26 of this year. Now, in order to use the language, we will need to use a Linux Operating System.

With this announcement, a question began to spread on the Web: “Is it the end of PHP on Windows?” And the answer is “Yes… and no ?”. In fact, Microsoft will no longer provide PHP binaries for us to install it. However, we can still install this language on Windows via WSL (Windows Subsystem for Linux).

In this article, we will show a step on how to perform this installation, specifically version Alpha 3. The best part is that it can help you whether you're using a Linux or Windows computer.

If you are using Windows, you can check how to install WSL 2 on our Blog or on our YouTube channel.

Installing PHP 8

The first thing we will do is update the package indexes with apt-get update:

sudo apt-get update

After performing this update, let's download PHP. We will download it to the root folder of Ubuntu:

cd /

We will use wget for the download, with this command:

sudo wget -c https://downloads.php.net/~carusogabriel/php-8.0.0alpha3.tar.xz -o -

After downloading, we will extract the PHP folder to then proceed with the installation. We will extract the folder and then rename it to a more pleasant name. For this, we will use the following command:

sudo tar -Jxxvf php-8.0.0alpha3.tar.xz && sudo mv php-8.0.0alpha3 php8-alpha3

Now, when listing the directories, we will see the PHP 8 folder:

Directory items in Ubuntu, including the PHP 8 folder

Let's access the php8-alpha3 folder. Before configuring PHP, we need to install some necessary modules for PHP to function well.

We will install all at once with the following command:

sudo apt-get install -y build-essential pkg-config libxml2-dev sqlite3 libsqlite3-dev

With this installation complete, we can configure PHP with the command sudo ./configure.

After the configuration, we will see the following success message:

Success message for PHP configuration

Finally, let's actually install PHP on Ubuntu with the command below:

sudo make && sudo make install

At the end of this process, we will execute the command php --version. The following information will be returned:

Version of PHP Alpha 3

Awesome! PHP version Alpha 3 was installed successfully!

Creating first code with PHP 8

To create our first example with PHP 8, we will access the html directory, with the command cd /var/www/html/.

Let's open Visual Studio Code. To do this, just execute code . and our text editor will open. The incredible part is that if we are using WSL, VS Code will open in Windows!

Visual Studio Code opened in Windows from a command in Ubuntu

Impressive, isn’t it?

Let's create a file called info.php and set the following content for it:

<?php

phpinfo();

Note that we will only display the PHP information that is installed on our machine. It is likely that Visual Studio Code will show an alert message asking to install the Remote - WSL extension. Just click on Install and then add it to VS Code.

Option to install the WSL extension in VS Code

WSL extension in VS Code

In order for us to see our PHP code being executed in the browser, a Web Server is necessary. Some options are Nginx or Apache, and we can discuss them in another article.

However, in this article, we will use PHP's built-in Web Server, available since version 5.4 of the language. We will execute the following command in the html directory:

sudo php -S localhost:80

Now, when accessing the address http://localhost/info.php in Chrome, we will see the following result:

PHP information displayed in Chrome

Excellent! PHP is running correctly and its information is already being displayed to us. With that, we are ready to conduct our tests with PHP 8 ?.

If you liked this content, don't forget to share it with others, it really helps our work. Thank you for reading this far, and see you in the next article.

Keep learning with Hcode

Sign up for the course platform and follow the next blog guides.