{"id":596,"date":"2024-06-08T17:49:25","date_gmt":"2024-06-08T17:49:25","guid":{"rendered":"https:\/\/vpswebhostingindia.in\/blog\/?p=596"},"modified":"2024-06-08T17:49:28","modified_gmt":"2024-06-08T17:49:28","slug":"install-and-uninstall-php-on-ubuntu","status":"publish","type":"post","link":"https:\/\/vpswebhostingindia.in\/blog\/install-and-uninstall-php-on-ubuntu\/","title":{"rendered":"Install and Uninstall PHP on Ubuntu"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">PHP on Ubuntu &#8211; If you don\u2019t know how to install PHP Ubuntu or uninstall it on your Ubuntu system then you`re in the right place. In this blog post, we&#8217;ll guide you how to install and uninstall PHP Ubuntu system.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#php-versions-in-ubuntu\">PHP Versions in Ubuntu<\/a><ul><li><a href=\"#some-additional-points-to-consider\">Some additional points to consider<\/a><\/li><\/ul><\/li><li><a href=\"#how-to-install-php-on-ubuntu\">How to Install PHP on Ubuntu?<\/a><ul><li><a href=\"#prerequisites\">Prerequisites<\/a><\/li><li><a href=\"#install-php-with-apache-on-ubuntu\">Install PHP with Apache on Ubuntu<\/a><ul><li><a href=\"#install-apache-and-php-7-4-8-1\">Install Apache and PHP 7.4, 8.1<\/a><\/li><li><a href=\"#verify-php-installation\">Verify PHP Installation<\/a><\/li><\/ul><\/li><\/ul><\/li><li><a href=\"#how-to-uninstall-php-on-ubuntu\">How to uninstall PHP on Ubuntu?<\/a><\/li><li><a href=\"#uninstall-php-7-4-on-ubuntu\">Uninstall PHP 7.4 on Ubuntu<\/a><\/li><li><a href=\"#uninstall-php-8-1-on-ubuntu\">Uninstall PHP 8.1 on Ubuntu<\/a><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"php-versions-in-ubuntu\">PHP Versions in Ubuntu<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The accessible PHP versions in Ubuntu depend on the <strong><a href=\"https:\/\/ubuntu.com\/\" rel=\"nofollow noopener\" target=\"_blank\">Ubuntu<\/a> version<\/strong> and the sources that are enabled. Here&#8217;s a brief review of the PHP versions often available in different Ubuntu versions:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Ubuntu 20.04 (Focal Fossa): <\/strong>The default version is PHP 7.4.<\/li>\n\n\n\n<li><strong>Ubuntu 22.04 (Jammy Jellyfish):<\/strong> The default version is PHP 8.1.<\/li>\n\n\n\n<li><strong>Ubuntu 23.10 (Kinetic Kudu):<\/strong> The default version is PHP 8.2.<\/li>\n\n\n\n<li><strong>Ubuntu 24.04 (LTS, due for release in April 2024):<\/strong> The expected default version is PHP 8.3.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Note<\/strong><strong>: <\/strong>These are the default versions available by&nbsp;the official Ubuntu repository. You can install additional PHP versions using Personal Package Archives (PPAs) if necessary.&nbsp; For example, if you want an older version, such as PHP 5.6, you can add a PPA that includes it for compatibility reasons.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"some-additional-points-to-consider\">Some additional points to consider<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Security upgrades<\/strong>: Newer PHP versions usually involve higher security features and more frequent safety updates. For additional safety, we recommend using the latest stable version whenever possible for better security.<\/li>\n\n\n\n<li><strong>Application Compatibility: Ensure that the PHP version you select is compatible with your web<\/strong> <strong>applications<\/strong>. If you&#8217;re unsure, consult your application&#8217;s documentation.<\/li>\n\n\n\n<li><strong>Multiple Versions:<\/strong> Ubuntu allows you to have multiple <strong>PHP versions<\/strong> installed simultaneously. This is handy for development, but make sure your web server is configured to use the correct version for each application.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-install-php-on-ubuntu\">How to Install PHP on Ubuntu?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Understanding how to install PHP Ubuntu gives you the ability to create your own web development environment. Then, you`re allowed to test and create dynamic apps and websites locally. This provides more control, flexibility, and affordability than relying entirely on external hosting services. Now, let`s see how to install PHP on Ubuntu with different methods.\u00a0<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"638\" height=\"401\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/06\/image-3.png\" alt=\"\" class=\"wp-image-600\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/06\/image-3.png 638w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/06\/image-3-300x189.png 300w\" sizes=\"auto, (max-width: 638px) 100vw, 638px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"prerequisites\">Prerequisites<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">For installing PHP on Ubuntu, you need 3 main prerequisites:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Ubuntu system<\/strong>: You&#8217;ll need a computer running a recent version of Ubuntu.<\/li>\n\n\n\n<li><strong>Sudo privileges<\/strong>: You&#8217;ll need access to an Ubuntu user account with sudo privileges to install software packages.<\/li>\n\n\n\n<li><strong>Terminal access:<\/strong> You&#8217;ll need to be comfortable using the terminal window to execute commands during the installation process.<\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-php-with-apache-on-ubuntu\">Install PHP with Apache on Ubuntu<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Installing PHP with Apache on Ubuntu is a great way\u00a0to create a local development environment. These tutorials will show you how to install PHP with Apache on your <strong><a href=\"https:\/\/vpswebhostingindia.in\/vps_hosting\/\">Ubuntu server<\/a><\/strong>. You&#8217;ll be able to choose between PHP 7.4 and 8.1.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Update and upgrade:<\/strong> This command updates the package lists and upgrades any existing packages on your system.<\/p>\n\n\n\n<p class=\"has-black-color has-cyan-bluish-gray-background-color has-text-color has-background has-link-color wp-elements-37cc01f71b499368e84ed4325e2f2afa wp-block-paragraph\"><code>sudo apt update &amp;&amp; sudo apt upgrade<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Install PPA prerequisites<\/strong>: This installs the necessary tools to work with Personal Package Archives (PPAs).<\/p>\n\n\n\n<p class=\"has-black-color has-cyan-bluish-gray-background-color has-text-color has-background has-link-color wp-elements-e6877a4feea1a46c4d3f46fd5bf1037c wp-block-paragraph\"><code>sudo apt install software-properties-common<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Add PHP PPA<\/strong>:&nbsp; This step provides various PHP versions.<\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background wp-block-paragraph\"><code>sudo add-apt-repository ppa:ondrej\/php<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Update package lists (Do this again):<\/strong> Run this command again to ensure the package lists include the new PPA repository.<\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background wp-block-paragraph\"><code>sudo a<\/code>pt update<\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"install-apache-and-php-7-4-8-1\"><em>Install Apache and PHP 7.4, 8.1<\/em><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Install Apache and PHP: <\/strong>Choose the version you want to install by replacing `7.4` with `8.1` in the following command:<\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background wp-block-paragraph\"><code>sudo apt install apache2 php&lt;version&gt; libapache2-mod-php&lt;version&gt;<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, to install Apache and PHP 7.4:<\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background wp-block-paragraph\"><code>sudo apt install apache2 php7.4 libapache2-mod-php7.4<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Restart Apache:<\/strong> This command restarts the Apache service to activate the changes.<\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background wp-block-paragraph\"><code>sudo systemctl restart apache2<\/code><\/p>\n\n\n\n<h4 class=\"wp-block-heading\" id=\"verify-php-installation\"><em>Verify PHP Installation<\/em><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Verify PHP Installation:<\/strong> There are two ways to verify the installation:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Firs way: <\/strong>Check version, which displays the installed PHP version.<\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background wp-block-paragraph\"><code>php -v<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Second way<\/strong>: Creating a test page. This way you should create a file named `info.php` in your web server&#8217;s document root (usually `\/var\/www\/html`). You can use a text editor like `nano`:<\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background wp-block-paragraph\"><code>sudo nano \/var\/www\/html\/info.php<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Paste the following code into the file:<\/p>\n\n\n\n<p class=\"has-cyan-bluish-gray-background-color has-background wp-block-paragraph\"><code>&lt;?php<\/code><code>phpinfo();<\/code><code>?&gt;<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">If the version 7.4 is installed successfully, you\u2019ll see something like the following image:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/monovm.com\/uploads\/tinymce\/Suno\/2024\/06\/01\/665af6d556754-image.png?1717237461334\" alt=\"Install PHP with Apache on Ubuntu\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">On the other hand, if you have installed version 8.1, the version will show:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"936\" height=\"104\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/06\/665af6fc70c92-image.png\" alt=\"\" class=\"wp-image-597\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/06\/665af6fc70c92-image.png 936w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/06\/665af6fc70c92-image-300x33.png 300w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/06\/665af6fc70c92-image-768x85.png 768w\" sizes=\"auto, (max-width: 936px) 100vw, 936px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"how-to-uninstall-php-on-ubuntu\">How to uninstall PHP on Ubuntu?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Uninstalling PHP on Ubuntu is\u00a0a useful skill in maintaining a server. It frees up disk space, increases security by deleting unwanted applications, and helps with debugging issues or replacing web frameworks. Even if you don&#8217;t want to uninstall right now, understanding the process allows you to make better\u00a0decisions about your server&#8217;s resource allocation and functioning.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"uninstall-php-7-4-on-ubuntu\">Uninstall PHP 7.4 on Ubuntu<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To uninstall PHP 7.4 on your Ubuntu system, run the following command. It will remove the core PHP package:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>sudo apt remove --purge php7.4<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Now, if you already have installed PHP-FPM, use the command below to uninstall it:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>sudo apt remove --purge php7.4-fpm<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">At last, you need to remove the PHP configuration files. To do that, run the following command:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><code>sudo rm -rf \/etc\/php\/7.4<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"uninstall-php-8-1-on-ubuntu\">Uninstall PHP 8.1 on Ubuntu<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The process of uninstalling PHP 8.1 is the same as uninstalling PHP 7.4. To remove PHP 8.1 from your Ubuntu system:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Remove the core package: <\/strong>sudo apt remove &#8211;purge php8.1<\/li>\n\n\n\n<li><strong>Remove PHP-FPM:<\/strong> sudo apt remove &#8211;purge php8.1-fpm<\/li>\n\n\n\n<li><strong>Delete configuration files: <\/strong>sudo rm -rf \/etc\/php\/8.1<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">(<strong>Note<\/strong><strong>:<\/strong> This step is optional. Using this command, the configuration directory specifically for PHP 8.1 will be removed. If you&#8217;re sure you won&#8217;t need PHP 8.1 again, we recommend using this command.)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PHP on Ubuntu PHP on Ubuntu PHP on Ubuntu<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP on Ubuntu &#8211; If you don\u2019t know how to install PHP Ubuntu or uninstall it on your Ubuntu system then you`re in the right place. In this blog post, we&#8217;ll guide you how to install and uninstall PHP Ubuntu system. PHP Versions in Ubuntu The accessible PHP versions in Ubuntu depend on the Ubuntu [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":599,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"_eb_attr":"","footnotes":""},"categories":[29],"tags":[],"class_list":["post-596","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ubuntu"],"_links":{"self":[{"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/posts\/596","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/comments?post=596"}],"version-history":[{"count":2,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/posts\/596\/revisions"}],"predecessor-version":[{"id":601,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/posts\/596\/revisions\/601"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/media\/599"}],"wp:attachment":[{"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/media?parent=596"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/categories?post=596"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/tags?post=596"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}