Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
litan1106 committed Jan 19, 2024
1 parent cadad27 commit 93f9524
Showing 1 changed file with 35 additions and 38 deletions.
73 changes: 35 additions & 38 deletions bin/wsl-init
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ sudo mkdir -p /etc/apt/keyrings

# NodeJS
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_21.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" | sudo tee /etc/apt/sources.list.d/nodesource.list

# PostgreSQL
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo gpg --dearmor -o /etc/apt/keyrings/postgresql.gpg
Expand All @@ -47,34 +47,31 @@ apt-get update -y
apt-get install -y build-essential dos2unix gcc git git-lfs libmcrypt4 libpcre3-dev libpng-dev chrony unzip make pv \
python3-pip re2c supervisor unattended-upgrades whois vim cifs-utils bash-completion zsh graphviz avahi-daemon tshark

# PHP
apt-get install -y --allow-change-held-packages \
php-imagick php-memcached php-redis php-xdebug php-dev php-swoole

# PHP 8.3
apt-get install -y --allow-change-held-packages \
php8.3 php8.3-bcmath php8.3-bz2 php8.3-cgi php8.3-cli php8.3-common php8.3-curl php8.3-dba php8.3-dev \
php8.3-enchant php8.3-fpm php8.3-gd php8.3-gmp php8.3-imap php8.3-interbase php8.3-intl php8.3-ldap \
php8.3-mbstring php8.3-mysql php8.3-odbc php8.3-opcache php8.3-pgsql php8.3-phpdbg php8.3-pspell php8.3-readline \
php8.3-snmp php8.3-soap php8.3-sqlite3 php8.3-sybase php8.3-tidy php8.3-xml php8.3-xsl \
php8.3-zip php8.3-imagick php8.3-memcached php8.3-redis php8.3-xmlrpc php8.3-xdebug
php$PHP_VERSION php$PHP_VERSION-bcmath php$PHP_VERSION-bz2 php$PHP_VERSION-cgi php$PHP_VERSION-cli php$PHP_VERSION-common php$PHP_VERSION-curl php$PHP_VERSION-dba php$PHP_VERSION-dev \
php$PHP_VERSION-enchant php$PHP_VERSION-fpm php$PHP_VERSION-gd php$PHP_VERSION-gmp php$PHP_VERSION-imap php$PHP_VERSION-interbase php$PHP_VERSION-intl php$PHP_VERSION-ldap \
php$PHP_VERSION-mbstring php$PHP_VERSION-mysql php$PHP_VERSION-odbc php$PHP_VERSION-opcache php$PHP_VERSION-pgsql php$PHP_VERSION-phpdbg php$PHP_VERSION-pspell php$PHP_VERSION-readline \
php$PHP_VERSION-snmp php$PHP_VERSION-soap php$PHP_VERSION-sqlite3 php$PHP_VERSION-sybase php$PHP_VERSION-tidy php$PHP_VERSION-xml php$PHP_VERSION-xsl \
php$PHP_VERSION-zip php$PHP_VERSION-imagick php$PHP_VERSION-memcached php$PHP_VERSION-redis php$PHP_VERSION-xmlrpc php$PHP_VERSION-xdebug \
php$PHP_VERSION-imagick php$PHP_VERSION-memcached php$PHP_VERSION-redis php$PHP_VERSION-xdebug php$PHP_VERSION-dev php$PHP_VERSION-swoole

# Configure php.ini for CLI
sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/8.3/cli/php.ini
sed -i "s/display_errors = .*/display_errors = On/" /etc/php/8.3/cli/php.ini
sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/8.3/cli/php.ini
sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/8.3/cli/php.ini
sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/$PHP_VERSION/cli/php.ini
sed -i "s/display_errors = .*/display_errors = On/" /etc/php/$PHP_VERSION/cli/php.ini
sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/$PHP_VERSION/cli/php.ini
sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/$PHP_VERSION/cli/php.ini

# Configure Xdebug
echo "xdebug.mode = debug" >> /etc/php/8.3/mods-available/xdebug.ini
echo "xdebug.discover_client_host = true" >> /etc/php/8.3/mods-available/xdebug.ini
echo "xdebug.client_port = 9003" >> /etc/php/8.3/mods-available/xdebug.ini
echo "xdebug.max_nesting_level = 512" >> /etc/php/8.3/mods-available/xdebug.ini
echo "opcache.revalidate_freq = 0" >> /etc/php/8.3/mods-available/opcache.ini
echo "xdebug.mode = debug" >> /etc/php/$PHP_VERSION/mods-available/xdebug.ini
echo "xdebug.discover_client_host = true" >> /etc/php/$PHP_VERSION/mods-available/xdebug.ini
echo "xdebug.client_port = 9003" >> /etc/php/$PHP_VERSION/mods-available/xdebug.ini
echo "xdebug.max_nesting_level = 512" >> /etc/php/$PHP_VERSION/mods-available/xdebug.ini
echo "opcache.revalidate_freq = 0" >> /etc/php/$PHP_VERSION/mods-available/opcache.ini

