{"id":20734,"date":"2023-08-31T18:13:34","date_gmt":"2023-08-31T18:13:34","guid":{"rendered":"https:\/\/linuxways.net\/?p=20734"},"modified":"2023-08-31T18:13:34","modified_gmt":"2023-08-31T18:13:34","slug":"how-to-install-php-on-debian-12","status":"publish","type":"post","link":"https:\/\/linuxways.net\/de\/debian\/how-to-install-php-on-debian-12\/","title":{"rendered":"How to Install PHP on Debian 12?"},"content":{"rendered":"<p><strong>PHP<\/strong> is a popular, general-purpose, cross-platform script language suited for web development. Web developers use PHP to interact with databases to create content. It is implemented on the server side embedded in HTML. In this article, the installation steps of PHP on the Debian 12 (Bookworm) system are discussed.<\/p>\n<h2>How to Install PHP on Debian 12?<\/h2>\n<p>To install PHP on Debian 12, users can utilize the APT package manager. For this, follow the step-by-step procedure below:<\/p>\n<h3>Step 1: Launch Terminal<\/h3>\n<p>The first step is to launch Terminal. It can be launched either by using the shortcut Ctrl+Alt+T or by using the Application launcher.<\/p>\n<p>All applications, system components, and files installed on the system are placed in the Application Launcher. Terminal can be launched by application launcher by pressing the Activities button in the left corner of the screen, then by typing \u201cTerminal\u201d in the search bar and by selecting the Terminal icon:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"2048\" height=\"441\" class=\"wp-image-20737\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-1.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-1.png 2048w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-1-300x65.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-1-1024x221.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-1-768x165.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-1-1536x331.png 1536w\" sizes=\"auto, (max-width: 2048px) 100vw, 2048px\" \/><\/p>\n<p>The following screenshot shows how the Terminal Application looks like on Debian:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1576\" height=\"698\" class=\"wp-image-20738\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-2.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-2.png 1576w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-2-300x133.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-2-1024x454.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-2-768x340.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-2-1536x680.png 1536w\" sizes=\"auto, (max-width: 1576px) 100vw, 1576px\" \/><\/p>\n<h3>Step 2: Update APT Sources\/Packages<\/h3>\n<p>It is highly recommended to make sure that all existing packages are up to date before installing any software. This is to avoid dependency issues. We can do that by running the following command as root or user with sudo privileges:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> apt update<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1704\" height=\"558\" class=\"wp-image-20739\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-3.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-3.png 1704w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-3-300x98.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-3-1024x335.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-3-768x251.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-3-1536x503.png 1536w\" sizes=\"auto, (max-width: 1704px) 100vw, 1704px\" \/><\/p>\n<h3>Step 3: Install PHP<\/h3>\n<p>We will install PHP by using <strong>apt<\/strong>, i.e., the default package manager of Debian, by running the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> apt <span class=\"kw2\">install<\/span> php<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1936\" height=\"746\" class=\"wp-image-20740\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-4.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-4.png 1936w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-4-300x116.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-4-1024x395.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-4-768x296.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-4-1536x592.png 1536w\" sizes=\"auto, (max-width: 1936px) 100vw, 1936px\" \/><\/p>\n<p>The installation process will start. Press \u201cY\u201d at the prompt to continue with the installation process. The installation will be completed once the above command is executed.<\/p>\n<h3>Step 4: Verify Installation<\/h3>\n<p>We can verify if the PHP is installed correctly by checking its version with the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span>php <span class=\"re5\">-v<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1548\" height=\"310\" class=\"wp-image-20741\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-5.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-5.png 1548w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-5-300x60.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-5-1024x205.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-5-768x154.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-5-1536x308.png 1536w\" sizes=\"auto, (max-width: 1548px) 100vw, 1548px\" \/><\/p>\n<h3>Step 5: Install PHP Extensions<\/h3>\n<p>We can install PHP extensions\/modules at any time whenever we require one by replacing the extension\/module name instead of php-extension. The general syntax of installing PHP extension is as follows:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> apt <span class=\"kw2\">install<\/span> php-extension1 php-extension2 php-extension3<\/div><\/div>\n<p>PHP extensions can be installed by running the following command:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> apt <span class=\"kw2\">install<\/span> php php-curl php-fpm php-bcmath php-gd php-soap php-zip php-curl php-mbstring php-mysqlnd php-gd php-xml php-intl php-zip<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1948\" height=\"750\" class=\"wp-image-20742\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-6.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-6.png 1948w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-6-300x116.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-6-1024x394.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-6-768x296.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-6-1536x591.png 1536w\" sizes=\"auto, (max-width: 1948px) 100vw, 1948px\" \/><\/p>\n<p>The above command will install PHP extensions: php-curl, php-fpm, php-bcmath, php-gd, php-soap, php-zip, php-curl, php-mbstring, php-mysqlnd, php-gd, php-xml, php-intl, and php-zip.<\/p>\n<p>Additionally, we can run the following command to check all the PHP modules:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span>php <span class=\"re5\">-m<\/span><\/div><\/div>\n<h1><a id=\"post-20734-_eedo8afwd9wy\"><\/a><img loading=\"lazy\" decoding=\"async\" width=\"1008\" height=\"700\" class=\"wp-image-20743\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-7.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-7.png 1008w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-7-300x208.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-7-768x533.png 768w\" sizes=\"auto, (max-width: 1008px) 100vw, 1008px\" \/><\/h1>\n<h2>How to Uninstall PHP on Debian 12?<\/h2>\n<p>If in case, we need to completely uninstall PHP (configuration and\/or data files of PHP) from our system then we can run the following command with the PHP version (We can check the version as described in Step 4):<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> apt purge PHP8.2<\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1730\" height=\"742\" class=\"wp-image-20744\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-8.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-8.png 1730w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-8-300x129.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-8-1024x439.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-8-768x329.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-8-1536x659.png 1536w\" sizes=\"auto, (max-width: 1730px) 100vw, 1730px\" \/><\/p>\n<p>Press \u201cY\u201d at the prompt to continue with the uninstallation process.<\/p>\n<p>We can then continue with the following command to remove the dependencies:<\/p>\n<div class=\"codecolorer-container bash blackboard\" style=\"width:100%;\"><div class=\"bash codecolorer\"><span class=\"co4\">$ <\/span><span class=\"kw2\">sudo<\/span> <span class=\"kw2\">apt-get autoremove<\/span><\/div><\/div>\n<p><img loading=\"lazy\" decoding=\"async\" width=\"1688\" height=\"700\" class=\"wp-image-20745\" src=\"http:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-9.png\" srcset=\"https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-9.png 1688w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-9-300x124.png 300w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-9-1024x425.png 1024w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-9-768x318.png 768w, https:\/\/linuxways.net\/wp-content\/uploads\/2023\/08\/word-image-20734-9-1536x637.png 1536w\" sizes=\"auto, (max-width: 1688px) 100vw, 1688px\" \/><\/p>\n<p>Press \u201cY\u201d at the prompt to continue with the uninstallation process. After executing the <strong>purge<\/strong> and <strong>autoremove <\/strong>commands, PHP will be completely uninstalled.<\/p>\n<h2>Bonus Tip: How to Use Previous Versions of PHP?<\/h2>\n<p>If we want to use previous versions of PHP e.g., PHP 7.x\/8.0\/8.1 along with the latest version, i.e., PHP 8.2, we need to install Sury Apt (<a href=\"https:\/\/deb.sury.org\/\">https:\/\/deb.sury.org\/<\/a>), which is a third party repository that provides PHP packages. By installing Sury Apt, we can have multiple versions of PHP (added from Surry Apt) installed in our system and we can switch between these versions.<\/p>\n<h2>Conclusion<\/h2>\n<p>To install PHP on Debian 12, users can utilize the APT package manager. Additionally, this article also discussed the extensions of PHP. PHP is a widely used language for web development. This article discussed how to install the latest version of PHP., (i.e., PHP 8.2) on Debian 12 (Bookworm) systems.<\/p>\n<p>&nbsp;<\/p>","protected":false},"excerpt":{"rendered":"<p>To install PHP on Debian 12, users can utilize the APT package manager. Additionally, this article also installed the PHP extensions.<\/p>","protected":false},"author":110,"featured_media":20747,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-20734","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-debian"],"_links":{"self":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/20734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/users\/110"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/comments?post=20734"}],"version-history":[{"count":0,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/posts\/20734\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media\/20747"}],"wp:attachment":[{"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/media?parent=20734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/categories?post=20734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxways.net\/de\/wp-json\/wp\/v2\/tags?post=20734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}