REF: https://computingforgeeks.com/how-to-install-php-on-ubuntu-linux-system/
I already added Ondřej Surý PPA repository. So Just install php8.1
|
1 |
sudo apt install php8.1 |
The apache module and cli for php8.1 is included
|
1 2 3 4 5 6 7 8 |
... 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 ... |
Check it on CLI Terminal
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
satria@teddy:~$ sudo update-alternatives --config php There are 3 choices for the alternative php (providing /usr/bin/php). Selection Path Priority Status ------------------------------------------------------------ 0 /usr/bin/php8.1 81 auto mode * 1 /usr/bin/php7.2 72 manual mode 2 /usr/bin/php7.4 74 manual mode 3 /usr/bin/php8.1 81 manual mode Press <enter> to keep the current choice[*], or type selection number: 0 update-alternatives: using /usr/bin/php8.1 to provide /usr/bin/php (php) in auto mode satria@teddy:~$ php -v PHP 8.1.6 (cli) (built: May 17 2022 16:48:09) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.6, Copyright (c) Zend Technologies with Zend OPcache v8.1.6, Copyright (c), by Zend Technologies |
Then install the extensions.
|
1 |
sudo apt install php8.1-{bcmath,xml,fpm,mysql,zip,intl,ldap,gd,cli,bz2,curl,mbstring,pgsql,opcache,soap,cgi} |
Install XDebug
|
1 |
sudo apt-get install php-xdebug |
Check
|
1 2 3 4 5 6 |
satria@teddy:~$ php -v PHP 8.1.6 (cli) (built: May 17 2022 16:48:09) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.6, Copyright (c) Zend Technologies with Zend OPcache v8.1.6, Copyright (c), by Zend Technologies with Xdebug v3.1.2, Copyright (c) 2002-2021, by Derick Rethans |
PHP8.1 On Apache2
Disable the old PHP
|
1 |
sudo a2dismod php7.2 |
Enable PHP8.1
|
1 |
sudo a2enmod php8.1 |
Also need to run
|
1 |
sudo a2enmod proxy_fcgi setenvif && sudo a2enconf php8.1-fpm |
Restart Apache server
|
1 |
sudo systemctl restart apache2 |
Check on the browser
|
1 |
http://localhost/phpinfo.php |
Should show like PHP Version 8.1.6
CHANGE THE PHP8.1 SETTING
MODIFY SOME INI FILES IN:
/etc/php/8.1/fpm/php.ini –> PHP-FPM AS MAIN
/etc/php/8.1/apache/php.ini –>APACHE
/etc/php/8.1/cli/php.ini –> CLI
|
1 2 3 4 5 6 7 8 |
upload_max_filesize = 4000M -> (default 2M) max_file_uploads = 4000 -> (default 20) post_max_size = 4000M -> (default 8M) max_execution_time = 6000 -> (default 30) in second max_input_time = 6000 -> (default 60) in second max_input_vars = 10000 memory_limit = 5120M -> (default 128M) memory_limit = -1 -> (FOR CLI) |
RESTART
|
1 |
sudo systemctl restart apache2 |
FOR PHP FPM
|
1 |
sudo systemctl restart php8.1-fpm |
TO USE PHP8.1 WITHOUT FPM, PLS STOP PHP8.1 FPM
|
1 |
sudo systemctl stop php8.1-fpm |
ALSO DISABLE SOME FPM MODULES (mpm_event)
|
1 |
sudo a2dismod mpm_event proxy_fcgi |
IF NEEDED
|
1 |
sudo a2disconf php8.1-fpm |
THEN ENABLE mpm_prefork
|
1 |
sudo a2enmod mpm_prefork |
RELOAD
|
1 |
sudo systemctl reload apache2 |
NOW IT’D BE RUNNING
USE NGINX and PHP8.1-FPM
STOP APACHE2
|
1 |
sudo systemctl stop apache2 |
INSTALL NGINX
|
1 |
sudo apt install nginx |
MODIFY THE DEFAULT CONF
|
1 |
sudo gedit /etc/nginx/sites-available/default |
THEN ADD ‘index.php’ SO THE PHP FILE WOULD BE EXECUTED NOT DOWNLOADED.
ALSO UNCOMMENT ‘include snippets/fastcgi-php.conf;’ AND ‘fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;’ AND ‘location ~ /\.ht{…}’
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
... server { ... # Add index.php to the list if you are using PHP index index.php index.html index.htm index.nginx-debian.html; #server_name _; server_name localhost; ... # pass PHP scripts to FastCGI server # location ~ \.php$ { # try_files $uri =404; # fastcgi_split_path_info ^(.+?\.php)(/.+)?$; include snippets/fastcgi-php.conf; # # # With php-fpm (or other unix sockets): # fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; # # With php-cgi (or other tcp sockets): # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } } ... |
CHECK SETTING: sudo nginx -t
RELOAD NGINX
|
1 |
sudo systemctl restart nginx |
SOMETIMES IT’D NEED TO RESTART/LOGOFF THE COMPUTER!!!
CHECK ON
|
1 |
http://localhost/phpinfo.php |
CONFIGURE PHPMYADMIN WITH NGINX
MODIFY /etc/nginx/sites-available/default
|
1 |
sudo gedit /etc/nginx/sites-available/default |
THEN ADD:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
server{ ... location /phpmyadmin { root /usr/share/; index index.php; try_files $uri $uri/ =404; location ~ ^/phpmyadmin/(doc|sql|setup)/ { deny all; } location ~ /phpmyadmin/(.+\.php)$ { fastcgi_pass unix:/var/run/php/php8.1-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; include snippets/fastcgi-php.conf; } } ... } |
RELOAD NGINX
OPEN PHPMYADMIN: http://localhost/phpmyadmin