{"id":76320,"date":"2020-11-28T10:25:36","date_gmt":"2020-11-28T03:25:36","guid":{"rendered":"https:\/\/harianaceh.co.id\/?p=76320"},"modified":"2022-09-30T08:25:06","modified_gmt":"2022-09-30T01:25:06","slug":"steps-to-install-php-8-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/www.harianaceh.co.id\/2020\/11\/28\/steps-to-install-php-8-on-ubuntu-20-04\/","title":{"rendered":"Steps to Install PHP 8 on Ubuntu 20.04"},"content":{"rendered":"<p><strong>BANDA ACEH<\/strong> &#8211; Install <a title=\"PHP 8\" href=\"https:\/\/www.harianaceh.co.id\/tag\/php-8\/\">PHP 8<\/a> on Ubuntu 20.04. This guide let you learn how install the latest PHP version 8 and upgrade to latest on your Ubuntu 20.04 or 18.04 systems or your Ubuntu server on any VPS or any Cloud or any Dedicated hosting and configure it with Apache and Nginx.<\/p>\n<p>The latest PHP 8 is officially released on November 26th, 2020. It comes with a number of new features and a few incompatibilities that you should be aware of before upgrading from the previous version.<\/p>\n<p>This installation is tested on Google Cloud Platform with a Compute Compute Engine VM Instance. This set up will work on all Linux servers.<\/p>\n<h3>Prerequisites<\/h3>\n<ol>\n<li>A Ubuntu server set up\u00a0with\u00a0<code>sudo<\/code>\u00a0privileges.<\/li>\n<li>Completed the\u00a0initial Ubuntu server setup.<\/li>\n<\/ol>\n<p>If you are using Google Cloud Platform to install PHP you need the following steps to be done.<\/p>\n<ol>\n<li>A running Compute Engine, see the\u00a0Setting up Compute Engine Instance with Ubuntu 20.04.<\/li>\n<\/ol>\n<h3>Getting Started<\/h3>\n<p>Make sure your Ubuntu server is having the latest packages by running the following command.<\/p>\n<pre class=\"wp-block-preformatted\">sudo apt update\r\nsudo apt upgrade<\/pre>\n<p>This will update the package index and update the installed packages to the latest version.<\/p>\n<h3>Add PPA for PHP 8<\/h3>\n<p>Add the\u00a0<code>ondrej\/php<\/code>\u00a0which has PHP 8 package and other required PHP extensions.<\/p>\n<pre class=\"wp-block-preformatted\">sudo apt install software-properties-common\r\nsudo add-apt-repository ppa:ondrej\/php\r\nsudo apt update<\/pre>\n<p>Once you have added the PPA you can install PHP 8.<\/p>\n<h3>Install PHP 8 for Apache<\/h3>\n<p>Execute the following command to install PHP 8<\/p>\n<pre class=\"wp-block-preformatted\">sudo apt install php8.0<\/pre>\n<p>After the installation has completed, you can confirm the installation using the following command<\/p>\n<pre class=\"wp-block-preformatted\">php -v<\/pre>\n<h3>Install PHP 8 FPM for Nginx<\/h3>\n<p>For Nginx you need to install FPM, execute the following command to install PHP 8 FPM<\/p>\n<pre class=\"wp-block-preformatted\">sudo apt install php8.0-fpm<\/pre>\n<p>After the installation has completed, confirm that PHP 8 FPM has installed correctly with this command<\/p>\n<pre class=\"wp-block-preformatted\">php-fpm8.0 -v<\/pre>\n<h3>Install PHP 8 Extensions<\/h3>\n<p>Installing PHP extensions are simple with the following syntax.<\/p>\n<pre class=\"wp-block-preformatted\">sudo apt install php8.0-<span class=\"replace\">extension_name<\/span><\/pre>\n<p>Now, install some commonly used\u00a0<code>php-extensions<\/code>\u00a0with the following command.<\/p>\n<pre class=\"wp-block-preformatted\">sudo apt install php8.0-common php8.0-mysql php8.0-xml php8.0-curl php8.0-gd php8.0-imagick php8.0-cli php8.0-dev php8.0-imap php8.0-mbstring php8.0-opcache php8.0-soap php8.0-zip -y<\/pre>\n<h3>Configure PHP 8 for Apache<\/h3>\n<p>Now we configure PHP for Web Applications by changing some values in\u00a0<code>php.ini<\/code>\u00a0file.<\/p>\n<p>For PHP 8 with Apache the\u00a0<code>php.ini<\/code>\u00a0location will be in following directory.<\/p>\n<pre class=\"wp-block-preformatted\">sudo nano \/etc\/php\/8.0\/apache2\/php.ini<\/pre>\n<p>Hit\u00a0<code>F6<\/code>\u00a0for search inside the editor and update the following values for better performance.<\/p>\n<p>&nbsp;<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:true,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:false,&quot;align&quot;:&quot;&quot;}\">upload_max_filesize = 32M\r\npost_max_size = 48M\r\nmemory_limit = 256M\r\nmax_execution_time = 600\r\nmax_input_vars = 3000\r\nmax_input_time = 1000<\/pre>\n<\/div>\n<p>Once you have modified your PHP settings you need to restart your Apache for the changes to take effect.<\/p>\n<h3>Configure PHP 8 for Nginx<\/h3>\n<p>For PHP 8 FPM with Nginx the\u00a0<code>php.ini<\/code>\u00a0location will be in following directory.<\/p>\n<pre class=\"wp-block-preformatted\">sudo nano \/etc\/php\/8.0\/fpm\/php.ini<\/pre>\n<p>Hit\u00a0<code>F6<\/code>\u00a0for search inside the editor and update the following values for better performance.<\/p>\n<p>&nbsp;<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:true,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:false,&quot;align&quot;:&quot;&quot;}\">upload_max_filesize = 32M\r\npost_max_size = 48M\r\nmemory_limit = 256M\r\nmax_execution_time = 600\r\nmax_input_vars = 3000\r\nmax_input_time = 1000<\/pre>\n<\/div>\n<p>Once you have modified your PHP settings you need to restart PHP FPM for the changes to take effect.<\/p>\n<pre id=\"block-8db38a9d-e938-47ed-b162-748b0d9b2925\" class=\"wp-block-preformatted\">sudo php-fpm8.0 -t \r\nsudo service php8.0-fpm restart<\/pre>\n<h3>Configure PHP 8 FPM Pools \u2013 Nginx<\/h3>\n<p>PHP 8 FPM allows you to configure the\u00a0<code>user<\/code>\u00a0and\u00a0<code>group<\/code>\u00a0that the service will run under. You can modify these with these commands<\/p>\n<pre class=\"wp-block-preformatted\">sudo nano \/etc\/php\/8.0\/fpm\/pool.d\/www.conf<\/pre>\n<p>Change the following lines by replacing the\u00a0<strong>www-data<\/strong>\u00a0with your\u00a0<code>username<\/code>.<\/p>\n<p>&nbsp;<\/p>\n<div class=\"wp-block-codemirror-blocks code-block \">\n<pre class=\"CodeMirror\" data-setting=\"{&quot;mode&quot;:&quot;shell&quot;,&quot;mime&quot;:&quot;text\/x-sh&quot;,&quot;theme&quot;:&quot;material&quot;,&quot;lineNumbers&quot;:true,&quot;lineWrapping&quot;:true,&quot;styleActiveLine&quot;:true,&quot;readOnly&quot;:false,&quot;align&quot;:&quot;&quot;}\">user = username\r\ngroup = username\r\nlisten.owner = username\r\nlisten.group = username<\/pre>\n<\/div>\n<p>Hit\u00a0<code>CTRL+X<\/code>\u00a0and\u00a0<code>Y<\/code>\u00a0to save the configuration and check if the configuration is correct and restart PHP.<\/p>\n<h3>Restart PHP 8.0 FPM \u2013 Nginx<\/h3>\n<p>Once you have updated your PHP FPM settings you need to restart it to apply the changes.<\/p>\n<pre>sudo php-fpm8.0 -t \r\nsudo service php8.0-fpm restart\r\n<\/pre>\n<p>Now you are having PHP 8 Installed and configured.<\/p>\n<h3>Upgrade to PHP 8 for Apache<\/h3>\n<p>Once you have installed PHP 8 you need to upgrade to the latest installed version of PHP.<\/p>\n<p>You need to disable the old PHP version and enable the new PHP version 8.<\/p>\n<pre class=\"wp-block-preformatted\">sudo a2dismod php<span class=\"replace\">7.4<\/span><\/pre>\n<p>This command will disable the PHP 7.4 module.<\/p>\n<pre>sudo a2enmod php8.0<\/pre>\n<p>This command will enable the PHP 8 module.<\/p>\n<p>Now you need to restart Apache for the changes to take effect.<\/p>\n<pre class=\"wp-block-preformatted\">sudo service apache2 restart<\/pre>\n<h3>Upgrade to PHP 8 for Nginx<\/h3>\n<p>For Nginx you need to update the PHP-FPM socket in your Nginx configuration located inside the\u00a0<code>sites-available<\/code>\u00a0directory. This will be located inside the\u00a0<code>location<\/code>\u00a0block\u00a0<code>location\u00a0~\u00a0\\.php$<\/code><\/p>\n<p>Edit your configuration\u2026<\/p>\n<pre>sudo nano \/etc\/nginx\/sites-available\/your.conf<\/pre>\n<p>The line you need to modify will look like this\u2026<\/p>\n<pre>fastcgi_pass\u00a0unix:\/run\/php\/php7.4-fpm.sock;<\/pre>\n<p>You need to replace the old PHP version with the new version.<\/p>\n<pre>fastcgi_pass\u00a0unix:\/run\/php\/php8.0-fpm.sock;<\/pre>\n<p>Test your configuration and restart Nginx.<\/p>\n<pre>sudo nginx -t\r\nsudo service nginx restart<\/pre>\n<h3>Conclusion<\/h3>\n<p>Now you have learned how to install PHP 8 and upgrade your configuration on your Ubuntu server.<\/p>\n<p>Thanks for your time. If you face any problem or any feedback, please leave a comment below.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Install PHP 8 on Ubuntu 20.04. This guide let you learn how install the latest PHP version 8 and upgrade to latest on your Ubuntu 20.04 or 18.04 systems or<\/p>\n","protected":false},"author":1,"featured_media":76326,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_disable_autopaging":true},"categories":[61,64],"tags":[71191,71192,58638,71189,71190],"series":[],"class_list":["post-76320","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-teknologi","category-internet","tag-php-8","tag-ubuntu-20-04","tag-ubuntu","tag-php","tag-how-to"],"_links":{"self":[{"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/posts\/76320","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/comments?post=76320"}],"version-history":[{"count":0,"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/posts\/76320\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/media\/76326"}],"wp:attachment":[{"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/media?parent=76320"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/categories?post=76320"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/tags?post=76320"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.harianaceh.co.id\/aplikasi-api\/wp\/v2\/series?post=76320"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}