Skip to content

Instantly share code, notes, and snippets.

@Pierstoval
Last active March 31, 2026 07:56
Show Gist options
  • Select an option

  • Save Pierstoval/2372ae4634322916608c4dcafe8ccfc6 to your computer and use it in GitHub Desktop.

Select an option

Save Pierstoval/2372ae4634322916608c4dcafe8ccfc6 to your computer and use it in GitHub Desktop.
Small script to initiate a server, like from a Docker container, or a VPS
#!/bin/bash
# Pre-requisites: sudo, curl
#
# This script is meant to be run on a fresh Debian 12 (Bookworm) installation
# It will install the latest PHP version, MariaDB, Node.js, NVM, and Caddy
# It also sets up some basic configurations and installs the Symfony CLI
# Usage: Run this script as root or with sudo privileges
# Note:
# You can run the script by just copy-pasting this command:
# curl -sSL https://gist.githubusercontent.com/Pierstoval/2372ae4634322916608c4dcafe8ccfc6/raw/Debian_starter.bash | bash
# ⚠ Only do this if you trust your network and understand what the script does!
export PHP_VERSION=8.5 # Change this to the desired PHP version, e.g., 8.4, 8.3, etc.
export NVM_VERSION=0.40.4 # You can find latest version at https://github.com/nvm-sh/nvm
# Feel free to change this to a custom password of yours,
# this command generates a 25-characters long password,
# so you could store it in secrets or a password manager.
# In case you still want to use the root password,
# it will be stored in $HOME/.dbpwd
export MARIADB_ROOT_PASSWORD="$(tr -dc A-Za-z0-9_ < /dev/urandom | head -c 25 | xargs)"
# Other vars
export LANG=fr_FR.UTF-8
export LC_CTYPE=$LANG \
LC_MESSAGES=$LANG \
LC_ALL=$LANG
export OSFILE=$(for f in /etc/os-release /etc/lsb-release /etc/redhat-release; do [ -f "$f" ] && echo "$f" && break; done)
if [[ -z $OSFILE ]]; then echo "Cannot find OS release file. Stopping script" ; exit 1 ; fi
export OSCODE=$(. $OSFILE && echo "${UBUNTU_CODENAME:-${DEBIAN_CODENAME:-$VERSION_CODENAME}}")
export OSFAMILY=$(. $OSFILE && echo "${ID}")
export NVM_DIR="$HOME/.nvm"
# Stop on any error.
set -e
# Base
sudo apt update
sudo apt upgrade -y \
locales-all \
zip \
unzip \
wget \
curl \
net-tools \
libnss3-tools \
vim \
htop
# Deb sury repository for PHP
sudo apt-get update
sudo apt-get -y install lsb-release ca-certificates curl
if command -v add-apt-repository >/dev/null 2>&1
then
sudo add-apt-repository ppa:ondrej/php
else
if [[ $OSFAMILY == 'ubuntu' ]]; then
sudo sh -c "echo \"\" > /etc/apt/sources.list.d/php.list"
sudo sh -c "echo \"deb https://ppa.launchpadcontent.net/ondrej/php/ubuntu $OSCODE main \" >> /etc/apt/sources.list.d/php.list"
sudo sh -c "echo \"deb-src https://ppa.launchpadcontent.net/ondrej/php/ubuntu $OSCODE main \" >> /etc/apt/sources.list.d/php.list"
else
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/debsuryorg-archive-keyring.gpg] https://packages.sury.org/php/ $OSCODE main\" > /etc/apt/sources.list.d/php.list"
fi
fi
sudo apt-get update
# PHP
sudo apt install -y \
php${PHP_VERSION}-apcu \
php${PHP_VERSION}-cli \
php${PHP_VERSION}-curl \
php${PHP_VERSION}-fpm \
php${PHP_VERSION}-gd \
php${PHP_VERSION}-intl \
php${PHP_VERSION}-mbstring \
php${PHP_VERSION}-mysql \
php${PHP_VERSION}-pgsql \
php${PHP_VERSION}-sqlite3 \
php${PHP_VERSION}-xdebug \
php${PHP_VERSION}-xml \
php${PHP_VERSION}-zip
# These extensions are built-in certain PHP versions, so failing is ok on these packages.
sudo apt install -y \
php${PHP_VERSION}-json \
php${PHP_VERSION}-opcache \
|| true
sudo sed -i "s/www-data/$(whoami)/g" /etc/php/${PHP_VERSION}/fpm/pool.d/www.conf
cat >> $HOME/custom-php-ini-file.ini<< EOF
allow_url_include = off
assert.active = on
date.timezone = UTC
max_execution_time = 180
memory_limit = 1024M
phar.readonly = off
post_max_size = 100M
precision = 17
realpath_cache_size = 4M
realpath_cache_ttl = 3600
serialize_precision = -1
session.use_strict_mode = On
short_open_tag = off
upload_max_filesize = 100M
zend.detect_unicode = Off
[assert]
zend_assertions = 1
assert.exception = 1
[apcu]
apc.enable_cli = 1
apc.enabled = 1
apc.shm_size = 128M
apc.ttl = 7200
[errors]
display_errors = On
display_startup_errors = off
error_reporting = E_ALL & ~E_DEPRECATED
[opcache]
opcache.enable = 1
opcache.enable_cli = 1
opcache.max_accelerated_files = 50000
[xdebug]
; Enable only if you need it, otherwise it will slow down your PHP setup
xdebug.mode = off
EOF
sudo cp $HOME/custom-php-ini-file.ini /etc/php/${PHP_VERSION}/fpm/conf.d/99-custom.ini
sudo cp $HOME/custom-php-ini-file.ini /etc/php/${PHP_VERSION}/cli/conf.d/99-custom.ini
rm $HOME/custom-php-ini-file.ini
# Symfony CLI for dev (and convenience sometimes)
wget https://get.symfony.com/cli/installer -O - | bash
sudo cp $HOME/.symfony5/bin/symfony /usr/local/bin/symfony
# Database
sudo apt install -y mariadb-server mariadb-client
sudo systemctl stop mariadb
sudo mariadbd-safe --skip-grant-tables --skip-networking &
mariadb -uroot -e "FLUSH PRIVILEGES ; ALTER USER 'root'@'localhost' IDENTIFIED BY '${MARIADB_ROOT_PASSWORD}';"
sudo kill `sudo cat /var/run/mysqld/mysqld.pid`
sudo systemctl start mariadb
mysql -uroot -p"${MARIADB_ROOT_PASSWORD}" -e 'SELECT "it works!";'
echo "${MARIADB_ROOT_PASSWORD}" > $HOME/.dbpwd
# Nodejs
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v$NVM_VERSION/install.sh | bash
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
# Caddy, just in case
sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list
sudo apt update
sudo apt install -y caddy
sudo mkdir -p /var/www/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment