How to install PHP8
How to install PHP and related modules
If you are using CentOS7 or older CentOS, please use yum instead of dnf.
If you are using Ubuntu, please use apt-get.
How to install PHP provided by Linux’s distributors
PHP can be older than official PHP but its maintenance is done by OS distributor.
So you can leave the update of PHP to them.
sudo dnf -y install php; sudo dnf -y install php-bcmath php-cli php-curl php-devel php-fpm php-gd php-json php-ldap php-mbstring php-mysqlnd php-xml php-odbc php-opcache php-pdo php-pear php-pgsql php-soap php-xml php-xmlrpc php-zip;
How to install PHP provided by official PHP
You can get latest PHP from official PHP, which is merit.
Demerit is that you have to keep catching up with update provided by official PHP, so you have to take responsibility of that part.
# In the case of CentOS 8 # This can be different based on your system, so please refer to http://rpms.remirepo.net/enterprise/ # In the case of PHP 8.0 OSVER=8; PHPVER=80; sudo dnf -y install http://rpms.remirepo.net/enterprise/remi-release-$OSVER.rpm; sudo dnf -y install epel-release yum-utils; sudo dnf config-manager --set-enabled PowerTools; sudo dnf -y install php$PHPVER*; sudo yum -y install php$PHPVER-php-bcmath php$PHPVER-php-cli php$PHPVER-php-curl php$PHPVER-php-devel php$PHPVER-php-fpm php$PHPVER-php-gd php$PHPVER-php-json php$PHPVER-php-ldap php$PHPVER-php-mbstring php$PHPVER-php-mysqlnd php$PHPVER-php-xml php$PHPVER-php-odbc php$PHPVER-php-opcache php$PHPVER-php-pdo php$PHPVER-php-pear php$PHPVER-php-pgsql php$PHPVER-php-soap php$PHPVER-php-xml php$PHPVER-php-xmlrpc php$PHPVER-php-zip; sudo update-alternatives \ --install /usr/bin/php php /opt/remi/php$PHPVER/root/usr/bin/php 0 \ --slave /usr/bin/php-cgi php-cgi /opt/remi/php$PHPVER/root/usr/bin/php-cgi \ --slave /usr/bin/pear pear /opt/remi/php$PHPVER/root/usr/bin/pear \ --slave /usr/bin/phar.phar phar /opt/remi/php$PHPVER/root/usr/bin/phar.phar;
If you have multiple version of PHP, you can switch it by
sudo alternatives --config php;
On my environment, I saw following output.
There are 2 programs which provide 'php'. Selection Command ----------------------------------------------- *+ 1 /opt/remi/php74/root/usr/bin/php 2 /opt/remi/php80/root/usr/bin/php
Then type number which you want to use.
Confirm version of PHP
php -v;
PHP 8.0.0 (cli) (built: Nov 24 2020 17:04:03) ( NTS gcc x86_64 ) Copyright (c) The PHP Group Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies with Zend OPcache v8.0.0, Copyright (c), by Zend Technologies
Install composer
sudo dnf -y install composer;
If composer is not provided through OS distribution, install it following instruciton.
https://getcomposer.org/download/
composer.phar will be put where you typed the command, so you should move it to the execution path.
mv composer.phar /usr/local/bin/;
How to install PHP-FPM
Install
PHPVER=80; dnf install -y php$PHPVER-php-fpm; systemctl enable php$PHPVER-php-fpm; systemctl start php$PHPVER-php-fpm;
Setting of config file
vi /etc/opt/remi/php$PHPVER/php-fpm.d/www.conf
To enable connection through TCP port,
#listen = /var/opt/remi/php$PHPVER/run/php-fpm/www.sock listen = 127.0.0.1:9000
To make php-fpm work with nginx instead of APache,
#group = apache group = nginx #user = apache user = nginx
How to deal with issue of mkdir failure for tmp directory when you are using php-fpm
vi /lib/systemd/system/php$PHPVER-php-fpm.service
Then set
PrivateTmp=false
in the file.
After editing, reflect the change.
systemctl daemon-reload; systemctl restart php$VER-php-fpm;
How to install PHP on Mac
If you have installed homebrew
https://brew.sh/
brew install php;
If you want to install PHP 8.0 even if homebrew’s default latest php is 7.x,
brew update&&brew tap shivammathur/php&&brew install shivammathur/php/php@8.0&&brew link --overwrite --force php@8.0
Then you can use PHP8 at
/usr/local/bin/php
What is VPS?
OS & Virtual Environment
- How to switch to AlmaLinux from CentOS(RHE’s clone)
- How to upgrade to CentOS 8 from CentOS 7 and its merit
- Benchmark of performance degradation by Docker's overhead with knowhow of installation&usage of docker
Database
Programming Language