How to Install and Update php on Ubuntu
PHP is an open-source server-side programming language that may be used to build websites, apps, and customer relationship management systems. It is a popular general-purpose language that can be embedded in HTML.
This compatibility with HTML implies that the PHP language has remained popular among developers since it simplifies HTML programming.
What does “PHP” Stands For?
PHP stands for ‘PHP: Hypertext Preprocessor’, with the original PHP meaning ‘Personal Home Page’. Since its inception in 1994, the acronym has evolved to better reflect the language’s nature.
As of 2022, PHP has been released in eight versions, with version 8.1 currently being the most popular among individuals who use the language on their websites.
What is PHP used for?
PHP programming may be used to generate almost anything that a software developer need. However, it thrives in three specific places.
1. Server-side scripting
PHP’s main strength is in server-side scripting. If you are new to coding and wish to experiment with server-side scripting, PHP is an excellent language to learn. To get started with PHP server-side scripting, you’ll need a PHP parser, web server, and browser.
2. Command-line scripting.
Command-line scripting is appropriate for scripts written with Cron (Linux) or Task Scheduler (Windows). It’s also ideal for simple text processing.
3. Create desktop applications
PHP is arguably not the ideal language for developing desktop programs, but it gives skilled web developers many more possibilities than its competitors.
Of course, PHP has a wide range of capabilities. For example, it excels in gathering form data, encrypting user data, and sending and receiving cookies. One of the most useful advantages of PHP is that it is compatible with all major operating systems, allowing you to code regardless of the technology you are using.
How to Install and Update PHP on Ubuntu
You can install and update almost all of the versions of php by following the steps mentioned below.
Step # 1; Check php Version
In the first step, you need to check the php version you are working on. This can be done by runing the code;
php -v
This will show the php version installed. For example, in the picture below, we have php version 8.3.8 installed.
Step # 2; Add Repository
In case you do not have php installed, you need to add repository and then install php. To add repository, run;
sudo add-apt-repository -y ppa:ondrej/php
Step # 3; Update Advance Package Tool
After adding repository, you need to update advance package tool. To add advance package tool, you need to run the code;
sudo apt update
Step # 4; Install php
After updating you can install almost any version of php through your advance package tool. Incase you want to install php version 9, code;
sudo apt install php8.0
How To Switch Between Version?
If you have more than one versions installed and want to switch between them, you can do that easily. Just run this code;
sudo update-alternatives --config php
This command will show the list of available versions. The (*) will show the version which is enabled. To switch between the versions, type the selection number you want to enable. If you want to enable the selection 2, type 2 at the cursor and press enter. It will update the php version.
How to Engage Module in Apache?
To enable the modules of a specific version of php, you need to first disable the already enable modules in apache.
To disaable the module of php version 8.3, code;
sudo a2dismod php8.3
To enable the module of apache for php version 8, code;
sudo a2enmod php8.0
To activate the new configuration, you need to run the code;
sudo systemctl restart apache2
How to Install php Extension
If you want to install any extension, you need to use APT. For example, if you want to install mbstring extension, run this code;
sudo apt install php8.0-mbstring
We hope you found this article helpful, make sure to comment down below or contact us if you face any issues. Thanks!