# Fixed php fpm bind listening socket - no such file issue.
mkdir -p /run/php
touch /run/php/php8.3-fpm.sock
touch /run/php/php$PHP_VERSION-fpm.sock

# Install Composer
curl -sS https://getcomposer.org/installer | php
Expand Down Expand Up @@ -102,35 +99,35 @@ touch /home/$WSL_USER_NAME/.config/nginx/nginx.conf
ln -sf /home/$WSL_USER_NAME/.config/nginx/nginx.conf /etc/nginx/conf.d/nginx.conf

# Configure php.ini for FPM
sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/8.3/fpm/php.ini
sed -i "s/display_errors = .*/display_errors = On/" /etc/php/8.3/fpm/php.ini
sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/8.3/fpm/php.ini
sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/8.3/fpm/php.ini
sed -i "s/upload_max_filesize = .*/upload_max_filesize = 100M/" /etc/php/8.3/fpm/php.ini
sed -i "s/post_max_size = .*/post_max_size = 100M/" /etc/php/8.3/fpm/php.ini
sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/8.3/fpm/php.ini

printf "[openssl]\n" | tee -a /etc/php/8.3/fpm/php.ini
printf "openssl.cainfo = /etc/ssl/certs/ca-certificates.crt\n" | tee -a /etc/php/8.3/fpm/php.ini
printf "[curl]\n" | tee -a /etc/php/8.3/fpm/php.ini
printf "curl.cainfo = /etc/ssl/certs/ca-certificates.crt\n" | tee -a /etc/php/8.3/fpm/php.ini
sed -i "s/error_reporting = .*/error_reporting = E_ALL/" /etc/php/$PHP_VERSION/fpm/php.ini
sed -i "s/display_errors = .*/display_errors = On/" /etc/php/$PHP_VERSION/fpm/php.ini
sed -i "s/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/" /etc/php/$PHP_VERSION/fpm/php.ini
sed -i "s/memory_limit = .*/memory_limit = 512M/" /etc/php/$PHP_VERSION/fpm/php.ini
sed -i "s/upload_max_filesize = .*/upload_max_filesize = 100M/" /etc/php/$PHP_VERSION/fpm/php.ini
sed -i "s/post_max_size = .*/post_max_size = 100M/" /etc/php/$PHP_VERSION/fpm/php.ini
sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/$PHP_VERSION/fpm/php.ini

printf "[openssl]\n" | tee -a /etc/php/$PHP_VERSION/fpm/php.ini
printf "openssl.cainfo = /etc/ssl/certs/ca-certificates.crt\n" | tee -a /etc/php/$PHP_VERSION/fpm/php.ini
printf "[curl]\n" | tee -a /etc/php/$PHP_VERSION/fpm/php.ini
printf "curl.cainfo = /etc/ssl/certs/ca-certificates.crt\n" | tee -a /etc/php/$PHP_VERSION/fpm/php.ini

# Set The Nginx & PHP-FPM User
sed -i "s/user www-data;/user $WSL_USER_NAME;/" /etc/nginx/nginx.conf
sed -i "s/# server_names_hash_bucket_size.*/server_names_hash_bucket_size 64;/" /etc/nginx/nginx.conf

sed -i "s/user = www-data/user = $WSL_USER_NAME/" /etc/php/8.3/fpm/pool.d/www.conf
sed -i "s/group = www-data/group = $WSL_USER_NAME/" /etc/php/8.3/fpm/pool.d/www.conf
sed -i "s/user = www-data/user = $WSL_USER_NAME/" /etc/php/$PHP_VERSION/fpm/pool.d/www.conf
sed -i "s/group = www-data/group = $WSL_USER_NAME/" /etc/php/$PHP_VERSION/fpm/pool.d/www.conf

sed -i "s/listen\.owner.*/listen.owner = $WSL_USER_NAME/" /etc/php/8.3/fpm/pool.d/www.conf
sed -i "s/listen\.group.*/listen.group = $WSL_USER_NAME/" /etc/php/8.3/fpm/pool.d/www.conf
sed -i "s/;listen\.mode.*/listen.mode = 0666/" /etc/php/8.3/fpm/pool.d/www.conf
sed -i "s/listen\.owner.*/listen.owner = $WSL_USER_NAME/" /etc/php/$PHP_VERSION/fpm/pool.d/www.conf
sed -i "s/listen\.group.*/listen.group = $WSL_USER_NAME/" /etc/php/$PHP_VERSION/fpm/pool.d/www.conf
sed -i "s/;listen\.mode.*/listen.mode = 0666/" /etc/php/$PHP_VERSION/fpm/pool.d/www.conf

# Disable XDebug On The CLI
sudo phpdismod -s cli xdebug

service nginx restart
service php8.3-fpm restart
service php$PHP_VERSION-fpm restart

# Add $WSL_USER_NAME User To WWW-Data
usermod -a -G www-data $WSL_USER_NAME
Expand Down

0 comments on commit 93f9524

Please sign in to comment.