development:system:mac-os
Table of Contents
1. Brew
1.1. Danh sách packages đã cài đặt
tungnt@MacBook-Pro-cua-Nguyen-2 template.1site.vn % brew list ==> Formulae abseil cairo freetype gradle jsoncpp libffi libpthread-stubs libuv little-cms2 mpg123 openjpeg pixman rav1e telnet yarn aom cjson frei0r graphite2 kafka libfido2 librist libvidstab logstash mysql openldap pkg-config rclone tesseract zeromq apr cmocka fribidi guile krb5 libgcrypt libsamplerate libvmaf lz4 nettle openssl@1.1 postgresql@14 readline theora zimg apr-util composer gd harfbuzz lame libgpg-error libsndfile libvorbis lzo nghttp2 openssl@3 protobuf redis tidy-html5 zlib argon2 curl gdbm highway leptonica libidn2 libsodium libvpx m4 nginx opus protobuf@21 rtmpdump unbound zookeeper aribb24 dav1d gettext hunspell libarchive libksba libsoxr libwebsockets macos-term-size node p11-kit pyqt@5 rubberband unixodbc zstd aspell dbus giflib icu4c libass libmetalink libssh libx11 mbedtls node@16 pango python-setuptools sdl2 webp assimp double-conversion git imath libassuan libmicrohttpd libssh2 libxau md4c npth pcre python@3.10 six wget autoconf duktape glib jasper libavif libmng libtasn1 libxcb mkcert oniguruma pcre2 python@3.11 snappy wxwidgets bazel erlang gmp jemalloc libb2 libnghttp2 libtiff libxdmcp mongodb-community opencore-amr php python@3.12 speex x264 bdw-gc ffmpeg gnupg jmeter libbluray libogg libtool libxext mongodb-database-tools openexr php@7.2 python@3.9 sqlite x265 brotli flac gnutls jpeg libcbor libpng libunibreak libxml2 mongosh openjdk php@7.4 qt srt xorgproto c-ares fontconfig gobject-introspection jpeg-turbo libev libpq libunistring libxrender mosquitto openjdk@11 php@8.2 qt@5 supervisor xvid ca-certificates freetds gpgme jpeg-xl libevent libproxy libusb libzip mpdecimal openjdk@17 pinentry rabbitmq svt-av1 xz
1.2. Danh sách dịch vụ đã cài đặt
tungnt@MacBook-Pro-cua-Nguyen-2 template.1site.vn % brew services list Name Status User File dbus none kafka none logstash none mongodb-community started tungnt ~/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist mosquitto none mysql started tungnt ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist nginx error 256 root ~/Library/LaunchAgents/homebrew.mxcl.nginx.plist php error 19968 tungnt ~/Library/LaunchAgents/homebrew.mxcl.php.plist php@7.2 none php@7.4 started tungnt ~/Library/LaunchAgents/homebrew.mxcl.php@7.4.plist php@8.2 none postgresql@14 error 6 tungnt ~/Library/LaunchAgents/homebrew.mxcl.postgresql@14.plist rabbitmq none root redis started tungnt ~/Library/LaunchAgents/homebrew.mxcl.redis.plist supervisor none root unbound none zookeeper none
2. Nginx
2.1. Cài đặt nginx
tungnt@TungNT ~ % brew install nginx
2.2. Restart nginx
tungnt@TungNT ~ % brew services start nginx
2.3. Xem thông tin nginx
tungnt@MacBook-Pro-cua-Nguyen-2 template.1site.vn % brew info nginx ==> nginx: stable 1.27.0 (bottled), HEAD HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server https://nginx.org/ Installed /opt/homebrew/Cellar/nginx/1.25.3 (26 files, 2.4MB) * Poured from bottle using the formulae.brew.sh API on 2023-11-16 at 21:07:26 From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/n/nginx.rb License: BSD-2-Clause ==> Dependencies Required: openssl@3 ✔, pcre2 ✘ ==> Options --HEAD Install HEAD version ==> Caveats Docroot is: /opt/homebrew/var/www The default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that nginx can run without sudo. nginx will load all files in /opt/homebrew/etc/nginx/servers/. To restart nginx after an upgrade: brew services restart nginx Or, if you don't want/need a background service you can just run: /opt/homebrew/opt/nginx/bin/nginx -g daemon\ off\; ==> Analytics install: 11,814 (30 days), 42,355 (90 days), 162,044 (365 days) install-on-request: 11,773 (30 days), 42,161 (90 days), 161,555 (365 days) build-error: 9 (30 days)
tungnt@MacBook-Pro-cua-Nguyen-2 template.1site.vn % ps aux | grep nginx nobody 1061 0.0 0.0 411171056 320 ?? S 26Jul24 0:00.39 nginx: worker process root 623 0.0 0.0 411039984 272 ?? Ss 26Jul24 0:00.07 nginx: master process /opt/homebrew/opt/nginx/bin/nginx -g daemon off; tungnt 37952 0.0 0.0 410733264 1456 s000 S+ 9:22PM 0:00.01 grep nginx
3. PHP
3.1. Kiểm tra version
tungnt@MacBook-Pro-cua-Nguyen-2 template.1site.vn % php -v PHP 7.2.34 (cli) (built: Jun 6 2024 19:16:24) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.34, Copyright (c) 1999-2018, by Zend Technologies tungnt@MacBook-Pro-cua-Nguyen-2 template.1site.vn % /opt/homebrew/opt/php@8.2/bin/php -v PHP 8.2.20 (cli) (built: Jun 4 2024 13:22:51) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.20, Copyright (c) Zend Technologies with Zend OPcache v8.2.20, Copyright (c), by Zend Technologies
3.2. Cài đặt PHP
$ brew install php@5.6 $ brew install php@7.0 $ brew install php@7.1 $ brew install php@7.2 $ brew install php@7.3
3.3. Start/Restart PHP
$ brew services start php@7.3 $ brew services start php@7.2 $ brew services start php@7.1 $ brew services start php@7.0 $ brew services start php@5.6 $ brew services restart php@8.2
3.4. Lựa chọn phiên bản PHP
tungnt@MacBook-Pro-cua-Nguyen-2 template.1site.vn % brew unlink php@8.2 && brew link --force php@8.2 Unlinking /opt/homebrew/Cellar/php@8.2/8.2.20... 343 symlinks removed. Linking /opt/homebrew/Cellar/php@8.2/8.2.20... 257 symlinks created. If you need to have this software first in your PATH instead consider running: echo 'export PATH="/opt/homebrew/opt/php@8.2/bin:$PATH"' >> ~/.zshrc echo 'export PATH="/opt/homebrew/opt/php@8.2/sbin:$PATH"' >> ~/.zshrc tungnt@MacBook-Pro-cua-Nguyen-2 template.1site.vn % php -v PHP 7.2.34 (cli) (built: Jun 6 2024 19:16:24) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.2.34, Copyright (c) 1999-2018, by Zend Technologies tungnt@MacBook-Pro-cua-Nguyen-2 template.1site.vn % source ~/.zshrc tungnt@MacBook-Pro-cua-Nguyen-2 template.1site.vn % php -v PHP 8.2.20 (cli) (built: Jun 4 2024 13:22:51) (NTS) Copyright (c) The PHP Group Zend Engine v4.2.20, Copyright (c) Zend Technologies with Zend OPcache v8.2.20, Copyright (c), by Zend Technologies
3.5. Xem thông tin PHP
tungnt@MacBook-Pro-cua-Nguyen-2 template.1site.vn % brew info php ==> php: stable 8.3.9 (bottled), HEAD General-purpose scripting language https://www.php.net/ Installed /opt/homebrew/Cellar/php/8.2.6 (193 files, 19.7MB) Built from source /opt/homebrew/Cellar/php/8.2.12_1 (520 files, 83.5MB) Poured from bottle using the formulae.brew.sh API on 2023-11-16 at 21:05:47 /opt/homebrew/Cellar/php/8.3.8 (524 files, 88.7MB) Poured from bottle using the formulae.brew.sh API on 2024-06-14 at 12:11:22 From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/p/php.rb License: PHP-3.01 ==> Dependencies Build: httpd ✘, pkg-config ✔ Required: apr ✔, apr-util ✔, argon2 ✔, aspell ✔, autoconf ✔, curl ✘, freetds ✘, gd ✔, gettext ✔, gmp ✔, icu4c ✔, krb5 ✘, libpq ✔, libsodium ✘, libzip ✔, oniguruma ✔, openldap ✔, openssl@3 ✔, pcre2 ✘, sqlite ✔, tidy-html5 ✔, unixodbc ✔ ==> Options --HEAD Install HEAD version ==> Caveats To enable PHP in Apache add the following to httpd.conf and restart Apache: LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> Finally, check DirectoryIndex includes index.php DirectoryIndex index.php index.html The php.ini and php-fpm.ini file can be found in: /opt/homebrew/etc/php/8.3/ To restart php after an upgrade: brew services restart php Or, if you don't want/need a background service you can just run: /opt/homebrew/opt/php/sbin/php-fpm --nodaemonize ==> Analytics install: 52,307 (30 days), 154,260 (90 days), 689,804 (365 days) install-on-request: 48,378 (30 days), 142,868 (90 days), 643,985 (365 days) build-error: 20 (30 days)
tungnt@MacBook-Pro-cua-Nguyen-2 template.1site.vn % ps aux | grep php tungnt 5829 0.3 0.1 411685232 9504 ?? S 26Jul24 4:43.50 /opt/homebrew/Cellar/php@8.2/8.2.20/bin/php artisan horizon:supervisor macbook-pro-cua-nguyen-2local-ba9r:test redis --workers-name=default --balance=auto --max-processes=5 --min-processes=1 --nice=0 --balance-cooldown=3 --balance-max-shift=1 --parent-id=2633 --auto-scaling-strategy=time --backoff=0 --max-time=0 --max-jobs=0 --memory=128 --queue=default --sleep=3 --timeout=60 --tries=1 --rest=0 tungnt 2633 0.3 0.1 411685232 9808 ?? S 26Jul24 5:18.32 /opt/homebrew/opt/php@8.2/bin/php /var/www/1site/template.1site.vn/artisan horizon tungnt 35991 0.0 0.1 413011024 6000 ?? S 8:58PM 0:19.60 /Users/tungnt/.vscode/extensions/devsense.phptools-vscode-1.33.12934/out/server/devsense.php.ls tungnt 5874 0.0 0.1 411554160 10096 ?? S 26Jul24 2:08.74 /opt/homebrew/Cellar/php@8.2/8.2.20/bin/php artisan horizon:work redis --name=default --supervisor=macbook-pro-cua-nguyen-2local-ba9r:blue --backoff=0 --max-time=0 --max-jobs=0 --memory=128 --queue=horizon --sleep=3 --timeout=60 --tries=1 --rest=0 tungnt 5870 0.0 0.1 411545968 10128 ?? S 26Jul24 2:08.30 /opt/homebrew/Cellar/php@8.2/8.2.20/bin/php artisan horizon:work redis --name=default --supervisor=macbook-pro-cua-nguyen-2local-ba9r:blue --backoff=0 --max-time=0 --max-jobs=0 --memory=128 --queue=test --sleep=3 --timeout=60 --tries=1 --rest=0 tungnt 5869 0.0 0.1 411545968 10160 ?? S 26Jul24 2:08.96 /opt/homebrew/Cellar/php@8.2/8.2.20/bin/php artisan horizon:work redis --name=default --supervisor=macbook-pro-cua-nguyen-2local-ba9r:test --backoff=0 --max-time=0 --max-jobs=0 --memory=128 --queue=default --sleep=3 --timeout=60 --tries=1 --rest=0 tungnt 5830 0.0 0.1 411685232 9600 ?? S 26Jul24 4:59.93 /opt/homebrew/Cellar/php@8.2/8.2.20/bin/php artisan horizon:supervisor macbook-pro-cua-nguyen-2local-ba9r:blue redis --workers-name=default --balance=auto --max-processes=10 --min-processes=1 --nice=0 --balance-cooldown=3 --balance-max-shift=1 --parent-id=2633 --auto-scaling-strategy=time --backoff=0 --max-time=0 --max-jobs=0 --memory=128 --queue=test,horizon --sleep=3 --timeout=60 --tries=1 --rest=0 tungnt 5795 0.0 0.0 411931808 784 ?? S 26Jul24 0:08.71 /opt/homebrew/opt/php@7.4/sbin/php-fpm --nodaemonize tungnt 5794 0.0 0.0 411931872 752 ?? S 26Jul24 0:09.21 /opt/homebrew/opt/php@7.4/sbin/php-fpm --nodaemonize tungnt 5629 0.0 0.0 411796960 1312 ?? S 26Jul24 0:05.86 /opt/homebrew/opt/php@7.4/sbin/php-fpm --nodaemonize tungnt 38046 0.0 0.0 410724048 1328 s000 S+ 9:27PM 0:00.00 grep php
tungnt@192 template.1site.vn % php --ini Configuration File (php.ini) Path: /opt/homebrew/etc/php/8.2 Loaded Configuration File: /opt/homebrew/etc/php/8.2/php.ini Scan for additional .ini files in: /opt/homebrew/etc/php/8.2/conf.d Additional .ini files parsed: /opt/homebrew/etc/php/8.2/conf.d/ext-opcache.ini ... /opt/homebrew/Cellar/php/8.2.6/pecl/20220829
3.6. Xoá cài đặt PHP
$ brew uninstall php@7.4
4. MySQL
4.1. Cài đặt MySQL
$ brew install mysql
4.2. Start MySQL
$ brew services start mysql
4.3. Xem thông tin MySQL
tungnt@MacBook-Pro-cua-Nguyen-2 template.1site.vn % brew info mysql ==> mysql: stable 8.3.0 (bottled) Open source relational database management system https://dev.mysql.com/doc/refman/8.3/en/ Conflicts with: mariadb (because mysql, mariadb, and percona install the same binaries) percona-server (because mysql, mariadb, and percona install the same binaries) Installed /opt/homebrew/Cellar/mysql/8.3.0_1 (324 files, 312.9MB) * Poured from bottle using the formulae.brew.sh API on 2024-06-14 at 12:10:27 From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/m/mysql.rb License: GPL-2.0-only with Universal-FOSS-exception-1.0 ==> Dependencies Build: bison ✘, cmake ✘, pkg-config ✔ Required: icu4c ✔, libevent ✔, libfido2 ✘, lz4 ✔, openssl@3 ✔, protobuf@21 ✔, zlib ✔, zstd ✔ ==> Caveats We've installed your MySQL database without a root password. To secure it run: mysql_secure_installation MySQL is configured to only allow connections from localhost by default To connect run: mysql -u root To restart mysql after an upgrade: brew services restart mysql Or, if you don't want/need a background service you can just run: /opt/homebrew/opt/mysql/bin/mysqld_safe --datadir\=/opt/homebrew/var/mysql ==> Analytics install: 29,603 (30 days), 96,441 (90 days), 488,402 (365 days) install-on-request: 29,569 (30 days), 96,325 (90 days), 486,840 (365 days) build-error: 879 (30 days)
tungnt@MacBook-Pro-cua-Nguyen-2 template.1site.vn % ps -feax | grep mysql 501 5634 1 0 26Jul24 ?? 0:00.03 /bin/sh /opt/homebrew/opt/mysql/bin/mysqld_safe --datadir=/opt/homebrew/var/mysql 501 5772 5634 0 26Jul24 ?? 7:29.43 /opt/homebrew/opt/mysql/bin/mysqld --basedir=/opt/homebrew/opt/mysql --datadir=/opt/homebrew/var/mysql --plugin-dir=/opt/homebrew/opt/mysql/lib/plugin --log-error=MacBook-Pro-cua-Nguyen-2.local.err --pid-file=MacBook-Pro-cua-Nguyen-2.local.pid 501 38540 847 0 9:31PM ttys000 0:00.00 grep mysql
5. MongoDb
5.1. Cài đặt Mongo
tungnt@TungNT ~ % brew install mongodb
5.2. Version Mongo
% mongod -v
Supervisor
brew install supervisor supervisord --version
- /opt/homebrew/etc/supervisor.d
- /opt/homebrew/etc/supervisord.conf
- /opt/homebrew/var/log/supervisord.log
6. Một số lênh khác
6.1. Restart shell
% exec -l $SHELL # Restart shell % sudo find / -name my.cnf # Tìm file thư mục
7. Dọn dẹp hệ thống
7.1. Xoá cache/log
Mở Finder → Nhấn Cmd + Shift + G → Nhập đường dẫn:
- ~/Library/Caches
- /Library/Caches
- ~/Library/Logs
Xóa tất cả các thư mục bên trong (không xóa toàn bộ thư mục Caches)
Hoặc:
rm -rf ~/Library/Caches/* rm -rf /Library/Caches/* rm -rf ~/Library/Logs/*
7.2. Gỡ ứng dụng không dùng đến
Vào Applications (Cmd + Shift + A trong Finder). Kéo ứng dụng vào Trash. Xóa các file còn sót lại trong:
- ~/Library/Application Support/
- ~/Library/Preferences/
7.3. Dọn dẹp bộ nhớ hệ thống bằng Terminal
sudo purge
7.4. Kiểm tra dung lượng & xóa file lớn
Mở Finder → Cmd + F → Chọn File Size > Lớn hơn 100MB để xem file nào chiếm nhiều dung lượng.
Hoặc:
du -sh * | sort -hr | head -20
7.5. Xóa file tải xuống không cần thiết
Mở Finder → Cmd + Shift + G → nhập: ~/Downloads
7.6. Xóa ứng dụng chạy nền không cần thiết
Vào System Settings → General → Login Items. Tắt ứng dụng không cần thiết.
Hoặc dùng Terminal:
launchctl list
Nếu thấy ứng dụng không cần thiết:
launchctl remove <tên_dịch_vụ>
7.7. Tắt file snapshot của Time Machine (Nếu có)
Nếu dùng Time Machine, macOS có thể giữ các snapshot cũ. Xóa bằng:
tmutil listlocalsnapshots / tmutil deletelocalsnapshots YYYY-MM-DD-HHMMSS # xóa từng cái
7.8. Kiểm tra dung lượng ổ đĩa nhanh
Apple Menu → About This Mac → Storage.
Hoặc:
df -h
development/system/mac-os.txt · Last modified: 2025/03/12 02:37 by tungnt