-
-
Save mpociot/1d6809a600701beca4fa544551acd2de to your computer and use it in GitHub Desktop.
/bin/bash -c "$(curl -fsSL https://php.new/install/linux)" | |
export PATH="/root/.config/herd-lite/bin/:$PATH" | |
composer install | |
cp .env.example .env | |
php artisan key:generate | |
php artisan migrate --seed --force -n | |
npm install | |
npm run build |
here is the version with MySQL
IT WORKS
`#!/usr/bin/env bash
this makes the script strict:
-e: exit on any error
-u: error on undefined variables
-o pipefail: exit if any command in a pipeline fails
set -euo pipefail
Adds a package repository that provides the latest PHP versions
(see https://deb.sury.org/ for details)
add-apt-repository -y ppa:ondrej/php
Updates package lists to get the latest information about available packages
apt-get update
Install PHP 8.4 and extensions commonly needed for Symfony applications
apt-get install -y
php8.4
php8.4-cli
php8.4-mbstring
php8.4-xml
php8.4-intl
php8.4-gd
php8.4-zip
php8.4-curl
php8.4-mysql # ✅ Also switch from pgsql to mysql now
This makes PHP 8.4 available through the global 'php' binary,
which is expected by many commands
update-alternatives --install /usr/bin/php php /usr/bin/php8.4 84
update-alternatives --set php /usr/bin/php8.4
Install Composer as a global 'composer' binary following the safest practices
EXPECTED_CHECKSUM="$(curl -fsSL https://composer.github.io/installer.sig)"
curl -fsSL https://getcomposer.org/installer -o composer-setup.php
ACTUAL_CHECKSUM="$(sha384sum composer-setup.php | cut -d ' ' -f 1)"
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]; then
echo 'ERROR: Invalid composer installer checksum.' >&2
rm composer-setup.php
exit 1
fi
php composer-setup.php --install-dir=/usr/local/bin --filename=composer --quiet
rm composer-setup.php
Install the PHP dependencies of your project;
private packages require some more work explained later in this article
composer install --ignore-platform-req=ext-bcmath
Show installed versions to check if everything worked
php -v
composer --version
Load Laravel-style environment variables
DB_DATABASE="${DB_DATABASE:-mydb}"
DB_USERNAME="${DB_USERNAME:-myuser}"
DB_PASSWORD="${DB_PASSWORD:-mypassword}"
Default MySQL root password (optional, can be customized)
MYSQL_ROOT_PASSWORD="${MYSQL_ROOT_PASSWORD:-root}"
apt-get install -y mysql-client mysql-common mysql-server-core-8.0
mkdir -p /tmp/mysql-data
mysqld --initialize-insecure --datadir=/tmp/mysql-data
Fix for secure-file-priv error
mkdir -p /var/lib/mysql-files
Start MySQL manually
nohup mysqld --user=root --datadir=/tmp/mysql-data --socket=/tmp/mysql.sock > /tmp/mysql.log 2>&1 &
Wait for socket
echo "Waiting for MySQL to be ready..."
for i in {30..0}; do
if [ -S /tmp/mysql.sock ]; then
echo "✅ MySQL socket is ready"
break
fi
sleep 1
done
if ! [ -S /tmp/mysql.sock ]; then
echo "❌ MySQL failed to start"
tail -n 50 /tmp/mysql.log || true
exit 1
fi
Setup user/db
mysql -u root --socket=/tmp/mysql.sock <<-EOSQL
CREATE DATABASE IF NOT EXISTS `${DB_DATABASE}`;
CREATE USER IF NOT EXISTS '${DB_USERNAME}'@'localhost' IDENTIFIED BY '${DB_PASSWORD}';
GRANT ALL PRIVILEGES ON `${DB_DATABASE}`.* TO '${DB_USERNAME}'@'localhost';
FLUSH PRIVILEGES;
EOSQL
Show installed MySQL version
mysql --version
cp .env.example .env
php artisan key:generate
php artisan migrate --seed --force -n
npm install --no-save
npm run build`
Thanks for this script. How do you deal with the DB? I'm not managing to get mysql nor sqlite working out of the box on codex. Did you add a special feature somewhere else?
Additionally, why
npm install
and notnpm install --no-save
(which would avoid merging problems, no?) and whycomposer install
and notcomposer install --no-interaction --prefer-dist --optimize-autoloader
(which has less chance in getting blocked)? Just asking to learn and to see whether it can be improved.