{"id":14125,"date":"2023-04-24T09:24:58","date_gmt":"2023-04-24T09:24:58","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=14125"},"modified":"2023-09-18T15:42:31","modified_gmt":"2023-09-18T15:42:31","slug":"how-to-update-to-php-7-4-on-ubuntu","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-update-to-php-7-4-on-ubuntu\/","title":{"rendered":"How to Update to PHP 7.4 on Ubuntu?"},"content":{"rendered":"<p>PHP 7.4 comes with several performance improvements and new features. If you&#8217;re running an older version of PHP on your <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-ubuntu-beginners-guide-ubuntu-linux-distro\/\">Ubuntu system<\/a>, upgrading to PHP 7.4 can provide a significant boost to your web applications. In this guide, we&#8217;ll walk you through the process of updating to PHP 7.4 on Ubuntu.<\/p>\n<p>Note: These instructions are for Ubuntu 18.04 and 20.04. Some steps may differ for other Ubuntu versions.<\/p>\n<pre>\r\nroot@geek:~# php -v\r\nPHP 7.2.24-0ubuntu0.18.04.17 (cli) (built: Feb 23 2023 13:29:25) ( NTS )\r\nCopyright (c) 1997-2018 The PHP Group\r\nZend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.24-0ubuntu0.18.04.17, Copyright (c) 1999-2018, by Zend Technologies\r\n<\/pre>\n<h2>Step 1: Add the PHP Repository<\/h2>\n<p>To ensure that you&#8217;re installing PHP 7.4 from a trusted source, add the ondrej\/php repository to your system. This repository is maintained by Ond\u0159ej Sur\u00fd, a well-known Debian and Ubuntu PHP package maintainer.<\/p>\n<p>First, update the package list and install the necessary packages:<\/p>\n<pre>\r\nsudo apt update\r\nsudo apt install -y software-properties-common\r\n<\/pre>\n<p>Next, add the ondrej\/php repository:<\/p>\n<pre>\r\nsudo add-apt-repository ppa:ondrej\/php\r\n<\/pre>\n<p>Update the package list again to include the packages from the newly added repository:<\/p>\n<pre>\r\nsudo apt update\r\n<\/pre>\n<h2>Step 2: Install PHP 7.4<\/h2>\n<p>Install PHP 7.4 and its associated modules by running the following command:<\/p>\n<pre>\r\nsudo apt install -y php7.4\r\n<\/pre>\n<pre>\r\nroot@geek:~# sudo apt install -y php7.4\r\nReading package lists... Done\r\nBuilding dependency tree       \r\nReading state information... Done\r\nThe following additional packages will be installed:\r\n  libapache2-mod-php7.4 libargon2-1 libpcre2-8-0 php-common php7.4-cli php7.4-common php7.4-json php7.4-opcache\r\n  php7.4-readline\r\nThe following NEW packages will be installed:\r\n  libapache2-mod-php7.4 libargon2-1 php7.4 php7.4-cli php7.4-common php7.4-json php7.4-opcache php7.4-readline\r\nThe following packages will be upgraded:\r\n  libpcre2-8-0 php-common\r\n2 upgraded, 8 newly installed, 0 to remove and 40 not upgraded.\r\nNeed to get 3,911 kB of archives.\r\nAfter this operation, 17.3 MB of additional disk space will be used.\r\nGet:1 http:\/\/ppa.launchpad.net\/ondrej\/php\/ubuntu bionic\/main amd64 php-common all 2:93+ubuntu18.04.1+deb.sury.org+2 [16.3 kB]\r\nGet:2 http:\/\/ppa.launchpad.net\/ondrej\/php\/ubuntu bionic\/main amd64 php7.4-common amd64 1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1 [641 kB]\r\nGet:3 http:\/\/ppa.launchpad.net\/ondrej\/php\/ubuntu bionic\/main amd64 php7.4-json amd64 1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1 [18.7 kB]\r\nGet:4 http:\/\/ppa.launchpad.net\/ondrej\/php\/ubuntu bionic\/main amd64 php7.4-opcache amd64 1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1 [196 kB]\r\nGet:5 http:\/\/ppa.launchpad.net\/ondrej\/php\/ubuntu bionic\/main amd64 php7.4-readline amd64 1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1 [12.3 kB]\r\nGet:6 http:\/\/ppa.launchpad.net\/ondrej\/php\/ubuntu bionic\/main amd64 libargon2-1 amd64 0~20190702-0.1+ubuntu18.04.1+deb.sury.org+1 [20.4 kB]\r\nGet:7 http:\/\/ppa.launchpad.net\/ondrej\/php\/ubuntu bionic\/main amd64 libpcre2-8-0 amd64 10.40-1+ubuntu18.04.1+deb.sury.org+1 [206 kB]\r\nGet:8 http:\/\/ppa.launchpad.net\/ondrej\/php\/ubuntu bionic\/main amd64 php7.4-cli amd64 1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1 [1,404 kB]\r\nGet:9 http:\/\/ppa.launchpad.net\/ondrej\/php\/ubuntu bionic\/main amd64 libapache2-mod-php7.4 amd64 1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1 [1,346 kB]\r\nGet:10 http:\/\/ppa.launchpad.net\/ondrej\/php\/ubuntu bionic\/main amd64 php7.4 all 1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1 [51.2 kB]\r\nFetched 3,911 kB in 3s (1,449 kB\/s)\r\n(Reading database ... 121438 files and directories currently installed.)\r\nPreparing to unpack ...\/0-php-common_2%3a93+ubuntu18.04.1+deb.sury.org+2_all.deb ...\r\nUnpacking php-common (2:93+ubuntu18.04.1+deb.sury.org+2) over (1:60ubuntu1) ...\r\nSelecting previously unselected package php7.4-common.\r\nPreparing to unpack ...\/1-php7.4-common_1%3a7.4.33-5+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...\r\nUnpacking php7.4-common (1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1) ...\r\nSelecting previously unselected package php7.4-json.\r\nPreparing to unpack ...\/2-php7.4-json_1%3a7.4.33-5+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...\r\nUnpacking php7.4-json (1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1) ...\r\nSelecting previously unselected package php7.4-opcache.\r\nPreparing to unpack ...\/3-php7.4-opcache_1%3a7.4.33-5+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...\r\nUnpacking php7.4-opcache (1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1) ...\r\nSelecting previously unselected package php7.4-readline.\r\nPreparing to unpack ...\/4-php7.4-readline_1%3a7.4.33-5+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...\r\nUnpacking php7.4-readline (1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1) ...\r\nSelecting previously unselected package libargon2-1:amd64.\r\nPreparing to unpack ...\/5-libargon2-1_0~20190702-0.1+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...\r\nUnpacking libargon2-1:amd64 (0~20190702-0.1+ubuntu18.04.1+deb.sury.org+1) ...\r\nPreparing to unpack ...\/6-libpcre2-8-0_10.40-1+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...\r\nUnpacking libpcre2-8-0:amd64 (10.40-1+ubuntu18.04.1+deb.sury.org+1) over (10.31-2) ...\r\nSelecting previously unselected package php7.4-cli.\r\nPreparing to unpack ...\/7-php7.4-cli_1%3a7.4.33-5+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...\r\nUnpacking php7.4-cli (1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1) ...\r\nSelecting previously unselected package libapache2-mod-php7.4.\r\nPreparing to unpack ...\/8-libapache2-mod-php7.4_1%3a7.4.33-5+ubuntu18.04.1+deb.sury.org+1_amd64.deb ...\r\nUnpacking libapache2-mod-php7.4 (1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1) ...\r\nSelecting previously unselected package php7.4.\r\nPreparing to unpack ...\/9-php7.4_1%3a7.4.33-5+ubuntu18.04.1+deb.sury.org+1_all.deb ...\r\nUnpacking php7.4 (1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1) ...\r\nSetting up php-common (2:93+ubuntu18.04.1+deb.sury.org+2) ...\r\nSetting up libargon2-1:amd64 (0~20190702-0.1+ubuntu18.04.1+deb.sury.org+1) ...\r\nSetting up libpcre2-8-0:amd64 (10.40-1+ubuntu18.04.1+deb.sury.org+1) ...\r\nSetting up php7.4-common (1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1) ...\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/calendar.ini with new version\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/ctype.ini with new version\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/exif.ini with new version\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/fileinfo.ini with new version\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/ffi.ini with new version\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/ftp.ini with new version\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/gettext.ini with new version\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/iconv.ini with new version\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/pdo.ini with new version\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/phar.ini with new version\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/posix.ini with new version\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/shmop.ini with new version\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/sockets.ini with new version\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/sysvmsg.ini with new version\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/sysvsem.ini with new version\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/sysvshm.ini with new version\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/tokenizer.ini with new version\r\nSetting up php7.4-opcache (1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1) ...\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/opcache.ini with new version\r\nSetting up php7.4-readline (1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1) ...\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/readline.ini with new version\r\nSetting up php7.4-json (1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1) ...\r\n\r\nCreating config file \/etc\/php\/7.4\/mods-available\/json.ini with new version\r\nSetting up php7.4-cli (1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1) ...\r\nupdate-alternatives: using \/usr\/bin\/php7.4 to provide \/usr\/bin\/php (php) in auto mode\r\nupdate-alternatives: using \/usr\/bin\/phar7.4 to provide \/usr\/bin\/phar (phar) in auto mode\r\nupdate-alternatives: using \/usr\/bin\/phar.phar7.4 to provide \/usr\/bin\/phar.phar (phar.phar) in auto mode\r\n\r\nCreating config file \/etc\/php\/7.4\/cli\/php.ini with new version\r\nSetting up libapache2-mod-php7.4 (1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1) ...\r\n\r\nCreating config file \/etc\/php\/7.4\/apache2\/php.ini with new version\r\nlibapache2-mod-php7.4: php7.2 module already enabled, not enabling PHP 7.4\r\nSetting up php7.4 (1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1) ...\r\nProcessing triggers for man-db (2.8.3-2ubuntu0.1) ...\r\nProcessing triggers for libc-bin (2.27-3ubuntu1.6) ...\r\nProcessing triggers for php7.4-cli (1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1) ...\r\nProcessing triggers for libapache2-mod-php7.4 (1:7.4.33-5+ubuntu18.04.1+deb.sury.org+1) ...\r\n<\/pre>\n<p>If you need any additional PHP extensions, you can install them using the following format:<\/p>\n<pre>\r\nsudo apt install -y php7.4-[extension-name]\r\n<\/pre>\n<p>For example, to install the MySQL, GD, and XML extensions, run:<\/p>\n<pre>\r\nsudo apt install -y php7.4-mysql php7.4-gd php7.4-xml\r\n<\/pre>\n<h2>Step 3: Verify PHP 7.4 Installation<\/h2>\n<p>After installing PHP 7.4, verify the installation by checking the PHP version:<\/p>\n<pre>\r\nphp -v\r\n<\/pre>\n<p>The output should display PHP 7.4.x, where &#8216;x&#8217; is the latest minor version.<\/p>\n<pre>\r\nroot@geek:~# php -v\r\nPHP 7.4.33 (cli) (built: Feb 14 2023 18:30:50) ( NTS )\r\nCopyright (c) The PHP Group\r\nZend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.33, Copyright (c), by Zend Technologies\r\n<\/pre>\n<h2>Step 4: Configure Your Web Server<\/h2>\n<p>If you&#8217;re using Apache, you may need to update the configuration to use PHP 7.4. First, disable the old PHP version and enable PHP 7.4:<\/p>\n<pre>\r\nsudo a2dismod php[old_version]\r\nsudo a2enmod php7.4\r\n<\/pre>\n<p>Replace [old_version] with the previous PHP version you had installed (e.g., 7.2 or 7.3).<\/p>\n<p>Next, restart the Apache service to apply the changes:<\/p>\n<pre>\r\nsudo systemctl restart apache2\r\n<\/pre>\n<p>If you&#8217;re using Nginx, you&#8217;ll need to update the PHP-FPM configuration. Open the Nginx configuration file for your website (usually located in \/etc\/nginx\/sites-available\/) and update the fastcgi_pass directive to point to the PHP 7.4 FPM socket:<\/p>\n<pre>\r\nfastcgi_pass unix:\/var\/run\/php\/php7.4-fpm.sock;\r\n<\/pre>\n<p>Finally, restart the Nginx and PHP-FPM services to apply the changes:<\/p>\n<pre>\r\nsudo systemctl restart nginx\r\nsudo systemctl restart php7.4-fpm\r\n<\/pre>\n<h2>Conclusion<\/h2>\n<p>You have now successfully updated to PHP 7.4 on your Ubuntu system. Be sure to test your web applications thoroughly to ensure compatibility with the new PHP version.<\/p>\n<p>If you have any questions, comments, or suggestions for improvement, please feel free to share your thoughts in the comments section below. Your feedback is invaluable to us, and it helps us create better and more informative content for our users.<\/p>\n<h2>Additional Considerations<\/h2>\n<p>After upgrading to PHP 7.4, it&#8217;s crucial to review the changes and deprecated features in this version. You can refer to the PHP 7.4 migration guide here for more information.<\/p>\n<p>It&#8217;s also a good idea to check the error logs for any issues or warnings related to the PHP upgrade. For Apache, the error log is typically located at \/var\/log\/apache2\/error.log, and for Nginx, the error log can be found at \/var\/log\/nginx\/error.log. The PHP-FPM error log is usually located at \/var\/log\/php7.4-fpm.log.<\/p>\n<p>In case you encounter any issues after the upgrade, you might need to adjust your PHP scripts or configurations to comply with PHP 7.4 requirements. Keep in mind that some PHP extensions may also require updates or may no longer be supported in PHP 7.4.<\/p>\n<p>Remember to keep your PHP version up-to-date by regularly checking for updates and applying them as needed. This ensures that your system remains secure and benefits from the latest performance improvements and features.<\/p>\n<p>If you need to switch between multiple PHP versions, consider using a tool like <a href=\"https:\/\/github.com\/phpbrew\/phpbrew\" rel=\"noopener\" target=\"_blank\">phpbrew<\/a> to manage different PHP installations more easily.<\/p>\n<p>Feel free to leave any questions or suggestions in the comments section below. We&#8217;re here to help you make the most of your PHP installation and ensure a seamless experience when upgrading to newer versions.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP 7.4 comes with several performance improvements and new features. If you&#8217;re running an older version of PHP on your Ubuntu system, upgrading to PHP 7.4 can provide a significant&#8230;<\/p>\n","protected":false},"author":6,"featured_media":1262,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[996,1073],"tags":[1646,1856,2033],"class_list":["post-14125","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-ubuntu","tag-php","tag-ubuntu","tag-upgrade"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/14125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=14125"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/14125\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/1262"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=14125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=14125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=14125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}