{"id":2531,"date":"2024-11-01T10:26:12","date_gmt":"2024-11-01T04:56:12","guid":{"rendered":"https:\/\/www.hostbet.in\/blog\/?p=2531"},"modified":"2025-07-26T11:53:49","modified_gmt":"2025-07-26T06:23:49","slug":"install-php-on-ubuntu","status":"publish","type":"post","link":"https:\/\/www.hostbet.in\/blog\/install-php-on-ubuntu\/","title":{"rendered":"How to Install PHP on Ubuntu 24: A Quick Tutorial 2025"},"content":{"rendered":"\n<p>Installing PHP on Ubuntu is essential for web developers, especially beginners working with dynamic web applications. PHP is the most popular language and is widely used for web development. Here\u2019s an in-depth guide on how to install PHP on Ubuntu.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_71 counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.hostbet.in\/blog\/install-php-on-ubuntu\/#Prerequisites_for_Installing_the_PHP_on_Ubuntu\" title=\"Prerequisites for Installing the PHP on Ubuntu.\">Prerequisites for Installing the PHP on Ubuntu.<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.hostbet.in\/blog\/install-php-on-ubuntu\/#Update_Package_Lists\" title=\"Update Package Lists:\">Update Package Lists:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.hostbet.in\/blog\/install-php-on-ubuntu\/#Verify_PHP_Installation\" title=\"Verify PHP Installation\">Verify PHP Installation<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.hostbet.in\/blog\/install-php-on-ubuntu\/#Configure_Apache_to_Use_PHP\" title=\"Configure Apache to Use PHP\">Configure Apache to Use PHP<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.hostbet.in\/blog\/install-php-on-ubuntu\/#Testing_PHP\" title=\"Testing PHP\">Testing PHP<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.hostbet.in\/blog\/install-php-on-ubuntu\/#Install_Additional_Modules\" title=\"Install Additional Modules\">Install Additional Modules<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.hostbet.in\/blog\/install-php-on-ubuntu\/#Final_Thought_on_Install_PHP_on_Ubuntu\" title=\"Final Thought on Install PHP on Ubuntu\">Final Thought on Install PHP on Ubuntu<\/a><\/li><\/ul><\/nav><\/div>\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Prerequisites_for_Installing_the_PHP_on_Ubuntu\"><\/span>Prerequisites for Installing the PHP on Ubuntu.<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>VPS: Get Powerful VPS Hosting: Visit HostBet.in<\/li>\n\n\n\n<li>Access to your VPS: You should have the IP address and password provided by HostBet. (Once you purchase a VPS hosting plan from any VPS hosting provider, you\u2019ll typically receive an email with the IP address, password, and other details:)<\/li>\n\n\n\n<li>SSH client: A tool like PuTTY or Terminal (on macOS\/Linux) to connect to your VPS. How to <a href=\"https:\/\/www.hostbet.in\/blog\/install-apache-server-on-ubuntu\/#Connect_to_Your_VPS_Hosting\">Connect to Your VPS Hosting via SSH\/PuTTY&nbsp;<\/a><\/li>\n<\/ul>\n\n\n\n<p>Remember that before installing any components, such as Linux, Apache, MySQL, or PHP, always start by updating your package index to ensure you are getting the latest version of PHP.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Update_Package_Lists\"><\/span><strong>Update Package Lists:<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>To update packages, you need to ensure you have the latest packages. If not, then you run the following command to update:&nbsp;<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-fb5217f8d2414a0444c1fdb731834fee\" style=\"border-style:none;border-width:0px\"><code><strong>sudo apt update<\/strong><\/code><\/pre>\n\n\n\n<p>You can install PHP on Ubuntu using either of these commands, depending on your specific need:<\/p>\n\n\n\n<p><strong>Option:- 1<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-8655935fd8d6b9da4641d3e45003c94e\"><code><strong>sudo apt install PHP<\/strong><\/code><\/pre>\n\n\n\n<p>This command installs the PHP interpreter itself because it is essential for running PHP scripts on your system.<\/p>\n\n\n\n<p><strong>Option:- 2<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-5-color has-black-background-color has-text-color has-background has-link-color wp-elements-82e755488240ce20e83c4f18cdfb843b\"><code><strong>sudo apt install php libapache2-mod-php<\/strong><\/code><\/pre>\n\n\n\n<p>Using this command, your system will run a PHP script on a web server using Apache, ensuring smooth website functionality.<\/p>\n\n\n\n<p><strong>Note:<\/strong> The second command is generally preferred if you plan to use PHP for web development with Apache.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Verify_PHP_Installation\"><\/span><strong>Verify PHP Installation<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Once you complete installation, check the <a href=\"https:\/\/www.php.net\/\" target=\"_blank\" rel=\"noopener\">PHP<\/a> version to confirm it\u2019s installed correctly.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-e6762cefd1d1b5dd35399a0f7a33a280\"><code><strong>Command: php -v<\/strong><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Configure_Apache_to_Use_PHP\"><\/span><strong>Configure Apache to Use PHP<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Once you complete verifications, to ensure Apache serves PHP files, you need to configure it to prioritize PHP files over others. Open the dir.conf file with a text editor.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-31c0c7b656eafa00d93ed2e979490d82\"><code><strong>sudo nano \/etc\/apache2\/mods-enabled\/dir.conf<\/strong><\/code><\/pre>\n\n\n\n<p>Modify the DirectoryIndex directive so index.php appears before index.html.<\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-9268d5b221674ee077f3530a32f80363\"><code><strong>&lt;IfModule mod_dir.c&gt;\n    DirectoryIndex index.php index.html\n&lt;\/IfModule&gt;<\/strong><\/code><\/pre>\n\n\n\n<p>Next, save the file and exit the text editor. And restart Apache to apply the changes. Follow the below command to restart.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Testing_PHP\"><\/span><strong>Testing PHP<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>You need to create a simple PHP file named info.php in your web server&#8217;s document root (usually \/var\/www\/html):<\/p>\n\n\n\n<p><em><strong>Add the following PHP code to the file:<\/strong><\/em><\/p>\n\n\n\n<pre class=\"wp-block-code has-white-color has-black-background-color has-text-color has-background has-link-color wp-elements-e8403b2af8077ef981734c5feb6759af\"><code><strong>&lt;?php\nphpinfo();\n?&gt;<\/strong><\/code><\/pre>\n\n\n\n<p>Once you type code, save and exit the text editor. Now open your web browser and navigate to http:\/\/your_server_ip\/info.php.&nbsp;<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Install_Additional_Modules\"><\/span>Install Additional Modules<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p>Depending on your specific requirements, you might need additional extensions; you can easily install them using the following command format:<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-4-color has-black-background-color has-text-color has-background has-link-color wp-elements-6fc00f9ff7fb4a822ceb521f89ab9ee2\"><code><strong>sudo apt install php-&lt;module-name&gt;<\/strong><\/code><\/pre>\n\n\n\n<p>For example, we will install the MySQL extension, which allows PHP to interact with MySQL databases.<\/p>\n\n\n\n<pre class=\"wp-block-code has-ast-global-color-4-color has-black-background-color has-text-color has-background has-link-color wp-elements-e8996b647247d36472776ff2d3c5eaf3\"><code><strong>sudo apt install php-mysql<\/strong><\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Final_Thought_on_Install_PHP_on_Ubuntu\"><\/span>Final Thought on Install PHP on Ubuntu<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Congratulations! You\u2019ve now successfully installed PHP on your <a href=\"https:\/\/iotamine.com\/germany-vps\" target=\"_blank\" rel=\"noopener\">Ubuntu VPS<\/a>. This comprehensive setup guarantees that you&#8217;re ready to develop robust web apps. You can now start creating dynamic web applications using PHP.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Installing PHP on Ubuntu is essential for web developers, especially beginners working with dynamic web applications. PHP is the most popular language and is widely used for web development. Here\u2019s an in-depth guide on how to install PHP on Ubuntu. Prerequisites for Installing the PHP on Ubuntu. Remember that before installing any components, such as [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":2552,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[402],"tags":[410,411,409],"class_list":["post-2531","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-lamp-stack","tag-how-to-install-php-on-ubuntu","tag-install-php","tag-install-php-on-ubuntu"],"_links":{"self":[{"href":"https:\/\/www.hostbet.in\/blog\/wp-json\/wp\/v2\/posts\/2531"}],"collection":[{"href":"https:\/\/www.hostbet.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostbet.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostbet.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostbet.in\/blog\/wp-json\/wp\/v2\/comments?post=2531"}],"version-history":[{"count":22,"href":"https:\/\/www.hostbet.in\/blog\/wp-json\/wp\/v2\/posts\/2531\/revisions"}],"predecessor-version":[{"id":2681,"href":"https:\/\/www.hostbet.in\/blog\/wp-json\/wp\/v2\/posts\/2531\/revisions\/2681"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostbet.in\/blog\/wp-json\/wp\/v2\/media\/2552"}],"wp:attachment":[{"href":"https:\/\/www.hostbet.in\/blog\/wp-json\/wp\/v2\/media?parent=2531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostbet.in\/blog\/wp-json\/wp\/v2\/categories?post=2531"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostbet.in\/blog\/wp-json\/wp\/v2\/tags?post=2531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}