Tuesday, July 3, 2018

Enable the "Sites" to be "http://localhost/~username" on macOS

Enable the "Sites" to be "http://localhost/~username" on macOS

There are actually two places where macOS serves website by default:

However, the second one needs setups to activate.

To make http://localhost/~username/ work, just follow the procedures below to configure:

1. Add a user’s config file /etc/apache2/users/username.conf.

<Directory "/Users/username/Sites/">
    Options Indexes MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

2. Turning on Modules in /etc/apache2/httpd.conf

First, copy a httpd.conf backup.

$ sudo cp httpd.conf httpd.conf.bak

Then edit the httpd.conf.

$ sudo vi httpd.conf

Uncomment the following lines:
( remove “#” at the beginning of the line.)

LoadModule authz_host_module libexec/apache2/mod_authz_host.so
LoadModule authz_core_module libexec/apache2/mod_authz_core.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule vhost_alias_module libexec/apache2/mod_vhost_alias.so

Include /private/etc/apache2/extra/httpd-userdir.conf
Include /private/etc/apache2/extra/httpd-vhosts.conf

Save and close vi while finished.

3. Edit /etc/apache2/extra/httpd-userdir.conf.

Go to /etc/apache2/extra/ folder and make a backup of httpd-userdir.conf.

$ sudo cp httpd-userdir.conf httpd-userdir.conf.bak

Then edit httpd-userdir.conf.

$ sudo vi httpd-userdir.conf

Uncomment the following line:
( remove “#” at the beginning of the line.)

Include /private/etc/apache2/users/*.conf

Save and close vi while finished.

4. Restart Apache

$ sudo apachectl restart

Type http://localhost/~username/index.html.en in the browser, it works! ( where username is the user’s name. )

Then type http://localhost/~username in the browser, it shows the index of the “Sites” and lists all files in the “Sites” directory. Now, I can put my web site in the “Sites” directory. Great!

Monday, July 2, 2018

Show username only without hostname in zsh agnoster theme

Show username only without hostname in zsh agnoster theme

Agnoster theme is a pretty good theme for my zsh terminal. However, the hostname is too long nearly over a half of the screen. I have found a way to reduce the length and show username without hostname. it’s very easy, just to remove the @%m to in the theme file.

1. Open the theme file.

~/.oh-my-zsh/themes/agnoster.zsh-theme

2. Search prompt_context.

# Context: user@hostname (who am I and where am I)
prompt_context() {  
  if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
    prompt_segment black default "%(!.%{%F{yellow}%}.)$USER@%m"
  fi
}

3. Remove @%m after $USER, then save it.

# Context: user@hostname (who am I and where am I)
prompt_context() {  
  if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
    prompt_segment black default "%(!.%{%F{yellow}%}.)$USER"
  fi
}

And That’s it!