Created
September 7, 2022 01:54
-
-
Save herbertUG/27f7b93056bb2d93625332fa76130699 to your computer and use it in GitHub Desktop.
Set up macOS development env
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 | |
set -i '' 's/Listen 8080/Listen 80/g' httpd.conf | |
# Set DocumentRoot location to the newly created Sites folder in your user directory | |
set -i '' 's|DocumentRoot \"\/usr\/local\/var\/www\"|DocumentRoot \"'$HOME'\/Sites\"|g' httpd.conf | |
set -i '' 's|Directory \"\/usr\/local\/var\/www\"|Directory \"'$HOME'\/Sites\"|g' httpd.conf | |
# Adjust AllowOverride to All instead of None | |
set -i '' 's/AllowOverride None/AllowOverride All/g' httpd.conf | |
# Uncomment mod_rewrite module | |
set -i '' '/mod_rewrite/s/^#//g' httpd.conf | |
# Set user permissions to current user and group | |
set -i '' 's/User _www/User '$USER'/g' httpd.conf | |
set -i '' 's/Group _www/Group staff/g' httpd.conf | |
# Set servername to make Apache happy | |
set -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/php@8.1 | |
# Add php module to to Apache config | |
echo "LoadModule php_module /usr/local/opt/php@8.1/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 | |
set -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/php@8.1/bin:$PATH"' >> ~/.zshenv | |
echo 'PATH="/usr/local/opt/php@8.1/sbin:$PATH"' >> ~/.zshenv | |
echo 'LDFLAGS="-L/usr/local/opt/php@8.1/lib"' >> ~/.zshenv | |
echo 'CPPFLAGS="-I/usr/local/opt/php@8.1/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/php@8.1 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment