Skip to content

Instantly share code, notes, and snippets.

@wagura-maurice
Last active July 15, 2025 18:55
Show Gist options
  • Select an option

  • Save wagura-maurice/fe8a0448c25ee2b96e685318fc816624 to your computer and use it in GitHub Desktop.

Select an option

Save wagura-maurice/fe8a0448c25ee2b96e685318fc816624 to your computer and use it in GitHub Desktop.
Laravel Dev Stack Setup Script
#!/bin/bash
# 2. Create and lock /etc/resolv.conf early to avoid chattr error
if [ ! -f /etc/resolv.conf ]; then
echo "πŸ“„ Creating /etc/resolv.conf..."
touch /etc/resolv.conf
fi
if lsattr /etc/resolv.conf | grep -qv 'i'; then
echo "πŸ”’ Locking /etc/resolv.conf with chattr..."
chattr +i /etc/resolv.conf
fi
# 3. Update and upgrade the system
echo "πŸ”§ Updating system packages..."
apt update && apt upgrade -y
# 4. Install essential utilities
echo "πŸ“¦ Installing base utilities..."
apt install -y curl wget git unzip lsb-release apt-transport-https ca-certificates \
software-properties-common gnupg dnsmasq inotify-tools
# 5. Install MySQL if not installed
if ! command -v mysql >/dev/null 2>&1; then
echo "🐬 Installing MySQL..."
wget https://dev.mysql.com/get/mysql-apt-config_0.8.30-1_all.deb
dpkg -i mysql-apt-config_0.8.30-1_all.deb
apt update
apt install -y mysql-server
systemctl enable mysql
systemctl start mysql
else
echo "βœ… MySQL already installed"
fi
# 6. Add PHP repository and install PHP 8.4 and extensions
echo "🐘 Installing PHP 8.4 and extensions..."
add-apt-repository ppa:ondrej/php -y && apt update
apt install -y \
php8.4 php8.4-cli php8.4-fpm php8.4-dev \
php8.4-pgsql php8.4-sqlite3 php8.4-mysql php8.4-imap \
php8.4-gd php8.4-curl php8.4-mbstring php8.4-xml php8.4-zip \
php8.4-bcmath php8.4-soap php8.4-intl php8.4-readline \
php8.4-gmp php8.4-redis php8.4-memcached php8.4-msgpack php8.4-igbinary \
php8.4-imagick php-pear php-dev libmagickwand-dev
# 7. Install Composer if not already installed
if ! command -v composer >/dev/null 2>&1; then
echo "πŸ“¦ Installing Composer..."
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
else
echo "βœ… Composer already installed"
fi
# 8. Ensure Composer global bin path is in ~/.bashrc
COMPOSER_BIN="$HOME/.config/composer/vendor/bin"
if ! grep -q "$COMPOSER_BIN" ~/.bashrc; then
echo "πŸ”§ Adding Composer global bin path to ~/.bashrc..."
echo "export PATH=\"\$PATH:$COMPOSER_BIN\"" >> ~/.bashrc
export PATH="$PATH:$COMPOSER_BIN"
else
echo "βœ… Composer bin path already in ~/.bashrc"
fi
# 9. Install and enable Nginx
echo "🌐 Installing Nginx..."
apt install -y nginx
systemctl enable nginx
systemctl start nginx
# 10. Install Node.js and npm
if ! command -v node >/dev/null 2>&1; then
echo "🟒 Installing Node.js and npm..."
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt install -y nodejs
else
echo "βœ… Node.js already installed"
fi
# 11. Install Laravel installer globally
echo "πŸ“₯ Installing Laravel Installer..."
composer global require laravel/installer
# 12. Install Valet Linux and setup
echo "πŸ§ͺ Installing Valet Linux..."
composer global require cpriego/valet-linux --with-all-dependencies
valet install
valet domain devops
valet park /var/www/html
# 13. Completion Message
echo "βœ… Laravel Dev Stack installed successfully!"
echo "πŸ“ Project directory: /var/www/html"
echo "πŸ“Œ To create a new Laravel project:"
echo " cd /var/www/html && laravel new your-project-name"
echo "🌐 Access it at: http://your-project-name.devops"
@wagura-maurice
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment