Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Get Localhost running on Big Sur

Hi


I've recently upgraded to Mac OS Big Sur. When I type http://localhost the browser shows It works! so I know that Apache is running. However, I can no longer access the sites I've got in my Sites folder (username/sites). Are there any instructions for reconfiguring this process.


I remember having to do something back in 2019 to these files:


httpd.conf and httpd-userdir.conf


Many thanks


Peter

iMac 27″ 5K, macOS 11.1

Posted on Jan 18, 2021 2:32 AM

Reply
Question marked as Best reply

Posted on Jan 18, 2021 5:57 AM

Well, there is a quick way to startup a localhost server, but does not address the Big Sur configuration challenges with Apache. In the Terminal, change to your Sites folder, and launch Python as shown in this link. That will tie up the Terminal window with the running HTTP server. Type control-C to quit the Python HTTP server.


In your browser, enter http://localhost:nnnn to see the default index.html file in Sites or http://localhost:nnnn/foo.html where foo is your choice of HTML content.


I don't happen to have current Apache configuration information for Big Sur handy.

Similar questions

6 replies
Question marked as Best reply

Jan 18, 2021 5:57 AM in response to PeterPeartree

Well, there is a quick way to startup a localhost server, but does not address the Big Sur configuration challenges with Apache. In the Terminal, change to your Sites folder, and launch Python as shown in this link. That will tie up the Terminal window with the running HTTP server. Type control-C to quit the Python HTTP server.


In your browser, enter http://localhost:nnnn to see the default index.html file in Sites or http://localhost:nnnn/foo.html where foo is your choice of HTML content.


I don't happen to have current Apache configuration information for Big Sur handy.

Jan 18, 2021 7:10 AM in response to PeterPeartree

The changed config files are moved into /Users/Shared/Relocated Items/

You can review them to see what was changed in the ones you had configured and fix the new ones.

Primarily, you need to enable mod_userdir around line 184 and the user home directories at about line 521.

Your user.conf files should still exist in /etc/apache2/users directory.


If you actually modified httpd-userdir.conf, see if there is a copy in Relocated Items and adjust the new one as appropriate.

Jan 18, 2021 7:59 AM in response to Barney-15E

Hi


I have to admit that I got lost with Python, and didn't want to waste any more of your time.


I found myself un-commenting a variety of lines in Terminal (e.g. mod_userdir and editing the user home directories).


Nothing happened until I restarted Apache (sudo apachectl restart), and I can now see the contents of my Sites directory.


Thank you all so much for your help.

Jan 19, 2021 8:32 PM in response to PeterPeartree

# Install macOS Command Line Tools
xcode-select --install

echo 'ZSH_DISABLE_COMPFIX="true"' >> ~/.zshenv

# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
# Symlink in root directories rather than home directories
echo 'HOMEBREW_CASK_OPTS="--appdir=/Applications --fontdir=/Library/Fonts"' >> ~/.zshenv

# Cleanup Homebrew installation
brew doctor

# 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/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
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/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

Get Localhost running on Big Sur

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.