{"id":130734,"date":"2025-07-01T09:55:23","date_gmt":"2025-07-01T09:55:23","guid":{"rendered":"\/tutorials\/?p=130734"},"modified":"2026-03-09T19:16:22","modified_gmt":"2026-03-09T19:16:22","slug":"how-to-install-install-php-ubuntu","status":"publish","type":"post","link":"\/ng\/tutorials\/how-to-install-install-php-ubuntu","title":{"rendered":"How to Install PHP on Ubuntu?"},"content":{"rendered":"<?xml encoding=\"utf-8\" ?><p>Installing <strong>PHP<\/strong> on Ubuntu is a crucial first step in setting up a dynamic web environment. Whether you&rsquo;re working with a content management system like WordPress, a custom web application, or a PHP-based framework like Laravel, PHP is the backbone of modern web development.<\/p><p>In this guide, we will walk you through the entire process of installing PHP on Ubuntu, configuring it with either Apache or Nginx, and testing your setup. By the end of this article, you&rsquo;ll have a fully functional PHP environment that is ready to host your website or application.<\/p><p>We&rsquo;ll also cover essential PHP extensions and provide tips for troubleshooting common issues. Follow these steps to ensure your PHP installation is smooth and effective.<\/p><p>\n<\/p><h2 id=\"h-prerequisites\" class=\"wp-block-heading\">Prerequisites<\/h2><p>Before you start, make sure you have the following:<\/p><ul class=\"wp-block-list\">\r\n<li><strong>An Ubuntu server<\/strong> &ndash; LTS version 20.04 or later. Hostinger offers <a href=\"\/ng\/vps\/ubuntu-hosting\">Ubuntu VPS hosting<\/a> that is quick and easy to set up.<\/li>\r\n\r\n\r\n\r\n<li><strong>Basic command line knowledge<\/strong> &ndash; you don&rsquo;t need to be an expert, but you should be comfortable using the terminal.<\/li>\r\n\r\n\r\n\r\n<li><strong>A user with sudo privileges<\/strong> &ndash; required for installing packages and managing a web server.<\/li>\r\n\r\n\r\n\r\n<li><strong>SSH access<\/strong> &ndash; to connect to your remote server.<\/li>\r\n<\/ul><?xml encoding=\"utf-8\" ?><figure class=\"wp-block-image size-large\"><a class=\"hgr-tutorials-cta hgr-tutorials-cta-vps-hosting\" href=\"\/ng\/vps-hosting\" target=\"_blank\" rel=\"noreferrer noopener\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"300\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/public\" alt=\"\" class=\"wp-image-77934\" srcset=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=1024,fit=scale-down 1024w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=300,fit=scale-down 300w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=150,fit=scale-down 150w, https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2023\/02\/VPS-hosting-banner.png\/w=768,fit=scale-down 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure><h2 id=\"h-how-to-install-php-on-ubuntu\" class=\"wp-block-heading\">How to install PHP on Ubuntu?<\/h2><h3 id=\"h-1-update-your-package-list\" class=\"wp-block-heading\">1. Update your package list<\/h3><p>Before installing PHP, update your system&rsquo;s package list. This ensures Ubuntu knows where to get any necessary installation files.<\/p><p>Use this command:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt update<\/pre><p>It&rsquo;s like checking with your suppliers before placing an order &ndash; if the catalog is outdated, your system might not find what you&rsquo;re asking for.<\/p><h3 id=\"h-2-install-php-on-ubuntu\" class=\"wp-block-heading\">2. Install PHP on Ubuntu<\/h3><p>To install PHP on Ubuntu, start with the <strong>default version<\/strong> available in the package manager. This is usually stable and well-supported.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install php<\/pre><p>If you need a <strong>specific version<\/strong>, like PHP 8.0, you&rsquo;ll need to add a third-party Personal Package Archive (PPA) repository first. The following commands will add the most commonly used PPA for older versions of PHP maintained by Ond&#345;ej Sur&yacute;, and will install your desired version of PHP:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo add-apt-repository ppa:ondrej\/php\r\nsudo apt update\r\nsudo apt install php8.0<\/pre><p>Make sure you replace <strong>php8.0<\/strong> with the version you want.<\/p><p>Once that&rsquo;s done, check if the PHP is running:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php -v<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e1979ce72ee\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/07\/php-version.png\/public\" alt=\"Checking the current PHP version using terminal command.\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>If you see version info without any errors, the installation was successful.<\/p><p>Make a note of the version, as you&rsquo;ll need it later when setting up Apache or Nginx. In the screenshot above, the PHP version is 8.3.<\/p><h3 id=\"h-3-test-php-on-the-command-line\" class=\"wp-block-heading\">3. Test PHP on the command line<\/h3><p>Before setting up a web server, it&rsquo;s best to verify if PHP is working as expected. This helps catch any problems early, before adding more moving parts.<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php -r 'echo \"PHP is workingn\";'<\/pre><p>You should see <strong><em>PHP is working<\/em><\/strong> in the output.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e1979ce8afe\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/07\/php-working.png\/public\" alt=\"Testing if PHP is working through a terminal command.\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>If you get that message, PHP is running fine and you&rsquo;re ready to proceed.<\/p><p>Now that you have PHP installed, it&rsquo;s time to choose and configure your web server. We&rsquo;ll walk through the steps to set up PHP with Apache and Nginx, the two most popular options.<\/p><h3 id=\"h-4-option-1-install-php-with-apache\" class=\"wp-block-heading\">4. Option 1: Install PHP with Apache<\/h3><p>If you want to use PHP with the <a href=\"\/ng\/tutorials\/what-is-apache\">Apache web server<\/a>, you&rsquo;ll need to install Apache along with the PHP module that lets it handle <strong>.php<\/strong> files.<\/p><p>Start by installing Apache:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install apache2<\/pre><p>Then, install the PHP module for Apache <strong>that matches your installed PHP version<\/strong>. For example, if you&rsquo;re using PHP 8.3:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install libapache2-mod-php8.3<\/pre><p>Restart Apache to load the new module:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl restart apache2<\/pre><p>Now it&rsquo;s time to check if everything&rsquo;s working. Create a test file in the Apache root directory:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">echo \"&lt;?php phpinfo(); ?&gt;\" | sudo tee \/var\/www\/html\/info.php<\/pre><p>Open your browser and go to <strong>http:\/\/&lt;your_server_ip&gt;\/info.php<\/strong>. Make sure you replace <strong>&lt;your_server_ip&gt;<\/strong> with the <strong>actual IP<\/strong> of your server.<\/p><p>You should see a page with PHP version details and configuration info. If this page loads as expected, you&rsquo;re all set.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e1979ce9fae\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/07\/php-info-apache.png\/public\" alt=\"PHP info page displayed in the browser.\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Once you&rsquo;re done, you can delete the test file:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo rm \/var\/www\/html\/info.php<\/pre><h3 id=\"h-5-option-2-install-and-configure-php-with-nginx\" class=\"wp-block-heading\">5. Option 2: Install and configure PHP with Nginx<\/h3><p>Unlike Apache, <a href=\"\/ng\/tutorials\/what-is-nginx\">Nginx<\/a> doesn&rsquo;t handle PHP files on its own &ndash; it passes them to the PHP-FPM processor. So, to use PHP with Nginx, you&rsquo;ll need to install both Nginx and the matching version of PHP-FPM.<\/p><p>Start by installing Nginx:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install nginx<\/pre><p>Then, install the PHP-FPM module <strong>that matches your installed PHP version<\/strong>. For example, if you&rsquo;re using PHP 8.3:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install php8.3-fpm<\/pre><p>Next, configure Nginx to work with PHP. Open the default site configuration file:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo nano \/etc\/nginx\/sites-available\/default<\/pre><p>Look for the block that starts with <strong>location ~ .php$<\/strong>. Update it so it looks like the following, adjusting the version number in the socket path to match your PHP version:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">location ~ .php$ {\r\n\r\n&nbsp;&nbsp;&nbsp;&nbsp;include snippets\/fastcgi-php.conf;\r\n\r\n&nbsp;&nbsp;&nbsp;&nbsp;fastcgi_pass unix:\/run\/php\/php8.3-fpm.sock;\r\n\r\n}<\/pre><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e1979ceb4c8\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/07\/nginx-config.png\/public\" alt=\"Nginx configuration to handle PHP files.\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>Once updated, restart both services:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl restart php8.3-fpm\r\n\r\nsudo systemctl restart nginx<\/pre><p>To check if PHP is working, create a test file:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">echo \"&lt;?php phpinfo(); ?&gt;\" | sudo tee \/var\/www\/html\/info.php<\/pre><p>Open your browser and go to <strong>http:\/\/&lt;your_server_ip&gt;\/info.php<\/strong>. Make sure you replace <strong>&lt;your_server_ip&gt;<\/strong> with the <strong>actual IP<\/strong> of your server.<\/p><p>You should see a page with PHP version details and configuration info. If the page loads as expected, it means everything works as expected.<\/p><div class=\"wp-block-image\"><figure data-wp-context='{\"imageId\":\"69e1979cecabc\"}' data-wp-interactive=\"core\/image\" class=\"aligncenter size-large wp-lightbox-container\"><img decoding=\"async\" data-wp-class--hide=\"state.isContentHidden\" data-wp-class--show=\"state.isContentVisible\" data-wp-init=\"callbacks.setButtonStyles\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-on-async--load=\"callbacks.setButtonStyles\" data-wp-on-async-window--resize=\"callbacks.setButtonStyles\" src=\"https:\/\/imagedelivery.net\/LqiWLm-3MGbYHtFuUbcBtA\/wp-content\/uploads\/sites\/2\/2025\/07\/php-info-nginx.png\/public\" alt=\"PHP info page displayed in the browser.\"><button class=\"lightbox-trigger\" type=\"button\" aria-haspopup=\"dialog\" aria-label=\"Enlarge\" data-wp-init=\"callbacks.initTriggerButton\" data-wp-on-async--click=\"actions.showLightbox\" data-wp-style--right=\"state.imageButtonRight\" data-wp-style--top=\"state.imageButtonTop\">\n\t\t\t<svg xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"12\" height=\"12\" fill=\"none\" viewbox=\"0 0 12 12\">\n\t\t\t\t<path fill=\"#fff\" d=\"M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z\"><\/path>\n\t\t\t<\/svg>\n\t\t<\/button><\/figure><\/div><p>When you&rsquo;re done testing, remove the file:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo rm \/var\/www\/html\/info.php<\/pre><h3 id=\"h-6-install-php-extensions\" class=\"wp-block-heading\">6. Install PHP extensions<\/h3><p>At some point, you&rsquo;ll likely need additional PHP extensions. The ones to install will depend on your project&rsquo;s requirements &ndash; they add support for things like databases, XML, or HTTP requests.<\/p><p>A complete list of PHP extensions can be found in the <a href=\"https:\/\/www.php.net\/manual\/en\/extensions.alphabetical.php\">official PHP documentation<\/a>. Here are some commonly used ones:<\/p><ul class=\"wp-block-list\">\r\n<li><strong>php-mysql <\/strong>&ndash; for connecting to MySQL or MariaDB.<\/li>\r\n\r\n\r\n\r\n<li><strong>php-mbstring<\/strong> &ndash; for working with multibyte strings.<\/li>\r\n\r\n\r\n\r\n<li><strong>php-curl<\/strong> &ndash; for sending HTTP requests.<\/li>\r\n\r\n\r\n\r\n<li><strong>php-xml<\/strong> &ndash; for processing XML data.<\/li>\r\n\r\n\r\n\r\n<li><strong>php-zip<\/strong> &ndash; for working with ZIP files.<\/li>\r\n<\/ul><p>To install one or more, run the following, listing each extension like so:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo apt install php8.3-mysql php8.3-mbstring php8.3-curl<\/pre><p>Make sure to match the version number with the PHP version installed on your system.<\/p><p>After installing extensions, always restart your web server and PHP service.<\/p><p>For Apache:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl restart apache2<\/pre><p>For Nginx with PHP-FPM:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">sudo systemctl restart php8.3-fpm\r\n\r\nsudo systemctl restart nginx<\/pre><p>To check currently installed PHP modules, run:<\/p><pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">php -m<\/pre><h2 id=\"h-next-steps-after-installing-php-on-ubuntu\" class=\"wp-block-heading\">Next steps after installing PHP on Ubuntu<\/h2><p>You&rsquo;ve successfully installed PHP on your Ubuntu system and configured it with either Apache or Nginx, setting up a solid foundation for web development.<\/p><p>If your project requires database support, the next step is to <a href=\"\/ng\/tutorials\/how-to-install-mysql-ubuntu\">install MySQL on your Ubuntu server.<\/a> You can manage your database efficiently using tools like <a href=\"\/ng\/tutorials\/how-to-install-and-setup-phpmyadmin-on-ubuntu\">phpMyAdmin<\/a>.<\/p><p>For continued development, consider exploring additional PHP extensions, frameworks like Laravel, or even setting up security measures like SSL.<\/p><p>Take these next steps to enhance your PHP environment further and get your project running smoothly.<\/p><h2 id=\"h-how-to-install-php-on-ubuntu-faq\" class=\"wp-block-heading\">How to install PHP on Ubuntu FAQ<\/h2><div class=\"wp-block-rank-math-faq-block\">\r\n<div class=\"rank-math-faq-item\">\r\n<h3 class=\"rank-math-question\">What version of PHP should I install on Ubuntu?<\/h3>\r\n<div class=\"rank-math-answer\">It depends on the tools or frameworks your project uses. If you&rsquo;re starting fresh, it&rsquo;s recommended to go with the latest stable release available, which includes recent security updates and is usually the safest choice. Keep in mind that some applications may require an older version for compatibility, so check the requirements first.&nbsp;<\/div>\r\n<\/div>\r\n<div class=\"rank-math-faq-item\">\r\n<h3 class=\"rank-math-question\">Do I need to install any additional PHP extensions?<\/h3>\r\n<div class=\"rank-math-answer\">Yes, most likely. A base PHP install usually isn&rsquo;t enough for web applications, but this varies greatly by project. If you&rsquo;re using any external tools or frameworks, check their documentation to see if any additional extensions are needed, then install them using your package manager.<\/div>\r\n<\/div>\r\n<div class=\"rank-math-faq-item\">\r\n<h3 class=\"rank-math-question\">Is there a graphical interface to install PHP on Ubuntu?<\/h3>\r\n<div class=\"rank-math-answer\">Not really. Most Ubuntu servers don&rsquo;t have a graphical interface at all and are managed entirely through the command line. While Ubuntu Desktop offers tools like Synaptic, they&rsquo;re rarely used for server setups. Installing PHP and managing packages is faster and more consistent using terminal commands.<\/div>\r\n<\/div>\r\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Installing PHP on Ubuntu is a crucial first step in setting up a dynamic web environment. Whether you&rsquo;re working with a content management system like WordPress, a custom web application, or a PHP-based framework like Laravel, PHP is the backbone of modern web development. In this guide, we will walk you through the entire process [&#8230;]<\/p>\n<p><a class=\"btn btn-secondary understrap-read-more-link\" href=\"\/ng\/tutorials\/how-to-install-install-php-ubuntu\">Read More&#8230;<\/a><\/p>\n","protected":false},"author":534,"featured_media":143160,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"rank_math_title":"How to install PHP on Ubuntu?","rank_math_description":"Learn how to install PHP on Ubuntu, set it up with Apache or Nginx, and add essential PHP extensions for web development projects.","rank_math_focus_keyword":"install php ubuntu","footnotes":""},"categories":[22644],"tags":[],"class_list":["post-130734","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vps"],"hreflangs":[{"locale":"en-US","link":"https:\/\/www.hostinger.com\/tutorials\/how-to-install-install-php-ubuntu","default":0},{"locale":"en-CA","link":"https:\/\/www.hostinger.com\/ca\/tutorials\/how-to-install-install-php-ubuntu","default":0},{"locale":"en-UK","link":"https:\/\/www.hostinger.com\/uk\/tutorials\/how-to-install-install-php-ubuntu","default":0},{"locale":"en-PH","link":"https:\/\/www.hostinger.com\/ph\/tutorials\/how-to-install-install-php-ubuntu","default":0},{"locale":"en-MY","link":"https:\/\/www.hostinger.com\/my\/tutorials\/how-to-install-install-php-ubuntu","default":0},{"locale":"en-IN","link":"https:\/\/www.hostinger.com\/in\/tutorials\/how-to-install-install-php-ubuntu","default":0},{"locale":"en-AU","link":"https:\/\/www.hostinger.com\/au\/tutorials\/how-to-install-install-php-ubuntu","default":0},{"locale":"en-NG","link":"https:\/\/www.hostinger.com\/ng\/tutorials\/how-to-install-install-php-ubuntu","default":0}],"_links":{"self":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/130734","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/users\/534"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/comments?post=130734"}],"version-history":[{"count":8,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/130734\/revisions"}],"predecessor-version":[{"id":143159,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/posts\/130734\/revisions\/143159"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media\/143160"}],"wp:attachment":[{"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/media?parent=130734"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/categories?post=130734"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hostinger.com\/ng\/tutorials\/wp-json\/wp\/v2\/tags?post=130734"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}