dev/lamp/php.md
2024-12-11 10:11:56 +02:00

4.1 KiB

Installation

dnf install php83
dnf install php83-php-opcache php83-php-gd php83-php-curl php83-php-mysqlnd php83-php-mbstring 
dnf install php83-php-devel php83-php-xml php83-php-pear php83-php-fpm php83-php-mysql php83-php-pdo
dnf install php83-php-json php83-php-zip php83-php-common php83-php-cli php83-php-xmlrpc
dnf install php83-php-xml php83-php-tidy php83-php-soap php83-php-bcmath
dnf install php83-php-gd php-pdo php-mysqlnd php83-php-intl
dnf install php82
dnf install php82-php-opcache php82-php-gd php82-php-curl php82-php-mysqlnd php82-php-mbstring 
dnf install php82-php-devel php82-php-xml php82-php-pear php82-php-fpm php82-php-mysql php82-php-pdo
dnf install php82-php-json php82-php-zip php82-php-common php82-php-cli php82-php-xmlrpc
dnf install php82-php-xml php82-php-tidy php82-php-soap php82-php-bcmath
dnf install php82-php-gd php-pdo php-mysqlnd php82-php-intl
dnf install php74
dnf install php74-php-opcache php74-php-gd php74-php-curl php74-php-mysqlnd php74-php-mbstring 
dnf install php74-php-devel php74-php-xml php74-php-pear php74-php-fpm php74-php-mysql php74-php-pdo
dnf install php74-php-json php74-php-zip php74-php-common php74-php-cli php74-php-xmlrpc
dnf install php74-php-xml php74-php-tidy php74-php-soap php74-php-bcmath

Configure

mv /usr/bin/php /usr/bin/php.bak
mv /usr/bin/phpize /usr/bin/phpize.bak
mv /usr/bin/php-config /usr/bin/php-config.bak

alternatives --install /usr/bin/php php /usr/bin/php82 1
alternatives --install /usr/bin/phpize phpize /usr/bin/phpize-8.2 1
alternatives --install /usr/bin/php-config php-config /usr/bin/php-config-8.2 1

alternatives --install /usr/bin/php php /usr/bin/php83 1
alternatives --install /usr/bin/phpize phpize /usr/bin/phpize-8.3 1
alternatives --install /usr/bin/php-config php-config /usr/bin/php-config-8.3 1
sed -i 's/:9000/:9074/' /etc/opt/remi/php74/php-fpm.d/www.conf
sed -i 's/:9000/:9080/' /etc/opt/remi/php82/php-fpm.d/www.conf
semanage port -a -t http_port_t -p tcp 9080
semanage port -a -t http_port_t -p tcp 9074

SystemD

systemctl start php82-php-fpm
systemctl start php74-php-fpm
systemctl enable php74-php-fpm
systemctl enable php82-php-fpm
systemctl status php74-php-fpm
systemctl status php82-php-fpm

php-cgi

/var/www/cgi-bin/php82.fcgi

#!/bin/bash
exec /bin/php82-cgi

/var/www/cgi-bin/php74.fcgi

#!/bin/bash
exec /bin/php74-cgi

chmod 755 /var/www/cgi-bin/php*

httpd configs

/etc/httpd/conf.d/php82.conf

Listen 8082

<VirtualHost *:8082>
     ServerAdmin root@localhost.com
     ServerName exmaple82.com
     DocumentRoot /var/www/html
     DirectoryIndex index.php index.html
<FilesMatch "\.php$">
  <If "-f %{REQUEST_FILENAME}">
      SetHandler "proxy:unix:/var/opt/remi/php82/run/php-fpm/www.sock|fcgi://localhost"
  </If>
</FilesMatch>
     ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
     AddHandler php82-fcgi .php
     Action php82-fcgi /cgi-bin/php82.fcgi
 <Directory  "/var/www/html">
    AllowOverride All
  </Directory>
</VirtualHost>

/etc/httpd/conf.d/php74.conf

Listen 8074

<VirtualHost *:8074>
     ServerAdmin root@localhost.com
     ServerName exmaple74.com
     DocumentRoot /var/www/html
     DirectoryIndex index.php index.html
<FilesMatch "\.php$">
  <If "-f %{REQUEST_FILENAME}">
      SetHandler "proxy:unix:/var/opt/remi/php74/run/php-fpm/www.sock|fcgi://localhost"
  </If>
</FilesMatch>
     ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
     AddHandler php74-fcgi .php
     Action php74-fcgi /cgi-bin/php74.fcgi
 <Directory  "/var/www/html">
    AllowOverride All
  </Directory>
</VirtualHost>

Set Default

scl enable php74 bash
php -v
scl enable php82 bash
php -v

Test

echo "<?php phpinfo(); ?>" > /var/www/html/index.php
systemctl restart php82-php-fpm
systemctl restart php74-php-fpm
systemctl restart httpd
firefox http://your-server:8082
firefox http://your-server:8074

Composer

# Install
wget https://getcomposer.org/installer -O composer-installer.php
php composer-installer.php --filename=composer --install-dir=/usr/local/bin

# Test
composer -v