Showing posts with label macOS. Show all posts
Showing posts with label macOS. Show all posts

Monday, May 25, 2020

The Solution to "Time Machine Couldn't Complete the Backup"

When using Time Machine to backup data to "Backup_Machine" disk, it shows the error message "Time Machine couldn't complete the backup to xxx" above and discontinues the backup operation.  It indicates that it might be the disk problems or file corruptions.  The message also suggests to run Disk Utility to solve the problem.

Disk Utility

So, The first thing is to run Disk Utility to check and repair all files and disk volumes if they have problems.  There are two steps to do so:

  1. Run the Disk Utility within the system.
  2. Run the Disk Utility in Recovery mode (press Command(⌘)and R when booting) .
After running Disk Utility and getting positive result, Time Machine backup operation should continue without any error.   If the problem remains, it shows that there is at least one corrupted file which can not be fixed by Disk Utility.  

The Time Machine Mechanic (T2M2)

The solution is to find out the corrupted file and exclude it from backup operation.  However, the error message from Time Machine does not indicate what exactly the corrupted file is. Fortunately, there is a sweet utility called "The Time Machine Mechanic (T2M2)" written by a friendly person who save our lives.  It shows the system log related to the backup errors, the file name and location.  Therefore we can exclude it from the Time Machine backup operation (see more details). 

If the problem shows again, just run T2M2 and add the file to the excluding list of Time Machine.  Rerun Time Machine again until it completes the job.

Note: The error of Time Machine is "BACKUP_FAILED_COPY_STAGE".

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!

Saturday, June 30, 2018

Upgrade PHP version from 5.6 to 7.2 on macOS Sierra (10.12)

Upgrade PHP version from 5.6 to 7.2 on macOS Sierra (10.12)

The PHP version 7.0.0 is released on 03 Dec 2015. It has been three years since then, however, the PHP version installed originally on macOS Sierra (10.12) is still 5.6. I would like to upgrade PHP version in my mac, here are the upgrade procedures to the version 7.2.

First, let’s find out the PHP version number.

$ php -v
PHP 5.6.30

Actually , There are two ways to upgrade PHP.

1. Homebrew

Homebrew is a famous package manager for macOS. It is very easy to use and very powerful.

First, let’s find out which PHP version is available in Homebrew’s package list.

$ brew search php7
==> Searching local taps...
php@7.0   php@7.1    php@7.2

Let’s install the latest version ‘7.2’. Just excute the following commands to install.

  • a. Update the brew package first.
$ brew update && brew upgrade
  • b. Error messages occurs with following commands. Actually, these commands are no longer needed. Therefore, they can be ignored.
$ brew tap homebrew/dupes
$ brew tap homebrew/versions
$ brew tap homebrew/homebrew-php

p.s. Error message: some of the taps are no longer needed.

$ brew tap homebrew/dupes
Error: homebrew/dupes was deprecated. This tap is now empty as all its formulae were migrated.
 $ brew tap homebrew/versions
Error: homebrew/versions was deprecated. This tap is now empty as all its formulae were migrated.
$ brew tap homebrew/homebrew-php
Error: homebrew/php was deprecated. This tap is now empty as all its formulae were migrated.
  • c. Unlink the old version of PHP if it was installed with Homebrew.
$ brew unlink php56 
  • d. Install the new version of PHP.
$ brew install php72

After installation, it shows:
To enable PHP in Apache add the following to httpd.conf (/etc/apache2) and restart Apache:

  • e. Using vim edit httpd.conf of apache2.
$ sudo vim /etc/apache2/httpd.conf

If you don’t like to edit using vim, go to Finder and type:

$ open /etc/apache2/

Search “php5_module” then commend out the statements as follows:

#Comment out the PHP5 module
#LoadModule php5_module libexec/apache2/libphp5.so

Add the commands as follows:

#Enable PHP 7 module
LoadModule php7_module /usr/local/opt/php/lib/httpd/modules/libphp7.so

<FilesMatch \.php$>
    SetHandler application/x-httpd-php
</FilesMatch>
  • f. Finally, check DirectoryIndex includes index.php
    DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
/usr/local/etc/php/7.2/

To have launchd start php now and restart at login:

$ brew services start php

Or, if you don’t want/need a background service you can just run:

$ php-fpm
==> Summary
 /usr/local/Cellar/php/7.2.7: 515 files, 78.9MB
  • g. Restart Apache service
$ sudo apachectl restart
  • h. check the php version:
$ php -v
PHP 7.2.7 (cli) (built: Jun 22 2018 06:29:00) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

Done!


Other brew commands for reference

  • brew tap: to list and update the repositories exist in local computer.
$ brew tap
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
No changes to formulae.
  • brew tap (user)/(repo): to download the 3rd party formula repositories (user)/(repo). If you want to install a package listed in a certain formula repository, the formula repository must be tapped first.

  • brew untap (user)/(repo): delete the 3rd party formula repositories (user)/(repo).

  • brew cleanup: a little tip, clean up old downloads and the files from the Homebrew download-cache are deleted.

$ brew cleanup
Removing: /Users/xxxx/Library/Caches/Homebrew/node-10.4.1.sierra.bottle.tar.gz... (16MB)
   :
   :
==> This operation has freed approximately 5.4GB of disk space.

5.4GB! It’s quite a lot of space.

  • brew doctor: fix your Homebrew repository.

2. CURL

Another option is to execute a curl command provided by php-osx.liip.ch which downloads the binary package from the website and installs it to my mac. This one-line installation is for PHP 7.2 (Current stable) and macOS 10.10 and later.

curl -s https://php-osx.liip.ch/install.sh | bash -s 7.2
  • One little problem mentioned on the php-osx.liip.ch website is: php -v echoes the old version number after installation. The explanation given by php-osx is:

php-osx doesn’t overwrite the php binaries installed by Apple, but installs everything in /usr/local/php5. The new php binary is therefore in /usr/local/php5/bin/php.

You can also adjust your PATH do include that directory, eg. write into your ~/.profile file the following

The solution is to add the path /usr/local/php5/bin to global variable $PATH.

export PATH=/usr/local/php5/bin:$PATH  

I choose the first method since it is really convenient to manage and install packages utilizing Homebrew.