Skip to content

Instantly share code, notes, and snippets.

@dannygsmith
Last active November 18, 2017 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dannygsmith/6bbd7c3a90fb66cc6d0e996c4c66726f to your computer and use it in GitHub Desktop.
Save dannygsmith/6bbd7c3a90fb66cc6d0e996c4c66726f to your computer and use it in GitHub Desktop.
Script to install Laravel Valet by first checking for any other web stacks
#!/usr/bin/env bash
#styles
VP_NONE='\033[00m'
VP_RED='\033[01;31m'
VP_GREEN='\033[01;32m'
VP_YELLOW='\033[01;33m'
VP_PURPLE='\033[01;35m'
VP_CYAN='\033[01;36m'
VP_WHITE='\033[01;37m'
VP_BOLD='\033[1m'
VP_UNDERLINE='\033[4m'
#check for any running services that need to be killed before running
ds=`ps aux | grep DesktopServer.app | grep -v grep| head -1`
flywheel=`ps aux | grep "Local by Flywheel.app" | grep -v grep| head -1`
xamp=`ps aux | grep -i "xamp" | grep -v grep| head -1`
mamp=`ps aux | grep -i "mamp" | grep -v grep| head -1`
dnsmasq=`ps aux | grep dnsmasq | grep -v grep| head -1`
nginx=`ps aux | grep nginx | grep -v grep| head -1`
php=`ps aux | grep php | grep -v grep| head -1`
mysql=`ps aux | grep mysql | grep -v grep| head -1`
msg=""
msg2=""
clear
# cache sudo password so it will only need to be entered once.
echo -e "${VP_RED}${VP_BOLD}You may be asked to enter your password twice?.${VP_NONE}"
sudo -v
# if any services are found running, exit and print messages
if [[ $ds ]]; then
msg+="${VP_RED}ERROR:${VP_NONE} found ${VP_PURPLE}DesktopServer.app${VP_NONE} running"$'\n'
fi
if [[ $flywheel ]]; then
msg+="${VP_RED}ERROR:${VP_NONE} found ${VP_PURPLE}Local by Flywheel.app${VP_NONE} running"$'\n'
fi
if [[ $xamp ]]; then
msg+="${VP_RED}ERROR:${VP_NONE} found ${VP_PURPLE}XAMPP${VP_NONE} running"$'\n'
fi
if [[ $mamp ]]; then
msg+="${VP_RED}ERROR:${VP_NONE} found ${VP_PURPLE}MAMP${VP_NONE} running"$'\n'
fi
if [[ $dnsmasq ]]; then
msg+="${VP_RED}ERROR:${VP_NONE} found dnsmasq running"$'\n'
fi
if [[ $nginx ]]; then
msg+="${VP_RED}ERROR:${VP_NONE} found nginx running"$'\n'
fi
if [[ $php ]]; then
msg+="${VP_RED}ERROR:${VP_NONE} found php running"$'\n'
fi
if [[ $mysql ]]; then
msg+="${VP_RED}ERROR:${VP_NONE} found mysql running"$'\n'
fi
if [[ $msg ]]; then
echo -e "$msg"
msg2+="You need to stop the running services before you can install."$'\n'
if [[ $ds ]]; then
msg2+=" ${VP_RED}stop Desktop Server now${VP_NONE}"$'\n'
elif [[ $flywheel ]]; then
msg2+=" ${VP_RED}stop Flywheel Local now${VP_NONE}"$'\n'
elif [[ $xamp ]]; then
msg2+=" ${VP_RED}stop XAMP now${VP_NONE}"$'\n'
elif [[ $mamp ]]; then
msg2+=" ${VP_RED}stop MAMP now${VP_NONE}"$'\n'
else
msg2+=" run: ${VP_GREEN}brew stop${VP_NONE}"$'\n'
msg2+=" run: ${VP_GREEN}sudo launchctl unload homebrew.mxcl.dnsmasq.plist${VP_NONE}"$'\n'
msg2+="Or run: ${VP_CYAN}valet-destroy${VP_NONE}"$'\n'
fi
echo -e "$msg2"$'\n'
echo " "
echo -e "${VP_GREEN}${VP_BOLD}user brew services list to see if any services are running${VP_NONE}"
brew services list
exit;
fi
# install xcode-command line tools
# You will need to answer yes to the prompts to continue
xcode-select --install
# update Homebrew if present, otherwise install
which -s brew
if [[ $? != 0 ]] ; then
# Install Homebrew
echo -e "${VP_GREEN}Installing brew${VP_NONE}"
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
else
# upgrade homebrew formulas
echo -e "${VP_GREEN}Updating brew${VP_NONE}"
brew update
brew upgrade
# cleanup mess
brew doctor
brew cleanup
brew prune
fi
# GNU core utilities (those that come with OS X are outdated)
brew install coreutils
brew install moreutils
# GNU `find`, `locate`, `updatedb`, and `xargs`, `g`-prefixed
brew install findutils
# GNU `sed`, overwriting the built-in `sed`
brew install gnu-sed --with-default-names
# install wget
brew install wget
# install PHP 7.1
brew install homebrew/php/php71
# install Composer
brew install homebrew/php/composer
# install Valet with Composer
composer global require laravel/valet
echo $'\n\nexport PATH="$PATH:$HOME/.composer/vendor/bin"' >> ~/.bash_profile
export PATH="$HOME/.composer/vendor/bin:$PATH"
# install valet
valet install
# give time to process sleep 10 seconds
sleep 10
# hard code php to use .user.ini in home directory
before='memory_limit = 128M'
after='memory_limit = 512M'
sed -i "s/${before}/${after}/g" /usr/local/etc/php/7.1/php.ini
# hard code php to use .user.ini in home directory
before='upload_max_filesize = 2M'
after='upload_max_filesize = 128M'
sed -i "s/${before}/${after}/g" /usr/local/etc/php/7.1/php.ini
# hard code php to use .user.ini in home directory
before='post_max_size = 8M'
after='post_max_size = 128M'
sed -i "s/${before}/${after}/g" /usr/local/etc/php/7.1/php.ini
# hard code php to use .user.ini in home directory
before=';user_ini.filename = ".user.ini"'
after='user_ini.filename = ".user.ini"'
sed -i "s/${before}/${after}/g" /usr/local/etc/php/7.1/php.ini
# change the curl timeout
before='default_socket_timeout = 60'
after='default_socket_timeout = 300'
sed -i "s/${before}/${after}/g" /usr/local/etc/php/7.1/php.ini
# change the curl timeout
before=';sendmail_path ='
after='sendmail_path = /usr/local/bin/mhsendmail'
sed -i "s/${before}/${after}/g" /usr/local/etc/php/7.1/php.ini
# make test the top level domain not dev
valet domain test
# install mysql
#cp ~/bin/my.cnf /usr/local/etc/
brew install mysql
brew services start mysql
sleep 10
brew services stop mysql
sleep 10
brew services start mysql
sleep 10
#cp ~/bin/my.cnf /usr/local/etc/
mysqladmin -u root password root
#sudo mysqladmin -u root password root
#sudo mysqladmin --user=root --password="" password "root"
valet secure phpmyadmin
echo -e "${VP_RED}${VP_BOLD}to configure phpmyadmin oepn https://phpmyadmin.test/config/index.php ${VP_NONE}"
#install mailhog
brew install mailhog
brew services start mailhog
echo -e "${VP_RED}${VP_BOLD}replace line ${VP_NONE}"
# Install wp-cli command tools
chmod 700 ~/bin/wp-cli.phar
sudo mv ~/bin/wp-cli.phar /usr/local/bin/wp
# This is a hack for machines that need a lot of memeory for compiling
php -d memory_limit=2G /usr/local/bin/wp package install aaemnnosttv/wp-cli-valet-command
#install mailhog
#brew install mailhog
#brew services start mailhog
#navigate to ~/Sites/phpmyadmin
mkdir ~/Sites/phpmyadmin
cd ~/Sites/phpmyadmin
wget https://files.phpmyadmin.net/phpMyAdmin/4.7.5/phpMyAdmin-4.7.5-english.zip
unzip -q phpMyAdmin-4.7.5-english.zip
cd phpMyAdmin-4.7.5-english
mv * ..
cd ..
rm -rf phpMyAdmin-4.7.5-english*
# after making changes you must restart
valet restart
# check to see if directory exists
if [ ! -d "~/Sites" ]; then
# Control will enter here if $DIRECTORY doesn't exist.
mkdir ~/Sites
fi
# if Valet is installed correctly you should see this domain responding on 127.0.0.1.
ping -c10 frodo-baggins.test
# navigate to ~/Sites folder
cd ~/Sites
# park this folder i.e., register the current working directory as projects root
valet park
# create example folder
mkdir ~/Sites/example
#navigate to ~/Sites/example
cd ~/Sites/example
# create index.php with a sentence
echo "<?php echo 'Valet at your service';" > index.php
# serve the site over encrypted TLS using HTTP/2
valet secure example
# launch the site in default browser
valet open example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment