A bash script that automates PHP and Node.js version configuration for shared hosting environments.
Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.2". You are running 7.4.32.
Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0"
npm WARN EBADENGINE Unsupported engine { package: 'vite@6.2.5', required: { node: '^18.0.0 || ^20.0.0 || >=22.0.0' }, current: { node: 'v16.20.2' } }
sh: line 1: /home/user/project/node_modules/.bin/vite: Permission denied
npm ERR! engine Unsupported engine for laravel-vite-plugin@1.2.0: wanted: {"node":"^18.0.0 || ^20.0.0 || >=22.0.0"} (current: {"node":"16.20.2"})
- Upload
server-env-setup.shto your server's home directory - Make it executable:
chmod +x server-env-setup.sh - Run the script:
./server-env-setup.sh
- Creates symlinks to specify PHP versions for CLI usage
- Configures aliases as fallback method
- Supports PHP versions 5.6 through 8.3
- Automatically sets up Composer to use the correct PHP version
- Installs Node Version Manager (NVM) if not present
- Downloads and configures specified Node.js version (18, 20, or 22)
- Sets the chosen version as default
- Updates shell configuration automatically
- Resolves common
node_modules/.binpermission issues - Configures npm cache permissions
- Fixes executable permissions for build tools
The script provides an interactive menu with these options:
- Configure PHP version only
- Install Node.js only
- Fix permissions only
- Complete setup (all three)
- Exit
After running the script:
- Restart your SSH session, or
- Run
source ~/.bashrcto apply changes - For terminal users: open a new terminal window
Note: The script automatically verifies the installation and displays version information.
- Bash shell environment
- Internet connection for downloading Node.js
- Write permissions to home directory
- Access to PHP binaries on the server
# Make sure the script has execute permissions
chmod +x server-env-setup.sh
# Check if bash is available
which bash# Manually source the configuration
source ~/.bashrc
# Check if symlinks were created
ls -la ~/bin/# Check if NVM was installed correctly
command -v nvm
# Manually load NVM
source ~/.nvm/nvm.shIf you prefer to configure manually, here are the key steps the script performs:
# Create bin directory
mkdir -p ~/bin
# Create PHP symlink (example for PHP 8.1)
ln -sf /usr/local/bin/php81 ~/bin/php
# Add to PATH in ~/.bashrc
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc# Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash
# Install and use Node.js
nvm install 18
nvm use 18
nvm alias default 18If you encounter any issues:
- Check the error messages displayed by the script
- Ensure you have the necessary permissions
- Verify your hosting provider supports the PHP/Node.js versions you're trying to use
- Contact your hosting provider for server-specific PHP binary locations