#!/usr/bin/env bash

sed -i -r 's/([a-z]{2}.)?archive.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
sed -i -r 's/security.ubuntu.com/old-releases.ubuntu.com/g' /etc/apt/sources.list
apt update
DEBIAN_FRONTEND=noninteractive apt -y install tzdata
apt install php-cli \
php-redis \
php-luasandbox \
php-fpm \
php-common \
php-cli \
php-gd \
php-mysql \
php-mbstring \
php-curl \
php-xml \
php-zip \
php-json \
php-xdebug \
php-tokenizer \
php-fileinfo \
php-dom \
php-xmlwriter \
php-mysqli \
php-imagick \
php-simplexml \
php-sqlite3 \
composer -y

apt install supervisor -y

sed -i 's@listen = /run/php/php8.3-fpm.sock@listen = 0.0.0.0:9000@g' /etc/php/8.3/fpm/pool.d/www.conf

sed -i 's@post_max_size = 8M@post_max_size = 85M@g' /etc/php/8.3/fpm/php.ini
sed -i 's@upload_max_filesize = 2M@upload_max_filesize = 10M@g' /etc/php/8.3/fpm/php.ini
sed -i 's@memory_limit = 128M@memory_limit = 512M@g' /etc/php/8.3/fpm/php.ini

sed -i 's@memory_limit = 128M@memory_limit = 512M@g' /etc/php/8.3/cli/php.ini

XDEBUG_CONF_CLI="/etc/php/8.3/cli/conf.d/20-xdebug.ini"
# echo 'zend_extension=xdebug.so' >> $XDEBUG_CONF
echo 'xdebug.start_with_request=yes' >> $XDEBUG_CONF_CLI
echo 'xdebug.discover_client_host=true' >> $XDEBUG_CONF_CLI
echo 'xdebug.remote_cookie_expire_time = 3600' >> $XDEBUG_CONF_CLI
echo 'xdebug.client_host=192.168.0.1' >> $XDEBUG_CONF_CLI
echo 'xdebug.client_port = 9000' >> $XDEBUG_CONF_CLI
echo 'xdebug.remote_handler = dbgp' >> $XDEBUG_CONF_CLI
echo 'xdebug.idekey=PHPSTORM' >> $XDEBUG_CONF_CLI
echo 'xdebug.mode = debug' >> $XDEBUG_CONF_CLI

XDEBUG_CONF_FPM="/etc/php/8.3/fpm/conf.d/20-xdebug.ini"
# echo 'zend_extension=xdebug.so' >> $XDEBUG_CONF
echo 'xdebug.start_with_request=yes' >> $XDEBUG_CONF_FPM
echo 'xdebug.discover_client_host=true' >> $XDEBUG_CONF_FPM
echo 'xdebug.remote_cookie_expire_time = 3600' >> $XDEBUG_CONF_FPM
echo 'xdebug.client_host=192.168.0.1' >> $XDEBUG_CONF_FPM
echo 'xdebug.client_port = 9000' >> $XDEBUG_CONF_FPM
echo 'xdebug.remote_handler = dbgp' >> $XDEBUG_CONF_FPM
echo 'xdebug.idekey=PHPSTORM' >> $XDEBUG_CONF_FPM
echo 'xdebug.mode = debug' >> $XDEBUG_CONF_FPM