Install php 8 extensions ubuntu
A previous version of this tutorial was written by alenaholligan. Show
IntroductionPHP is a popular server scripting language known for creating dynamic and interactive web pages. Getting up and running with your language of choice is the first step in learning to program. This tutorial will guide you through installing PHP 8.1 on Ubuntu and setting up a local programming environment via the command line. You will also install a dependency manager, Composer, and test your installation by running a script. PrerequisitesTo complete this tutorial, you will need a local or virtual machine with Ubuntu 22.04 installed and have administrative access and an internet connection to that machine. You can download this operating system via the Ubuntu releases page. Step 1 — Setting Up PHP 8.1You’ll be completing your installation and setup on the command line, which is a non-graphical way to interact with your computer. That is, instead of clicking on buttons, you’ll be typing in text and receiving feedback from your computer through text as well. The command line, also known as a shell or terminal, can help you modify and automate many of the tasks you do on a computer every day and is an essential tool for software developers. There are many terminal commands to learn that can enable you to do more powerful things. The article An Introduction to the Linux Terminal can get you better oriented with the terminal. On Ubuntu, you can find the Terminal application by clicking on the Ubuntu
icon in the upper-left-hand corner of your screen and typing Note: Ubuntu 22.04 ships with PHP 8.1 in its repositories. This means that if you attempt to install PHP without a specified version, it will use 8.1. If you would like to use a different version of PHP on your Ubuntu 22.04 server, you can use the phpenv project to install and manage different versions. Run the following commands to update your list of available packages, then then install PHP 8.1:
The Check your PHP version information with the following command:
You will receive output like this:
Besides PHP itself, you will likely want to install some additional PHP modules. You can use this command to install additional modules, replacing
You can also install more than one package at a time. Here are a few suggestions of the most common modules you will most likely want to install:
This command will install the following modules:
PHP configurations related to Apache are stored in
You have installed PHP and verified the version you have running. You also installed any required PHP modules and were able to list the modules that you have loaded. You could start using PHP right now, but you will likely want to use various libraries to build PHP applications quickly. Before you test your PHP environment, first set up a dependency manager for your projects. Step 2 — Setting Up Composer for Dependency Management (Optional)Libraries are a collection of code that can help you solve common problems without needing to write everything yourself. Since there are many libraries available, using a dependency manager will help you manage multiple libraries as you become more experienced in writing PHP. Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and will manage installing and updating these packages. Although similar, Composer is not a package manager in the same sense as This idea is not new, and Composer is strongly inspired by Node’s Suppose:
Composer:
To install Composer, download the installer first with the
following
Next, verify that the downloaded installer matches the SHA-384 hash for the latest installer found on the Composer Public Keys / Signatures page. To facilitate the verification step, you can use the following command to programmatically obtain the latest hash from the Composer page and store it in a shell variable:
To verify the obtained value, you can run:
Now execute the following PHP code, as provided in the Composer download page, to verify that the installation script is safe to run:
You’ll see the following output: Output
If the output says To install
You’ll receive output similar to this:
To test your installation, run:
You will receive output like the following:
This verifies that Composer was successfully installed on your system and is available system-wide. Note: If you prefer to have separate Composer executables for each project you host on your server, you can install it locally, on a per-project basis. This method is also useful when your system user doesn’t have permission to install software system-wide. To do this, use the command Step 3 — Using Composer in a PHP ProjectAs a final step, you may optionally initialize your project with First, make a directory and change into it to contain your project files:
Now initialize your project:
Running this command will start the setup wizard. Details that you enter in the wizard can be updated later, so feel free to leave the defaults and just press
Before you confirm the generation, you will see a sample of the The first time you define any dependency, Composer will create a Note:
The Now that you have PHP installed and a way to manage your project dependencies using Composer, you’re ready to test your environment. Step 3 — Testing the PHP EnvironmentTo test that your system is configured correctly for PHP, you can create and run a basic PHP script. Call
this script
This will open a blank file. Put the following text, which is valid PHP code, inside the file: hello.php
Once you’ve added the text, save and close the file. You can do this by holding down the Now you can test to make sure that PHP processes your script correctly. Type
If the PHP is processed properly, you will see only the characters within the quotes:
PHP has successfully processed the script, meaning that your PHP environment is successfully installed and you’re ready to continue your programming journey. ConclusionAt this point, you have a PHP 8.1 programming environment set up on your Ubuntu system and can begin a coding project. Before you start coding, you may want to set up an Integrated Development Environment (IDE). While there are many IDEs to choose from, VS Code is a popular choice as it offers many powerful features such as a graphical interface, syntax highlighting, and debugging. With your local machine ready for software development, you can continue to learn more about coding in PHP by following How To Work With Strings in PHP. How can I run multiple PHP versions in Ubuntu?How to Install Multiple PHP Versions on Ubuntu 22.04. Step 1: System Update. First, log in to Ubuntu 22.04 via console. ... . Step 2: Installing Multiple PHP Versions on Ubuntu 22.04. ... . Step 3: Check Active PHP Version. ... . Step 4: Switch Default PHP Version for CLI. ... . Step 5: Uninstalling PHP Versions.. How install PHP in Ubuntu step by step?Follow the below steps to install PHP on Linux:. Step 1: Open your terminal in Linux. On your Linux computer open the terminal. ... . Step 2: Update your packages. On your terminal update your packages using the following command. ... . Step 3: Upgrade your packages. ... . Step 4: Install PHP.. How do I install the latest PHP version in Ubuntu?Install PHP 7.4 on Ubuntu 18.04 / Ubuntu 16.04. Step 1: Add PHP PPA Repository. We'll add ppa:ondrej/php PPA repository which has the latest build packages of PHP. ... . Step 2: Install PHP 7.4 on Ubuntu 18.04/16.04. Install PHP 7.4 on Ubuntu 18.04/19.04/16.04 using the command: sudo apt -y install php7.4.. |