Last active
July 15, 2025 18:55
-
-
Save wagura-maurice/fe8a0448c25ee2b96e685318fc816624 to your computer and use it in GitHub Desktop.
Laravel Dev Stack Setup Script
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 | |
| # 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" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Download the script
wget https://gist.githubusercontent.com/wagura-maurice/fe8a0448c25ee2b96e685318fc816624/raw/57838acab1f2822efa1e38c5574af70f0805217c/DevOps.sh
Make it executable
chmod +x ./DevOps.sh
Run it
./DevOps.sh