{"id":9694,"date":"2022-06-02T03:14:59","date_gmt":"2022-06-02T03:14:59","guid":{"rendered":"https:\/\/myprojects.advchaweb.com\/?p=9694"},"modified":"2024-11-11T13:56:15","modified_gmt":"2024-11-11T13:56:15","slug":"install-php-8-1-on-ubuntu-20-04-apache-and-nginx","status":"publish","type":"post","link":"https:\/\/myprojects.advchaweb.com\/index.php\/2022\/06\/02\/install-php-8-1-on-ubuntu-20-04-apache-and-nginx\/","title":{"rendered":"Install PHP 8.1 On Ubuntu 20.04 (Apache and Nginx)"},"content":{"rendered":"<p>REF: https:\/\/computingforgeeks.com\/how-to-install-php-on-ubuntu-linux-system\/<\/p>\n<p>I already added Ond\u0159ej Sur\u00fd PPA repository. So Just install php8.1<\/p>\n<pre class=\"lang:default decode:true \">sudo apt install php8.1<\/pre>\n<p>The apache module and cli for php8.1 is included<\/p>\n<pre class=\"lang:default decode:true \">...\r\nThe following additional packages will be installed:\r\n  libapache2-mod-php8.1 php8.1-cli php8.1-opcache php8.1-readline\r\nSuggested packages:\r\n  php-pear\r\nThe following NEW packages will be installed:\r\n  libapache2-mod-php8.1 php8.1 php8.1-cli php8.1-opcache php8.1-readline\r\n...<\/pre>\n<p>Check it on CLI Terminal<\/p>\n<pre class=\"lang:default decode:true\">satria@teddy:~$ sudo update-alternatives --config php\r\nThere are 3 choices for the alternative php (providing \/usr\/bin\/php).\r\n\r\n  Selection    Path             Priority   Status\r\n------------------------------------------------------------\r\n  0            \/usr\/bin\/php8.1   81        auto mode\r\n* 1            \/usr\/bin\/php7.2   72        manual mode\r\n  2            \/usr\/bin\/php7.4   74        manual mode\r\n  3            \/usr\/bin\/php8.1   81        manual mode\r\n\r\nPress &lt;enter&gt; to keep the current choice[*], or type selection number: 0\r\nupdate-alternatives: using \/usr\/bin\/php8.1 to provide \/usr\/bin\/php (php) in auto mode\r\nsatria@teddy:~$ php -v\r\nPHP 8.1.6 (cli) (built: May 17 2022 16:48:09) (NTS)\r\nCopyright (c) The PHP Group\r\nZend Engine v4.1.6, Copyright (c) Zend Technologies\r\n    with Zend OPcache v8.1.6, Copyright (c), by Zend Technologies<\/pre>\n<p>Then install the extensions.<\/p>\n<pre class=\"lang:default decode:true \">sudo apt install php8.1-{bcmath,xml,fpm,mysql,zip,intl,ldap,gd,cli,bz2,curl,mbstring,pgsql,opcache,soap,cgi}<\/pre>\n<p>Install XDebug<\/p>\n<pre class=\"lang:default decode:true \">sudo apt-get install php-xdebug<\/pre>\n<p>Check<\/p>\n<pre class=\"lang:default decode:true \">satria@teddy:~$ php -v\r\nPHP 8.1.6 (cli) (built: May 17 2022 16:48:09) (NTS)\r\nCopyright (c) The PHP Group\r\nZend Engine v4.1.6, Copyright (c) Zend Technologies\r\n    with Zend OPcache v8.1.6, Copyright (c), by Zend Technologies\r\n    with Xdebug v3.1.2, Copyright (c) 2002-2021, by Derick Rethans<\/pre>\n<p>PHP8.1 On Apache2<br \/>\nDisable the old PHP<\/p>\n<pre class=\"lang:default decode:true\">sudo a2dismod php7.2<\/pre>\n<p>Enable PHP8.1<\/p>\n<pre class=\"lang:default decode:true\">sudo a2enmod php8.1<\/pre>\n<p>Also need to run<\/p>\n<pre class=\"lang:default decode:true\">sudo a2enmod proxy_fcgi setenvif &amp;&amp; sudo a2enconf php8.1-fpm<\/pre>\n<p>Restart Apache server<\/p>\n<pre class=\"lang:default decode:true \">sudo systemctl restart apache2<\/pre>\n<p>Check on the browser<\/p>\n<pre class=\"lang:default decode:true \">http:\/\/localhost\/phpinfo.php<\/pre>\n<p>Should show like PHP Version 8.1.6<\/p>\n<p>CHANGE THE PHP8.1 SETTING<br \/>\nMODIFY SOME INI FILES IN:<br \/>\n\/etc\/php\/8.1\/fpm\/php.ini\u00a0 &#8211;&gt; PHP-FPM\u00a0 AS MAIN<br \/>\n\/etc\/php\/8.1\/apache\/php.ini\u00a0 &#8211;&gt;APACHE<br \/>\n\/etc\/php\/8.1\/cli\/php.ini &#8211;&gt; CLI<\/p>\n<pre class=\"lang:default decode:true \">upload_max_filesize = 4000M -&gt; (default 2M) \r\nmax_file_uploads = 4000 -&gt; (default 20) \r\npost_max_size = 4000M -&gt; (default 8M) \r\nmax_execution_time = 6000 -&gt; (default 30) in second \r\nmax_input_time = 6000 -&gt; (default 60) in second \r\nmax_input_vars = 10000 \r\nmemory_limit = 5120M -&gt; (default 128M) \r\nmemory_limit = -1 -&gt; (FOR CLI)<\/pre>\n<p>RESTART<\/p>\n<pre class=\"lang:default decode:true \">sudo systemctl restart apache2<\/pre>\n<p>FOR PHP FPM<\/p>\n<pre class=\"lang:default decode:true \">sudo systemctl restart php8.1-fpm<\/pre>\n<p>TO USE PHP8.1 WITHOUT FPM, PLS STOP PHP8.1 FPM<\/p>\n<pre class=\"lang:default decode:true \">sudo systemctl stop php8.1-fpm<\/pre>\n<p>ALSO DISABLE SOME FPM MODULES (mpm_event)<\/p>\n<pre class=\"lang:default decode:true \">sudo a2dismod mpm_event proxy_fcgi<\/pre>\n<p>IF NEEDED<\/p>\n<pre class=\"lang:default decode:true \">sudo a2disconf php8.1-fpm<\/pre>\n<p>THEN ENABLE mpm_prefork<\/p>\n<pre class=\"lang:default decode:true\">sudo a2enmod mpm_prefork<\/pre>\n<p>RELOAD<\/p>\n<pre class=\"lang:default decode:true \">sudo systemctl reload apache2<\/pre>\n<p>NOW IT&#8217;D BE RUNNING<\/p>\n<p>USE NGINX and PHP8.1-FPM<br \/>\nSTOP APACHE2<\/p>\n<pre class=\"lang:default decode:true \">sudo systemctl stop apache2<\/pre>\n<p>INSTALL NGINX<\/p>\n<pre class=\"lang:default decode:true \">sudo apt install nginx<\/pre>\n<p>MODIFY THE DEFAULT CONF<\/p>\n<pre class=\"lang:default decode:true\">sudo gedit \/etc\/nginx\/sites-available\/default<\/pre>\n<p>THEN ADD &#8216;index.php&#8217; SO THE PHP FILE WOULD BE EXECUTED NOT DOWNLOADED.<br \/>\nALSO UNCOMMENT &#8216;include snippets\/fastcgi-php.conf;&#8217; AND &#8216;fastcgi_pass unix:\/var\/run\/php\/php8.1-fpm.sock;&#8217; AND &#8216;location ~ \/\\.ht{&#8230;}&#8217;<\/p>\n<pre class=\"lang:default decode:true \">...\r\nserver {\r\n\t...\r\n\r\n\t# Add index.php to the list if you are using PHP\r\n\tindex index.php index.html index.htm index.nginx-debian.html;\r\n\r\n\t#server_name _;\r\n\tserver_name localhost;\r\n\r\n\t...\r\n\r\n\t# pass PHP scripts to FastCGI server\r\n\t#\r\n\tlocation ~ \\.php$ {\r\n\t#  try_files $uri =404;\r\n  #  fastcgi_split_path_info ^(.+?\\.php)(\/.+)?$;\r\n\t\tinclude snippets\/fastcgi-php.conf;\r\n\t#\r\n\t#\t# With php-fpm (or other unix sockets):\r\n\t#\tfastcgi_pass unix:\/var\/run\/php\/php7.4-fpm.sock;\r\n\t\tfastcgi_pass unix:\/var\/run\/php\/php8.1-fpm.sock;\r\n\t#\t# With php-cgi (or other tcp sockets):\r\n\t#\tfastcgi_pass 127.0.0.1:9000;\r\n\t#  fastcgi_index index.php;\r\n  #  include fastcgi_params;\r\n\t}\r\n\r\n\t# deny access to .htaccess files, if Apache's document root\r\n\t# concurs with nginx's one\r\n\t#\r\n\tlocation ~ \/\\.ht {\r\n\t\tdeny all;\r\n\t}\r\n}\r\n\r\n...<\/pre>\n<p>CHECK SETTING: sudo nginx -t<br \/>\nRELOAD NGINX<\/p>\n<pre class=\"lang:default decode:true \">sudo systemctl restart nginx<\/pre>\n<p>SOMETIMES IT&#8217;D NEED TO RESTART\/LOGOFF THE COMPUTER!!!<br \/>\nCHECK ON<\/p>\n<pre class=\"lang:default decode:true \">http:\/\/localhost\/phpinfo.php<\/pre>\n<p>CONFIGURE PHPMYADMIN WITH NGINX<br \/>\nMODIFY \/etc\/nginx\/sites-available\/default<\/p>\n<pre class=\"lang:default decode:true\">sudo gedit \/etc\/nginx\/sites-available\/default<\/pre>\n<p>THEN ADD:<\/p>\n<pre class=\"lang:default decode:true\">server{\r\n    ...\r\n    location \/phpmyadmin {\r\n        root \/usr\/share\/;\r\n        index index.php;\r\n        try_files $uri $uri\/ =404;\r\n\r\n        location ~ ^\/phpmyadmin\/(doc|sql|setup)\/ {\r\n            deny all;\r\n        }\r\n\r\n        location ~ \/phpmyadmin\/(.+\\.php)$ {\r\n            fastcgi_pass unix:\/var\/run\/php\/php8.1-fpm.sock;\r\n            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\r\n            include fastcgi_params;\r\n            include snippets\/fastcgi-php.conf;\r\n        }\r\n    }\r\n    ...\r\n}<\/pre>\n<p>RELOAD NGINX<br \/>\nOPEN PHPMYADMIN: http:\/\/localhost\/phpmyadmin<\/p>\n","protected":false},"excerpt":{"rendered":"<p>REF: https:\/\/computingforgeeks.com\/how-to-install-php-on-ubuntu-linux-system\/ I already added Ond\u0159ej Sur\u00fd PPA repository. So Just install php8.1 sudo apt install php8.1 The apache module and cli for php8.1 is included &#8230; The following additional packages will be installed: libapache2-mod-php8.1 php8.1-cli php8.1-opcache php8.1-readline Suggested packages: php-pear The following NEW packages will be installed: libapache2-mod-php8.1 php8.1 php8.1-cli php8.1-opcache php8.1-readline &#8230; Check &hellip; <a href=\"https:\/\/myprojects.advchaweb.com\/index.php\/2022\/06\/02\/install-php-8-1-on-ubuntu-20-04-apache-and-nginx\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Install PHP 8.1 On Ubuntu 20.04 (Apache and Nginx)&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[48],"tags":[],"class_list":["post-9694","post","type-post","status-publish","format-standard","hentry","category-php-2"],"_links":{"self":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/9694","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/comments?post=9694"}],"version-history":[{"count":8,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/9694\/revisions"}],"predecessor-version":[{"id":9711,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/posts\/9694\/revisions\/9711"}],"wp:attachment":[{"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/media?parent=9694"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/categories?post=9694"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/myprojects.advchaweb.com\/index.php\/wp-json\/wp\/v2\/tags?post=9694"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}