{"id":10932,"date":"2024-04-10T06:37:48","date_gmt":"2024-04-10T06:37:48","guid":{"rendered":"https:\/\/youstable.com\/blog\/?p=10932"},"modified":"2024-04-13T07:19:44","modified_gmt":"2024-04-13T07:19:44","slug":"install-and-run-php-8-x-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/www.youstable.com\/blog\/install-and-run-php-8-x-on-ubuntu-20-04","title":{"rendered":"How to Install and Run PHP 8.x on Ubuntu 20.04 &#8211; Step-by-Step Guide"},"content":{"rendered":"\n<p>PHP is one of the most popular programming languages for web development, powering millions of websites worldwide. With the release of PHP 8.x, developers gain access to numerous new features, enhancements, and performance improvements. If you&#8217;re an Ubuntu 20.04 user interested in harnessing the power of PHP 8.x for your projects, this guide will walk you through the installation process step by step.<\/p>\n\n\n\n<p><strong>Step 1: Update your system<\/strong><\/p>\n\n\n\n<p>Before installing PHP 8.x, it is very important to make sure your system is up-to-date. Open a terminal and run the following commands:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsudo apt update\nsudo apt upgrade\n<\/pre><\/div>\n\n\n<p>This will update the package list and upgrade the existing packages to their latest version.<\/p>\n\n\n\n<p><strong>Step 2: Install PHP 8.x<\/strong><\/p>\n\n\n\n<p>The Ubuntu 20.04 repository may not have the latest PHP version available. Therefore, we will use the Ond\u0159ej Sur\u00fd repository, which provides up-to-date PHP packages for Ubuntu.<\/p>\n\n\n\n<p>Add repository:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsudo add-apt-repository ppa:ondrej\/php\n<\/pre><\/div>\n\n\n<p>Press Enter when prompted to confirm adding the repository.<\/p>\n\n\n\n<p>Next, update the package list again.<\/p>\n\n\n\n<p>sudo apt update<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsudo apt update\n<\/pre><\/div>\n\n\n<p>Finally, install PHP 8.x with the usual extensions:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsudo apt php8.0 install php8.0-common php8.0-cli\n<\/pre><\/div>\n\n\n<p>This command installs PHP 8.0 core with a command-line interface and common modules. You can install additional PHP extensions as per your requirements.<\/p>\n\n\n\n<p><strong>Step 3: Verify the PHP installation<\/strong><\/p>\n\n\n\n<p>To ensure that PHP 8.x is installed correctly, you can run the following command to check the installed version:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nphp -v\n<\/pre><\/div>\n\n\n<p>This command will display the PHP version installed on your system.<\/p>\n\n\n\n<p><strong>Step 4: Configure Apache or Nginx<\/strong><\/p>\n\n\n\n<p>If you use Apache or Nginx as your web server, you need to configure them to work with PHP. For Apache, you can install the PHP module with the following command:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsudo apt install libapache2-mod-php8.0\n<\/pre><\/div>\n\n\n<p>After installing the module, restart Apache.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsudo systemctl restart apache2\n<\/pre><\/div>\n\n\n<p>For Nginx, you need to install the PHP FastCGI Process Manager (PHP-FPM) with the following command:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsudo apt-install php8.0-fpm\n<\/pre><\/div>\n\n\n<p>Then, you need to configure your Nginx server blocks to use PHP-FPM. This configuration may vary depending on your specific setup.<\/p>\n\n\n\n<p><strong>Step 5: Test the PHP<\/strong><\/p>\n\n\n\n<p>To ensure that PHP is running correctly on . your web server, you can create a simple PHP script and access it through a web browser. For example, create a file named `info.php` in the document root directory of your web server (e.g., `\/var\/www\/html\/`) with the following content:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n&amp;lt;?php\nphpinfo();\n?&gt;\n<\/pre><\/div>\n\n\n<p>Save the file and then access it through your web browser (e.g., <a href=\"http:\/\/localhost\/info.php\" target=\"_blank\" rel=\"noopener\">http:\/\/localhost\/info.php<\/a>). You should see a page displaying PHP configuration information.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" class=\"wp-block-heading\" id=\"conclusion\">Conclusion<\/h2>\n\n\n\n<p>By following these steps, you can easily install and run PHP 8.x on Ubuntu 20.04. Whether you are an experienced developer or just starting out with PHP development, using the latest version brings many benefits in terms of performance, security, and new features. Keeping your PHP environment up-to-date ensures compatibility with modern web applications and frameworks, enhancing the overall development experience.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP is one of the most popular programming languages for web development, powering millions of websites worldwide. With the release [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":10975,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"inline_featured_image":false,"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":"","ast-disable-related-posts":"","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":"default","ast-page-background-enabled":"default","ast-page-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":"","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-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":"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":""},"mobile":{"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":""}},"footnotes":""},"categories":[3],"tags":[2075],"class_list":["post-10932","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-hosting","tag-php"],"acf":[],"featured_image_src":"https:\/\/www.youstable.com\/blog\/wp-content\/uploads\/2024\/04\/PHP-8.X-On-Ubuntu-20.04.jpg","author_info":{"display_name":"YouStable","author_link":"https:\/\/www.youstable.com\/blog\/author\/youstable"},"_links":{"self":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts\/10932","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/comments?post=10932"}],"version-history":[{"count":6,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts\/10932\/revisions"}],"predecessor-version":[{"id":13886,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/posts\/10932\/revisions\/13886"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/media\/10975"}],"wp:attachment":[{"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/media?parent=10932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/categories?post=10932"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.youstable.com\/blog\/wp-json\/wp\/v2\/tags?post=10932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}