From 14c65580fc10f1c624eb4c1193de90b97b3edef3 Mon Sep 17 00:00:00 2001 From: Sophia Atkinson Date: Fri, 31 Mar 2023 18:39:13 -0700 Subject: [PATCH] PMA nginx conf --- conf/pmaapache.conf | 20 ++++++++++++ conf/pmanginx.conf | 17 +++++++++++ scripts/caddyinstall.sh | 49 ++++++++++++++++++++++++++++++ scripts/giteaupdate.sh | 2 +- scripts/pmainstall.sh | 67 +++++++++++++++++++++++------------------ 5 files changed, 125 insertions(+), 30 deletions(-) create mode 100644 conf/pmaapache.conf create mode 100644 conf/pmanginx.conf create mode 100644 scripts/caddyinstall.sh diff --git a/conf/pmaapache.conf b/conf/pmaapache.conf new file mode 100644 index 0000000..9593f44 --- /dev/null +++ b/conf/pmaapache.conf @@ -0,0 +1,20 @@ +Listen 8080 + + + + ServerName localhost + + + AllowOverride None + Require all granted + + + DocumentRoot /usr/share/phpmyadmin + + Include /etc/phpmyadmin/apache.conf + + ErrorLog ${APACHE_LOG_DIR}/phpmyadmin.error.log + CustomLog ${APACHE_LOG_DIR}/phpmyadmin.access.log combined + + + \ No newline at end of file diff --git a/conf/pmanginx.conf b/conf/pmanginx.conf new file mode 100644 index 0000000..3da5222 --- /dev/null +++ b/conf/pmanginx.conf @@ -0,0 +1,17 @@ +server { +listen 8080; +listen [::]:8080; +server_name localhost; +access_log /var/log/nginx/phpmyadmin.vhost.access.log; +error_log /var/log/nginx/phpmyadmin.vhost.error.log; +root /usr/share/phpmyadmin; +index index.php; +location ~ \.php$ { + try_files $uri =404; + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass unix:/var/run/php/php8.2-fpm.sock; + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + include fastcgi_params; + } +} \ No newline at end of file diff --git a/scripts/caddyinstall.sh b/scripts/caddyinstall.sh new file mode 100644 index 0000000..e1320dc --- /dev/null +++ b/scripts/caddyinstall.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +while true +do + read -r -p "Would you like to install Caddy Server? [Y/n] " input + + case $input in + [yY][eE][sS]|[yY]) + break + ;; + [nN][oO]|[nN]) + break + ;; + *) + echo "That wasn't an option..." + ;; + esac +done +caddy_ver="0.3.2" +apt install golang git curl -y +cd /tmp +wget https://github.com/caddyserver/xcaddy/releases/download/v"$caddy_ver"/xcaddy_"$caddy_ver"_linux_amd64.tar.gz +tar xvf xcaddy_"$caddy_ver"_linux_amd64.tar.gz xcaddy +sudo mv xcaddy /usr/bin +mkdir ~/caddy +cd ~/caddy +xcaddy build +sudo mv caddy /usr/bin +sudo groupadd --system caddy +sudo useradd --system \ + --gid caddy \ + --create-home \ + --home-dir /var/lib/caddy \ + --shell /usr/sbin/nologin \ + --comment "Caddy web server" \ + caddy +sudo chown root:root /usr/bin/caddy +sudo chmod 755 /usr/bin/caddy +sudo mkdir /etc/caddy +sudo chown -R root:caddy /etc/caddy +sudo mkdir /etc/ssl/caddy +sudo chown -R root:caddy /etc/ssl/caddy +sudo chmod 0770 /etc/ssl/caddy +sudo mkdir /var/www +sudo chown caddy:caddy /var/www +sudo sh -c 'curl https://raw.githubusercontent.com/caddyserver/dist/master/init/caddy.service > /etc/systemd/system/caddy.service' +sudo systemctl daemon-reload +sudo systemctl status caddy +sudo ufw allow proto tcp from any to any port 80,443 \ No newline at end of file diff --git a/scripts/giteaupdate.sh b/scripts/giteaupdate.sh index 746181f..e59da3f 100644 --- a/scripts/giteaupdate.sh +++ b/scripts/giteaupdate.sh @@ -20,7 +20,7 @@ ping -c1 "github.com" &>"/dev/null" if [[ "${?}" -ne 0 ]]; then echo "I am unable to access Github.com, that is needed to continue this Install." elif [[ "${#args[@]}" -eq 0 ]]; then -GITEA_VER="1.19.0" +GITEA_VER="1.18.5" sudo systemctl stop gitea sudo wget -O /usr/local/bin/gitea https://github.com/go-gitea/gitea/releases/download/v"$GITEA_VER"/gitea-"$GITEA_VER"-linux-amd64 sudo chmod +x /usr/local/bin/gitea diff --git a/scripts/pmainstall.sh b/scripts/pmainstall.sh index ff742b4..793a3ee 100644 --- a/scripts/pmainstall.sh +++ b/scripts/pmainstall.sh @@ -16,31 +16,47 @@ do ;; esac done +while [ "$go" != 'apache' ] && [ "$go" != 'nginx' ]; do + read -p "Would you like to install using Nginx or Apache? (nginx/apache)" go +done +if [ "$go" == 'nginx' ]; then PHP_VER="8.2" sudo apt update && apt upgrade -y -sudo add-apt-repository --yes ppa:ondrej/php && apt install libapache2-mod-php$PHP_VER php$PHP_VER-fpm software-properties-common phpmyadmin php-mbstring php-zip php-gd php-json php-curl apache2 -y +sudo apt install software-properties-common -y && sudo add-apt-repository --yes ppa:ondrej/nginx-mainline && sudo apt install php$PHP_VER-fpm software-properties-common phpmyadmin php-mbstring php-zip php-gd php-json php-curl nginx -y +sudo systemctl stop nginx +sudo apt remove php8.1-fpm php8.1-* -y +sudo wget -O /etc/nginx/conf.d/phpmyadmin.conf https://git.oldgate.org/Sophia/thelinuxlist/raw/branch/main/conf/pmanginx.conf +sudo systemctl enable nginx +sudo systemctl start nginx +## Updating phpMyAdmin. +PMA_VER="5.2.1" +sudo rm -rf /usr/share/phpmyadmin.bak +sudo mv /usr/share/phpmyadmin/ /usr/share/phpmyadmin.bak +sudo mkdir /usr/share/phpmyadmin/ +sudo wget https://files.phpmyadmin.net/phpMyAdmin/$PMA_VER/phpMyAdmin-"$PMA_VER"-all-languages.tar.gz -P /usr/share/phpmyadmin/ +sudo tar xzf /usr/share/phpmyadmin/phpMyAdmin-"$PMA_VER"-all-languages.tar.gz -C /usr/share/phpmyadmin/ +sudo mv /usr/share/phpmyadmin/phpMyAdmin-"$PMA_VER"-all-languages/* /usr/share/phpmyadmin +sudo mkdir /usr/share/phpmyadmin/tmp/ && chmod -R 777 /usr/share/phpmyadmin/tmp/ +sudo rm -rf /usr/share/phpmyadmin/phpMyAdmin-"$PMA_VER"-all-languages /usr/share/phpmyadmin/phpMyAdmin-"$PMA_VER"-all-languages.tar.gz +## Thanks https://stackoverflow.com/users/3266847/benjamin-w +randomBlowfishSecret=$(openssl rand -base64 22) +sudo sed -e "s|cfg\['blowfish_secret'\] = ''|cfg['blowfish_secret'] = '$randomBlowfishSecret'|" /usr/share/phpmyadmin/config.sample.inc.php > /usr/share/phpmyadmin/config.inc.php +sudo systemctl restart nginx +sudo ufw allow 8080 +echo -e "==================================================================" +publicipaddress=$(curl -sS --connect-timeout 10 -m 60 https://ipv4.icanhazip.com/ || curl -sS --connect-timeout 10 -m 60 https://api.ipify.org ) +intenalip=$(ip addr | grep -E -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | grep -E -v "^127\.|^255\.|^0\." | head -n 1) + echo "phpMyAdmin Should be available at http://${intenalip}:8080" + echo "Or If you are using a VPS at http://${publicipaddress}:8080" +echo -e "==================================================================" +fi +if [ "$go" == 'apache' ]; then +PHP_VER="8.2" +sudo apt update && apt upgrade -y +sudo add-apt-repository --yes ppa:ondrej/apache2 && apt install libapache2-mod-php$PHP_VER php$PHP_VER-fpm software-properties-common phpmyadmin php-mbstring php-zip php-gd php-json php-curl apache2 -y sudo systemctl stop apache2 sudo apt remove php8.1-fpm php8.1-* -y -sudo echo " -Listen 8080 - - - - ServerName localhost - - - AllowOverride None - Require all granted - - - DocumentRoot /usr/share/phpmyadmin - - Include /etc/phpmyadmin/apache.conf - - ErrorLog ${APACHE_LOG_DIR}/phpmyadmin.error.log - CustomLog ${APACHE_LOG_DIR}/phpmyadmin.access.log combined - -" >> /etc/apache2/sites-enabled/phpmyadmin.conf +sudo wget -O /etc/apache2/sites-enabled/phpmyadmin.conf https://git.oldgate.org/Sophia/thelinuxlist/raw/branch/main/conf/pmaapache.conf sudo phpenmod mbstring sudo a2dismod php$PHP_VER sudo a2dismod mpm_prefork @@ -72,11 +88,4 @@ intenalip=$(ip addr | grep -E -o '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} echo "phpMyAdmin Should be available at http://${intenalip}:8080" echo "Or If you are using a VPS at http://${publicipaddress}:8080" echo -e "==================================================================" - - - - - - - - +fi