Sitedigital

by darioma072019
10 deployments · 10 still active · last rev. 2 months ago

Instalar un nuevo servico

Compatible with: Debian 9
						#!/bin/bash

# <UDF name="dbpassword" Label="MySQL Password" example="s3cure_p4ssw0rd" />

# Set hostname
HOSTNAME=$(hostname)
FQDN=$(hostname -f)
IPV4=$(hostname -I | cut -d ' ' -f 1)
IPV6=$(hostname -I | cut -d ' ' -f 2)
hostnamectl set-hostname $HOSTNAME
echo "${IPV4} ${FQDN} ${HOSTNAME}" >> /etc/hosts
echo "${IPV6} ${FQDN} ${HOSTNAME}" >> /etc/hosts

# Update system
export DEBIAN_FRONTEND=noninteractive
apt-get update
apt-get upgrade -y

# Install/configure UFW
apt-get install -y ufw
ufw default allow outgoing
ufw default deny incoming
ufw allow ssh
systemctl start ufw
systemctl enable ufw

# Install/configure MySQL
apt-get install -y mysql-server
systemctl start mariadb
systemctl enable mariadb
mysql_secure_installation <<EOF

y
$DBPASSWORD
$DBPASSWORD
y
y
y
y
EOF

# Install Apache
apt-get install -y apache2

# Install PHP
apt-get install -y php php-mysql

# Configure Apache
ufw allow http
ufw allow https
rm /var/www/html/index.html
cat > /var/www/html/index.php <<EOF
<?php phpinfo(); ?>
EOF
systemctl start apache2
systemctl enable apache2

#check for composer installation
if ! type "composer" > /dev/null; then
  	echo -e "${RED}You don't have Composer installed.${NC}"

  	echo "Do you want to install composer?"
	select yn in "Yes" "No"; do
	    case $yn in
	        Yes ) 
				echo -e "${GREEN}Installing Composer...${NC}"

				php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
				php -r "if (hash_file('SHA384', 'composer-setup.php') === 'e115a8dc7871f15d853148a7fbac7da27d6c0030b848d9b3dc09e2a0388afed865e6a3d6b3c0fad45c48e2b5fc1196ae') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
				php composer-setup.php
				php -r "unlink('composer-setup.php');"
				mv composer.phar /usr/local/bin/composer
			break;;
	        No ) 
				echo -e "${RED}You need to install composer to proceed.${NC}"
			exit 1;;
	    esac
	done
fi


echo -n "Enter a project name: "
read project_name


# if a project name given then work on that otherwise prompt to give a project name
if [ "$project_name" == "" ]; then
	echo -e "${RED}Please give a project name.${NC}"
else
	cd /var/www/html
	composer create-project --prefer-dist laravel/laravel $project_name
	#apache user group permission 
	chown -R www-data.www-data /var/www/$project_name 
	chmod -R 755 /var/www/$project_name
	cd $project_name
	chmod -R 775 storage
	chmod -R 775 bootstrap/cache	
	echo -e "${GREEN}Everything is ready, mate! Create something awesome!${NC}"
fi


#TODO
# laravel version selection when creating
# linux other distros support
# virtual host creation

# Cleanup
rm /root/StackScript
echo "Installation complete!"