install-nginx.sh
· 2.0 KiB · Bash
Raw
#!/bin/bash
# This will be a basic script for installing Nginx, Mariadb, and php.
# Mostly created with a few guides and my knowledge of this stuff.
# Set these to true depending on if installing all of them.
# By default, these are set to false.
INSTALL_NGINX=false
INSTALL_PHP=false
INSTALL_MARIADB=false
# Set the php version here, on Ubuntu Server 24 the latest is 8.3
# Using php 8.5 from the PHP PPA.
PHP_VERSION=8.5
# Setup to use the Ondrej PHP PPA from here
# https://php.watch/articles/php-84-install-upgrade-guide-debian-ubuntu
# Adding the PPA for Ubuntu Server:
# sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
# sudo apt update
# Adding the PPA for Debian (Some of these packages may already be installed):
# sudo apt-get update
# sudo apt-get -y install lsb-release ca-certificates curl apt-transport-https
# sudo curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
# sudo dpkg -i /tmp/debsuryorg-archive-keyring.deb
# sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
# sudo apt-get update
# First, check if user is root.
# https://stackoverflow.com/questions/18215973/how-to-check-if-running-as-root-in-a-bash-script
if [ "$EUID" -ne 0 ]; then
echo "This script requires root."
exit 1
fi
# Install nginx
if [ "$INSTALL_NGINX" = true ]; then
apt install nginx -y
fi
# Removed
# php$PHP_VERSION-json \
# https://stackoverflow.com/a/40816033
if [ "$INSTALL_PHP" = true ]; then
apt install \
php$PHP_VERSION-bcmath \
php$PHP_VERSION-bz2 \
php$PHP_VERSION-cli \
php$PHP_VERSION-common \
php$PHP_VERSION-curl \
php$PHP_VERSION-dev \
php$PHP_VERSION-fpm \
php$PHP_VERSION-gd \
php$PHP_VERSION-mbstring \
php$PHP_VERSION-mcrypt \
php$PHP_VERSION-mysql \
php$PHP_VERSION-sqlite3 \
php$PHP_VERSION-tokenizer \
php$PHP_VERSION-xml \
php$PHP_VERSION-zip -y
fi
if [ "$INSTALL_MARIADB" = true ]; then
apt install mariadb-server -y
fi
| 1 | #!/bin/bash |
| 2 | # This will be a basic script for installing Nginx, Mariadb, and php. |
| 3 | # Mostly created with a few guides and my knowledge of this stuff. |
| 4 | |
| 5 | # Set these to true depending on if installing all of them. |
| 6 | # By default, these are set to false. |
| 7 | INSTALL_NGINX=false |
| 8 | INSTALL_PHP=false |
| 9 | INSTALL_MARIADB=false |
| 10 | # Set the php version here, on Ubuntu Server 24 the latest is 8.3 |
| 11 | # Using php 8.5 from the PHP PPA. |
| 12 | PHP_VERSION=8.5 |
| 13 | |
| 14 | # Setup to use the Ondrej PHP PPA from here |
| 15 | # https://php.watch/articles/php-84-install-upgrade-guide-debian-ubuntu |
| 16 | |
| 17 | # Adding the PPA for Ubuntu Server: |
| 18 | # sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php |
| 19 | # sudo apt update |
| 20 | |
| 21 | # Adding the PPA for Debian (Some of these packages may already be installed): |
| 22 | # sudo apt-get update |
| 23 | # sudo apt-get -y install lsb-release ca-certificates curl apt-transport-https |
| 24 | # sudo curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb |
| 25 | # sudo dpkg -i /tmp/debsuryorg-archive-keyring.deb |
| 26 | # sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' |
| 27 | # sudo apt-get update |
| 28 | |
| 29 | # First, check if user is root. |
| 30 | # https://stackoverflow.com/questions/18215973/how-to-check-if-running-as-root-in-a-bash-script |
| 31 | if [ "$EUID" -ne 0 ]; then |
| 32 | echo "This script requires root." |
| 33 | exit 1 |
| 34 | fi |
| 35 | |
| 36 | # Install nginx |
| 37 | if [ "$INSTALL_NGINX" = true ]; then |
| 38 | apt install nginx -y |
| 39 | fi |
| 40 | |
| 41 | # Removed |
| 42 | # php$PHP_VERSION-json \ |
| 43 | |
| 44 | # https://stackoverflow.com/a/40816033 |
| 45 | if [ "$INSTALL_PHP" = true ]; then |
| 46 | apt install \ |
| 47 | php$PHP_VERSION-bcmath \ |
| 48 | php$PHP_VERSION-bz2 \ |
| 49 | php$PHP_VERSION-cli \ |
| 50 | php$PHP_VERSION-common \ |
| 51 | php$PHP_VERSION-curl \ |
| 52 | php$PHP_VERSION-dev \ |
| 53 | php$PHP_VERSION-fpm \ |
| 54 | php$PHP_VERSION-gd \ |
| 55 | php$PHP_VERSION-mbstring \ |
| 56 | php$PHP_VERSION-mcrypt \ |
| 57 | php$PHP_VERSION-mysql \ |
| 58 | php$PHP_VERSION-sqlite3 \ |
| 59 | php$PHP_VERSION-tokenizer \ |
| 60 | php$PHP_VERSION-xml \ |
| 61 | php$PHP_VERSION-zip -y |
| 62 | fi |
| 63 | |
| 64 | if [ "$INSTALL_MARIADB" = true ]; then |
| 65 | apt install mariadb-server -y |
| 66 | fi |