Sure! Here’s a Bash script that automates the installation of Snipe-IT on an Ubuntu Server. This script sets up:
- Apache
- MySQL/MariaDB
- PHP
- Composer
- Git
- Snipe-IT with necessary permissions and configuration
Let’s assume Ubuntu 20.04+ and a fresh server.
✅ Script: install_snipeit.sh
bash#!/bin/bash
# Exit on any error
set -e
# Define MySQL root password and Snipe-IT DB info
MYSQL_ROOT_PASSWORD="StrongRootPass123!"
SNIPEIT_DB="snipeit"
SNIPEIT_USER="snipeuser"
SNIPEIT_PASS="SnipeUserPass456!"
echo "Updating system..."
apt update && apt upgrade -y
echo "Installing required packages..."
apt install -y apache2 mariadb-server php php-mysql php-curl php-gd php-mbstring php-xml php-bcmath php-zip php-tokenizer unzip git curl composer
echo "Starting and securing MySQL..."
systemctl enable mariadb
systemctl start mariadb
mysql -u root <<MYSQL_SCRIPT
ALTER USER 'root'@'localhost' IDENTIFIED BY '${MYSQL_ROOT_PASSWORD}';
FLUSH PRIVILEGES;
CREATE DATABASE ${SNIPEIT_DB};
CREATE USER '${SNIPEIT_USER}'@'localhost' IDENTIFIED BY '${SNIPEIT_PASS}';
GRANT ALL PRIVILEGES ON ${SNIPEIT_DB}.* TO '${SNIPEIT_USER}'@'localhost';
FLUSH PRIVILEGES;
MYSQL_SCRIPT
echo "Cloning Snipe-IT..."
mkdir -p /var/www
cd /var/www
git clone https://github.com/snipe/snipe-it snipeit
cd snipeit
cp .env.example .env
echo "Configuring .env..."
sed -i "s/DB_DATABASE=homestead/DB_DATABASE=${SNIPEIT_DB}/" .env
sed -i "s/DB_USERNAME=homestead/DB_USERNAME=${SNIPEIT_USER}/" .env
sed -i "s/DB_PASSWORD=secret/DB_PASSWORD=${SNIPEIT_PASS}/" .env
echo "Running composer install..."
composer install --no-dev --prefer-source
echo "Setting permissions..."
chown -R www-data:www-data /var/www/snipeit
chmod -R 755 /var/www/snipeit
echo "Generating app key..."
php artisan key:generate
echo "Creating Apache config..."
cat <<EOF > /etc/apache2/sites-available/snipeit.conf
<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/snipeit/public
<Directory /var/www/snipeit/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog \${APACHE_LOG_DIR}/snipeit_error.log
CustomLog \${APACHE_LOG_DIR}/snipeit_access.log combined
</VirtualHost>
EOF
echo "Enabling Apache config..."
a2enmod rewrite
a2ensite snipeit
a2dissite 000-default
systemctl reload apache2
echo "Snipe-IT installation completed!"
echo "Access it at: http://<your-server-ip>/"
📝 Usage Instructions
- Save this script: bash
nano install_snipeit.sh
- Paste the code, save, and make executable: bashCopyEdit
chmod +x install_snipeit.sh
- Run it: bashCopyEdit
sudo ./install_snipeit.sh
🔐 Security Tips
- Change passwords (
MYSQL_ROOT_PASSWORD
,SNIPEIT_PASS
) before running. - Optionally secure MariaDB (
mysql_secure_installation
). - Consider using HTTPS via Let’s Encrypt.