PHP einrichten
Zur Navigation springen
Zur Suche springen
Links
Zielsetzung
PHP ist eine Programmiersprache. Hier wird beschrieben, wie sie genutzt werden kann.
Installation
Repository einrichten
sudo apt install -y lsb-release ca-certificates apt-transport-https software-properties-common gnupg2
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/sury-php.list
curl -fsSL https://packages.sury.org/php/apt.gpg| sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/sury-keyring.gpg
sudo apt update
Pakete installieren
PHP_VERS=8.2
apt install php$PHP_VERS php$PHP_VERS-cli php$PHP_VERS-common php$PHP_VERS-curl php$PHP_VERS-fpm \
php$PHP_VERS-gd php$PHP_VERS-igbinary php$PHP_VERS-imagick php$PHP_VERS-intl \
php$PHP_VERS-mbstring php$PHP_VERS-memcached php$PHP_VERS-msgpack php$PHP_VERS-mysql \
php$PHP_VERS-opcache php$PHP_VERS-pgsql php$PHP_VERS-phpdbg php$PHP_VERS-readline \
php$PHP_VERS-redis php$PHP_VERS-xdebug php$PHP_VERS-xml php$PHP_VERS-zip php$PHP_VERS-ssh2 \
redis php$PHP_VERS-opcache
Wichtige Konfiguration in php.ini
- PHP_VERS=8.2
- /etc/php/$PHP_VERS/fpm/php.ini
memory_limit = 2048M upload_max_filesize = 512M max_file_uploads = 100 post_max_size = 512M max_execution_time = 600 max_input_time = 600 default_socket_timeout = 600 [Session] #session.save_handler = files session.save_handler = redis session.save_path = "tcp://127.0.0.1:6379" [opcache] opcache.enable=1 opcache.memory_consumption=1024 opcache.interned_strings_buffer=512 [XDebug] ; Ist normalerweise in xdebug-spezifischer Konfiguration, z.B. mods.d/20-xdebug ;zend_extension="/usr/lib/php/20160303/xdebug.so" xdebug.remote_port=9004 xdebug.remote_enable=On xdebug.remote_host=192.168.100.100 ; Alternativ: remote-Adresse selber ermitteln: ;xdebug.remote_connect_back=On xdebug.remote_log=/var/log/php/xdebug.log xdebug.remote_autostart=1
- Diese Einstellungen werden folgendermaßen erstellt:
FN=/etc/php/$PHP_VERS/fpm/php.ini
sed -i $FN \
-e 's/^memory_limit *=.*/memory_limit = 2048M/' \
-e 's/^upload_max_filesize *=.*/upload_max_filesize = 512M/' \
-e 's/^max_file_uploads *=.*/max_file_uploads = 100/' \
-e 's/^post_max_size *=.*/post_max_size = 512M/' \
-e 's/^max_execution_time *=.*/max_execution_time = 600/' \
-e 's/^max_input_time *=.*/max_input_time = 600/' \
-e 's/^default_socket_timeout *=.*/default_socket_timeout = 600/' \
-e 's/^session.save_handler *=.*/session.save_handler = redis/' \
-e 's%^session.save_path *=.*%session.save_path = "tcp://127.0.0.1:6379"%' \
-e 's/^opcache.enable *=.*/opcache.enable = 1/' \
-e 's/^opcache.memory_consumption *=.*/opcache.memory_consumption = 1024/' \
-e 's/^opcache.interned_strings_buffer =.*/opcache.interned_strings_buffer = 512/' \
$FN
grep -q ^session.save_path $FN || sed -i -e 's%^;session.save_path *=.*%session.save_path = "tcp://127.0.0.1:6379"%' $FN
grep -q ^opcache.enable $FN || sed -i -e 's/^;opcache.enable *=.*/opcache.enable = 1/' $FN
grep -q ^opcache.memory_consumption $FN || sed -i -e 's/^;opcache.memory_consumption *=.*/opcache.memory_consumption = 1024/' $FN
grep -q ^opcache.interned_strings_buffer $FN || sed -i -e 's/^;opcache.interned_strings_buffer =.*/opcache.interned_strings_buffer = 512/' $FN
# Debugging:
grep -q ^xdebug.remote_port $FN || cat <<EOS >>$FN
[XDebug]
xdebug.remote_port=9082
xdebug.remote_enable=On
xdebug.remote_host=localhost
; Alternativ: remote-Adresse selber ermitteln:
;xdebug.remote_connect_back=On
xdebug.remote_autostart=1
EOS
- in NGINX:
- fastcgi_read_timeout 3600s;