55 lines
2.2 KiB
Bash

#!/bin/bash
PHP_VER=8.1
# Install PHP modules for Apache2
sudo su
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ bookworm main" > /etc/apt/sources.list.d/php.list
apt update
apt install libapache2-mod-php${PHP_VER}
apt install php${PHP_VER} php${PHP_VER}-cli php${PHP_VER}-common php${PHP_VER}-curl php${PHP_VER}-mbstring php${PHP_VER}-mysql php${PHP_VER}-xml php${PHP_VER}-fileinfo php${PHP_VER}-xml php${PHP_VER}-mbstring php${PHP_VER}-pdo php${PHP_VER}-zip php${PHP_VER}-http php${PHP_VER}-cli
phpenmod ctype curl dom iconv mbstring posix simplexml xml zip fileinfo pdo_mysql
sudo systemctl enable apache2 --now
sudo systemctl restart apache2
# Testing
sudo rm -rf /var/www/html/*
sudo nano /var/www/html/index.php
sudo nano /etc/php/8.1/apache2/php.ini
sudo systemctl restart apache2
# sudo systemctl stop apache2
# sudo systemctl disable apache2
# Install Nginx
sudo su
wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg
echo "deb https://packages.sury.org/php/ bookworm main" > /etc/apt/sources.list.d/php.list
apt update
apt install php${PHP_VER}-fpm
apt install php${PHP_VER}-curl php${PHP_VER}-mbstring php${PHP_VER}-mysql php${PHP_VER}-xml php${PHP_VER}-fileinfo php${PHP_VER}-xml php${PHP_VER}-mbstring php${PHP_VER}-pdo php${PHP_VER}-zip php${PHP_VER}-http php${PHP_VER}-cli
phpenmod ctype curl dom iconv mbstring posix simplexml xml zip fileinfo pdo_mysql
sudo systemctl enable nginx --now
sudo systemctl enable php${PHP_VER}-fpm --now
sudo systemctl restart php${PHP_VER}-fpm
cd /etc/nginx/sites-available/
sudo nano default
sudo rm ../sites-enabled/default
sudo ln default ../sites-enabled/
sudo systemctl reload nginx
# Testing
sudo rm -rf /var/www/html/*
sudo nano /var/www/html/index.php
sudo nano /etc/php/8.1/fpm/php.ini
sudo systemctl restart php${PHP_VER}-fpm
# sudo systemctl stop nginx
# sudo systemctl disable nginx
# Some useful commands
# update-alternatives --set php /usr/bin/php8.1
# update-alternatives --set phar /usr/bin/phar8.1
# update-alternatives --set phar.phar /usr/bin/phar.phar8.1
# update-alternatives --set phpize /usr/bin/phpize8.1
# update-alternatives --set php-config /usr/bin/php-config8.1