Skip to content

Instantly share code, notes, and snippets.

@ndlrx
Created October 18, 2018 02:50
Show Gist options
  • Save ndlrx/1094ecd55477119e389f954e1d7490d0 to your computer and use it in GitHub Desktop.
Save ndlrx/1094ecd55477119e389f954e1d7490d0 to your computer and use it in GitHub Desktop.
LEMP Stack Provision for Vagrant
#!/usr/bin/env bash
echo ""
echo ""
echo "======================================="
echo "| Initializing Vagrant LEMP Setup |"
echo "======================================="
echo ""
# Turnoff interactivemode
export DEBIAN_FRONTEND=noninteractive
# Update Paket
sudo apt update
# Install Nginx
sudo apt install nginx -y
# Install PHP-FPM
sudo apt-get install software-properties-common -y
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
sudo apt install php7.2-mysql php7.2 php7.2-fpm -y
# Install MySQL
echo "mysql-server mysql-server/root_password password root" | debconf-set-selections
echo "mysql-server mysql-server/root_password_again password root" | debconf-set-selections
sudo apt-get install -y mysql-server mysql-client
# Virtual host configuration
sudo mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.asli
sudo cat >> /etc/nginx/sites-available/default <<'EOF'
server {
# Server listening port
listen 80;
# Server domain or IP
server_name localhost;
# Root and index files
root /var/www/html;
index index.php index.html index.htm;
# Urls to attempt
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# Configure PHP FPM
location ~* \.php$ {
fastcgi_pass unix:/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}
# Debugging
access_log /var/log/nginx/localhost_access.log;
error_log /var/log/nginx/localhost_error.log;
rewrite_log on;
}
EOF
# PHPINFO
sudo echo '<?php phpinfo(); ?>' > /var/www/html/info.php
# Add index.html
echo '<h1><center>hakase-ndlr provision LEMP Stack</h1></center>' > /var/www/html/index.html
# Restart service
sudo systemctl restart nginx
sudo systemctl restart php7.2-fpm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment