Last active
August 13, 2025 08:06
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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.4 # Change this to the desired PHP version, e.g., 8.4, 8.3, etc. | |
export NVM_VERSION=0.40.3 # 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)" | |
# Base | |
export LC_CTYPE=fr_FR.UTF-8 \ | |
LC_MESSAGES=fr_FR.UTF-8 \ | |
LC_ALL=fr_FR.UTF-8 | |
sudo apt update | |
sudo apt upgrade -y \ | |
locales-all \ | |
zip \ | |
unzip \ | |
wget \ | |
curl \ | |
net-tools \ | |
htop | |
# Deb sury repository for PHP | |
sudo apt-get update | |
sudo apt-get -y install lsb-release ca-certificates curl | |
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/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list' | |
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}-opcache \ | |
php${PHP_VERSION}-pgsql \ | |
php${PHP_VERSION}-sqlite3 \ | |
php${PHP_VERSION}-xdebug \ | |
php${PHP_VERSION}-zip | |
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 | |
export NVM_DIR="$HOME/.nvm" | |
[ -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