Skip to content

Instantly share code, notes, and snippets.

@dcondrey
Last active June 26, 2024 19:58
Show Gist options
  • Save dcondrey/fec86d6ecedaf37c622cc4d9ba5c5413 to your computer and use it in GitHub Desktop.
Save dcondrey/fec86d6ecedaf37c622cc4d9ba5c5413 to your computer and use it in GitHub Desktop.
(macOS Big Sur) Install Xcode from terminal, setup local development with Apache and PHP 8, and other configurations
# Install Command-line tools as dependency for Homebrew
xcode-select --install # Sets the development directory path to /Library/Developer/CommandLineTools
# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install Mas (command-line interface for Mac App Store)
brew install mas
# Search for Xcode showing only the first 5 results
mas search xcode | head -5
# Install Xcode using App ID
mas install 497799835 # The appid for Xcode shown when doing search
sudo xcode-select -r # Reset the development directory path to put to Xcode /Applications/Xcode.app/Contents/Developer
#sudo xcodebuild -license
# Updaate all Apple software and auto agree to any licenses and restart if necessary
sudo softwareupdate --install --agree-to-license -aR
# Install macOS Command Line Tools
xcode-select --install
sudo softwareupdate --install -aR
echo 'ZSH_DISABLE_COMPFIX="true"' >> ~/.zshenv
# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
# Configure and cleanup Homebrew installation
brew analytics off
brew completions link
brew doctor
# Symlink in root directories rather than home directories
echo 'HOMEBREW_CASK_OPTS="--appdir=/Applications --fontdir=/Library/Fonts"' >> ~/.zshenv
# Disable macOS installation of Apache
sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
# Install Apache with Homebrew
brew install httpd
brew services start httpd
# Check that Apache is running properly
# open http://localhost:8080
# Set localhost to listen for port 80
sed -i '' 's/Listen 8080/Listen 80/g' httpd.conf
# Set DocumentRoot location to the newly created Sites folder in your user directory
sed -i '' 's|DocumentRoot \"\/usr\/local\/var\/www\"|DocumentRoot \"'$HOME'\/Sites\"|g' httpd.conf
sed -i '' 's|Directory \"\/usr\/local\/var\/www\"|Directory \"'$HOME'\/Sites\"|g' httpd.conf
# Adjust AllowOverride to All instead of None
sed -i '' 's/AllowOverride None/AllowOverride All/g' httpd.conf
# Uncomment mod_rewrite module
sed -i '' '/mod_rewrite/s/^#//g' httpd.conf
# Set user permissions to current user and group
sed -i '' 's/User _www/User '$USER'/g' httpd.conf
sed -i '' 's/Group _www/Group staff/g' httpd.conf
# Set servername to make Apache happy
sed -i '' 's/\#ServerName www\.example\.com\:8080/ServerName localhost/g' httpd.conf
# Create DocumentRoot folder and a test page
mkdir $HOME/Sites
echo "<h1>My User Web Root</h1>" > $HOME/Sites/index.html
# Restart Apache
brew services restart httpd
# Check that everything is still working properly
# open http://localhost
# Install PHP 8.0.1
brew tap shivammathur/php
brew install shivammathur/php/[email protected]
# Add php module to to Apache config
echo "LoadModule php_module /usr/local/opt/[email protected]/lib/httpd/modules/libphp.so" >> httpd.conf
echo "" >> httpd.conf
echo " <FilesMatch \.php$>" >> httpd.conf
echo " SetHandler application/x-httpd-php" >> httpd.conf
echo " </FilesMatch>" >> httpd.conf
sed -i '' 's/DirectoryIndex index.html/DirectoryIndex index.php index.html/g' httpd.conf
# Add environment variables to load our version of php rather than the default installed php
echo 'PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshenv
echo 'PATH="/usr/local/opt/[email protected]/sbin:$PATH"' >> ~/.zshenv
echo 'LDFLAGS="-L/usr/local/opt/[email protected]/lib"' >> ~/.zshenv
echo 'CPPFLAGS="-I/usr/local/opt/[email protected]/include"' >> ~/.zshenv
# Reload profile
source ~/.zshenv
# Create test file to make sure PHP is working properly
echo "<?php phpinfo();" > ~/Sites/info.php
# restart Apache and PHP
brew services restart shivammathur/php/[email protected]
brew services restart httpd
# Check that everything is still working and PHP is loading properly
# open http://localhost/info.php
# Install MySQL
brew install mysql
brew services start mysql
@calvin2021y
Copy link

This redownload is not available for this Apple ID either because it was bought by a different user or the item was refunded or cancelled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment