2020 年第 4 四半期の YouTube 急上昇動画数をチャンネル別にランキング形式で掲載しています。
[yttrendrank 20201001 20201231]
Random Notes
2020 年第 4 四半期の YouTube 急上昇動画数をチャンネル別にランキング形式で掲載しています。
[yttrendrank 20201001 20201231]
OS: macOS Catalina バージョン 10.15.4
Python: Python 3.8.3
Python で MySQLdb モジュールを使える様にしたい。
まず Homebrew で MySQL をインストールする必要があるので「brew install mysql」を実行します。
これをしていないとこの後 pip で「mysqlclient」のインストールができません。
(scraping) % brew install mysql Updating Homebrew... ==> Auto-updated Homebrew! Updated 1 tap (homebrew/core). ==> New Formulae acl2 heksa nfpm act httpx ngs airshare hy notmuch-mutt alsa-lib i686-elf-binutils numcpp amp i686-elf-gcc oci-cli apidoc idris2 omake arb infracost openfst argo inja oq argocd inko ormolu arrayfire ioctl ory-hydra asimov jerryscript osi asroute jimtcl osm athenacli jinx packetbeat austin jobber packr awsweeper jsonnet-bundler pandoc-include-code blogc k9s pandocomatic bombadillo kde-karchive parallel-hashmap bond kde-kdoctools periscope borgbackup kde-ki18n pipgrip box2d kde-threadweaver po4a buildozer kona podman c7n kondo postgresql@12 cadence ksync prometheus-cpp carton kubie promtail cassowary ladspa-sdk protoc-gen-go-grpc castget latexindent protoc-gen-gogo cbc ldpl protoc-gen-gogofaster cdktf leaf pwncat cgl libaio python@3.7 chalk-cli libcouchbase@2 python@3.9 charge libdmx reg chart-testing libdrm rgf choose-rust libfontenc rqlite chrony libfs rust-analyzer clair libgccjit rustscan clang-format@8 libgnt s2n cli11 libhandy saltwater cloud-nuke libice scw@1 cloudformation-cli libirecovery sdns cloudformation-guard libmnl server-go coconut libnetfilter-queue shallow-backup colfer libnetworkit sheldon commitizen libnfnetlink shtools copilot liboqs silicon coredns libpciaccess simdjson cortex libpthread-stubs skylighting cpio libseccomp sleef cpm libsm smlpkg cpr libx11 snap croaring libxau so croc libxaw solidity cubejs-cli libxaw3d sonic cvs-fast-export libxcb sponge datasette libxcomposite sqlite-utils dbdeployer libxcursor standardese diskonaut libxdamage staticcheck dnsprobe libxdmcp structurizr-cli doctest libxext subfinder dosbox-staging libxfixes termcolor dotnet libxfont terraform-ls duckscript libxft terraform@0.12 eksctl libxi terrascan eleventy libxinerama tfsec empty libxkbfile thanos envoy libxmu toot fava libxpm torchvision fblog libxrandr tre-command fennel libxrender trunk fetch libxres ugrep flank libxscrnsaver uptoc fleet-cli libxshmfence usb.ids flit libxt util-macros folderify libxtst vapor font-util libxv vcpkg foreman libxvmc vgrep fpart libxxf86dga vivid fpdns libxxf86vm vlang functionalplus litecli volk gateway-go localstack vsearch gcc@9 logcli vtk@8.2 git-hooks-go loki webify git-hound lunchy wgcf gitql lunchy-go wownero gitui macos-trash wren gluon mandown wren-cli go@1.14 mariadb@10.4 x86_64-elf-gdb gofish marked xcb-proto golangci-lint mask xdpyinfo gostatic matplotplusplus xorgproto gradle-profiler mhonarc xtrans gravity microplane yj grpcui naabu z.lua gulp-cli nanorc zoxide halide nest zsh-you-should-use hashlink networkit hasura-cli never ==> Updated Formulae Updated 4645 formulae. ==> Renamed Formulae elasticsearch@6.8 -> elasticsearch@6 gst-validate -> gst-devtools interactive-rebase-tool -> git-interactive-rebase-tool jfrog-cli-go -> jfrog-cli kibana@6.8 -> kibana@6 mkl-dnn -> onednn ==> Deleted Formulae baidupcs-go elasticsearch@5.6 marathon-swift unravel biogeme highlighting-kate python urbit cargo-completion i386-elf-grub residualvm wpscan cryptopp kibana@5.6 sflowtool xu4 elasticsearch@2.4 lumo tomee-jax-rs ==> Downloading https://homebrew.bintray.com/bottles/openssl%401.1-1.1.1h.catali ==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/4e5357c0cfd55cfa4ef0b ######################################################################## 100.0% ==> Downloading https://homebrew.bintray.com/bottles/protobuf-3.13.0.catalina.bo ==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/af2990ba0a6e5588ef2af ######################################################################## 100.0% ==> Downloading https://homebrew.bintray.com/bottles/mysql-8.0.21_1.catalina.bot ==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/81e92d0df39edaff415e7 ######################################################################## 100.0% ==> Installing dependencies for mysql: openssl@1.1 and protobuf ==> Installing mysql dependency: openssl@1.1 ==> Pouring openssl@1.1-1.1.1h.catalina.bottle.tar.gz ==> Caveats A CA file has been bootstrapped using certificates from the system keychain. To add additional certificates, place .pem files in /usr/local/etc/openssl@1.1/certs and run /usr/local/opt/openssl@1.1/bin/c_rehash openssl@1.1 is keg-only, which means it was not symlinked into /usr/local, because macOS provides LibreSSL. If you need to have openssl@1.1 first in your PATH run: echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc For compilers to find openssl@1.1 you may need to set: export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" ==> Summary 🍺 /usr/local/Cellar/openssl@1.1/1.1.1h: 8,067 files, 18.5MB ==> Installing mysql dependency: protobuf ==> Pouring protobuf-3.13.0.catalina.bottle.tar.gz ==> Caveats Emacs Lisp files have been installed to: /usr/local/share/emacs/site-lisp/protobuf ==> Summary 🍺 /usr/local/Cellar/protobuf/3.13.0: 266 files, 19.8MB ==> Installing mysql ==> Pouring mysql-8.0.21_1.catalina.bottle.tar.gz ==> /usr/local/Cellar/mysql/8.0.21_1/bin/mysqld --initialize-insecure --user=ken ==> 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 -uroot To have launchd start mysql now and restart at login: brew services start mysql Or, if you don't want/need a background service you can just run: mysql.server start ==> Summary 🍺 /usr/local/Cellar/mysql/8.0.21_1: 290 files, 291.2MB ==> `brew cleanup` has not been run in 30 days, running now... Removing: /Users/xxxxxxxx/Library/Caches/Homebrew/gettext--0.20.2_1.catalina.bottle.tar.gz... (8.4MB) Removing: /Users/xxxxxxxx/Library/Caches/Homebrew/libidn2--2.3.0.catalina.bottle.tar.gz... (233.6KB) Removing: /Users/xxxxxxxx/Library/Caches/Homebrew/libunistring--0.9.10.catalina.bottle.tar.gz... (1.4MB) Removing: /usr/local/Cellar/openssl@1.1/1.1.1g... (8,059 files, 18MB) Removing: /Users/xxxxxxxx/Library/Caches/Homebrew/openssl@1.1--1.1.1g.catalina.bottle.tar.gz... (5.3MB) Removing: /Users/xxxxxxxx/Library/Caches/Homebrew/tree--1.8.0.catalina.bottle.tar.gz... (49.5KB) Removing: /Users/xxxxxxxx/Library/Caches/Homebrew/wget--1.20.3_2.catalina.bottle.tar.gz... (1.4MB) Removing: /Users/xxxxxxxx/Library/Logs/Homebrew/tree... (64B) Removing: /Users/xxxxxxxx/Library/Logs/Homebrew/wget... (64B) Removing: /Users/xxxxxxxx/Library/Logs/Homebrew/libidn2... (64B) Removing: /Users/xxxxxxxx/Library/Logs/Homebrew/libunistring... (64B) Removing: /Users/xxxxxxxx/Library/Logs/Homebrew/gettext... (64B) Removing: /Users/xxxxxxxx/Library/Logs/Homebrew/openssl@1.1... (64B) Pruned 1 symbolic links and 2 directories from /usr/local ==> Caveats ==> openssl@1.1 A CA file has been bootstrapped using certificates from the system keychain. To add additional certificates, place .pem files in /usr/local/etc/openssl@1.1/certs and run /usr/local/opt/openssl@1.1/bin/c_rehash openssl@1.1 is keg-only, which means it was not symlinked into /usr/local, because macOS provides LibreSSL. If you need to have openssl@1.1 first in your PATH run: echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc For compilers to find openssl@1.1 you may need to set: export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" ==> protobuf Emacs Lisp files have been installed to: /usr/local/share/emacs/site-lisp/protobuf ==> mysql 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 -uroot To have launchd start mysql now and restart at login: brew services start mysql Or, if you don't want/need a background service you can just run: mysql.server start
長々とログが出ましたが、入力待ちになったら which コマンドで mysql がインストールされたのを確認します。
(scraping) % which mysql /usr/local/bin/mysql
/usr/local/bin/mysql にインストールされています。
「mysql.server start」と入力して MySQL を起動してみます。
% mysql.server start Starting MySQL .. SUCCESS! %
無事起動しました。
「mysql.server stop」でシャットダウンすることができます。
% mysql.server stop Shutting down MySQL .. SUCCESS! %
pip で mysqlclient をインストールします。
(scraping) % pip install mysqlclient Collecting mysqlclient Using cached https://files.pythonhosted.org/packages/a5/e1/e5f2b231c05dc51d9d87fa5066f90d1405345c54b14b0b11a1c859020f21/mysqlclient-2.0.1.tar.gz Installing collected packages: mysqlclient Running setup.py install for mysqlclient ... done Successfully installed mysqlclient-2.0.1 WARNING: You are using pip version 19.2.3, however version 20.2.3 is available. You should consider upgrading via the 'pip install --upgrade pip' command. (scraping) %
Python で MySQLdb モジュールがインポートできることを確認して完了です。
>>> import MySQLdb >>>
いきなり request をインポートしようとすると「request モジュールがありません」とのことでエラーが出てしまいます。
>>> import requests Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'requests'
なので一旦 Python は exit() します。そして pip3 で request をインストール。
>>> exit() % pip3 install requests
すると下記の様に諸々のダウンロードが実行され一瞬で入力待ち状態に戻ります。
% pip3 install requests Collecting requests Downloading requests-2.24.0-py2.py3-none-any.whl (61 kB) |████████████████████████████████| 61 kB 692 kB/s Collecting certifi>=2017.4.17 Downloading certifi-2020.6.20-py2.py3-none-any.whl (156 kB) |████████████████████████████████| 156 kB 6.7 MB/s Collecting idna<3,>=2.5 Downloading idna-2.10-py2.py3-none-any.whl (58 kB) |████████████████████████████████| 58 kB 7.5 MB/s Collecting chardet<4,>=3.0.2 Downloading chardet-3.0.4-py2.py3-none-any.whl (133 kB) |████████████████████████████████| 133 kB 16.4 MB/s Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 Downloading urllib3-1.25.10-py2.py3-none-any.whl (127 kB) |████████████████████████████████| 127 kB 20.1 MB/s Installing collected packages: certifi, idna, chardet, urllib3, requests Successfully installed certifi-2020.6.20 chardet-3.0.4 idna-2.10 requests-2.24.0 urllib3-1.25.10 %
入力待ちになったら Python3 を起動。
% python3
そしてそのまま request をインポートしてみます。
>>> import requests >>>
今回はエラーが出ず入力待ち状態になりました。試しにそのまま Yahoo! のソースコードを表示してみます。
>>> import requests >>> r = requests.get('http://yahoo.com/') >>> r.text '<!DOCTYPE html>\n<html id="atomic" lang="en-US" class="atomic l-out Pos-r https fp fp-v2 fp-default mini-uh-on uh-topbar-on ltr desktop Desktop bkt201">\n<head>\n <meta http-equiv="X-UA-Compatible" content="IE=edge">\n \n <title>Yahoo</title><meta http-equiv="x-dns-prefetch-control" content="on"><link rel="dns-prefetch" href="//s.yimg.com"><link rel="preconnect" href="//s.yimg.com">
問題なさそうですね。これで request のインストールは完了です。
さくらのレンタルサーバにはデフォルトで Python2 系のみ入っているのですが、残念ながらPython2 は 2020 年にサポートが終了していてもう推奨されていません。
というか Python2 だ Python3 だ以前にレンタルサーバーの Python で色々やろうという考えが半ば間違いみたいな部分もありますが。笑
▶︎【7社比較】レンタルサーバーの大クセ Python は本当は使いづらい!?
▶︎レンタルサーバーで Python は茨の道!VPS が楽得でおすすめ
とはいえいろんな理由でまださくらのレンタルサーバで頑張りたい方のために、Python3 系をインストールする方法を紹介します。
では本編、さくらのレンタルサーバーに Python3 をインストールする方法を案内します。
ちなみに私が使っているのはさくらのレンタルサーバ スタンダードで、ローカルは Mac で作業します。
まずはターミナルを立ち上げ、ssh でさくらレンタルサーバにログインします。
Last login: Sun Oct 11 10:43:12 on ttys000 % ssh XXXXXX@XXXXXX.sakura.ne.jp XXXXXX@XXXXXX.sakura.ne.jp's password:
ファイルをダウンロードする前に、ダウンロード用のフォルダを作っておきます。下記のコマンドで「work」フォルダとその配下に「python3」フォルダを作成します。
% mkdir -p ~/work/python3
FTPクライアントで見てみると下記の様に各フォルダが作成されているのが確認できます。
% cd ~/work/python3 % wget --no-check-certificate https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
ファイルがダウンロードされ、下記の様に入力待ちになれば無事ダウンロード完了です。
% wget --no-check-certificate https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz --2020-10-11 12:39:03-- https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz Resolving www.python.org... 151.101.88.223, 2a04:4e42:15::223 Connecting to www.python.org|151.101.88.223|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 26724009 (25M) [application/octet-stream] Saving to: 'Python-3.9.0.tgz' Python-3.9.0.tgz 100%[=====================>] 25.49M 43.9MB/s in 0.6s 2020-10-11 12:39:03 (43.9 MB/s) - 'Python-3.9.0.tgz' saved [26724009/26724009] %
念のため覗いてみると、先ほど作成した「python3」フォルダのなかに「Python-3.9.0.tgz」のファイルがダウンロードされているのが分かります。
% tar zxf Python-3.9.0.tgz
ファイルが解凍され、元々ダウンロードした圧縮ファイルとは別に「Python-3.9.0」という名前のフォルダが作成されています。
解凍されたフォルダ「Python-3.9.0」に移動します。
% cd ./Python-3.9.0
次に ./configure を実行しますが、その際 prefix を使ってインストールするディレクトリを指定します。
% ./configure --prefix=$HOME/local/python/ --with-system-ffi LDFLAGS="-L $HOME/local/lib/" CPPFLAGS="-I $HOME/local/include/"
*–with-system-ffi 以降の部分は無くても Python3 のインストールはできますが、後々 _ctypes の問題があったので追記しました。
実行するとプロセスが走ってドバドバとターミナルに表示されますが、下記が表示されて入力待ちの状態になったら完了です。
creating Modules/Setup.local creating Makefile
「make」を実行します。
% make
しばらくプロセスが走るので入力待ちになるまで待ちます。次に「make install」を実行します。
% make install
またプロセスが走るので最後下記の様な表示が出て入力待ちになるまで待ちます。
Installing collected packages: setuptools, pip WARNING: The script easy_install-3.9 is installed in '/home/XXXXXX/local/python/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. WARNING: The scripts pip3 and pip3.9 are installed in '/home/XXXXXX/local/python/bin' which is not on PATH. Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. Successfully installed pip-20.2.3 setuptools-49.2.1 %
実は上のログに2箇所「WARNING」として警告が表示されているのですが、その内容が以下の通り。
WARNING:スクリプトeasy_install-3.9は、「PATH」にない「/home/XXXXXX/local/python/bin」にインストールされています。このディレクトリを「PATH」に追加することを検討してください。 WARNING:スクリプトpip3およびpip3.9は、「PATH」にない「/home/XXXXXX/local/python/bin」にインストールされています。このディレクトリを「PATH」に追加することを検討してください。
これは後ほど .cshrc ファイルを編集して解決します。
local > python というディレクトリが作られ、さらにその配下に様々なフォルダが作られています。
python3 と pip3 のインストール自体は完了しましたが、この状態だとまだ python3 や pip3 と言ったコマンドを直接使うことができません。いわゆる「パスが通っていない」状態です。「which」コマンドを実行しても下記の通りエラーが返ってきます。
% which python3 python3: Command not found. % which pip3 pip3: Command not found.
python3 と pip3 が両方とも「$HOME/local/python/bin」にインストールされている状態です。
.cshrc ファイルを編集することでパスを通しますが、この作業をする前に必ず .cshrc のバックアップをとっておきましょう。
% cd ~/ % vi .cshrc
.cshrc の内容がターミナルに表示されます。
# $FreeBSD: src/share/skel/dot.cshrc,v 1.14.6.1 2008/11/25 02:59:29 kensmith Exp $ # # .cshrc - csh resource script, read at beginning of execution by each shell # # see also csh(1), environ(7). # alias h history 25 alias j jobs -l alias la ls -a alias lf ls -FA alias ll ls -lA # A righteous umask umask 22 set path = (/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/bin) setenv EDITOR vi setenv PAGER more setenv BLOCKSIZE K setenv PKG_DBDIR ~/db/pkg if ($?prompt) then # An interactive shell -- set some stuff up set filec set history = 100 set savehist = 100 set mail = (/var/mail/$USER) if ( $?tcsh ) then bindkey "^W" backward-delete-word bindkey -k up history-search-backward bindkey -k down history-search-forward endif endif
このファイルの最後に「set path = ($path $HOME/local/python/bin)」を追記したいのですが、手順が少しややこしいので下記の記事などを参考にしつつ行ってください。
以下の様に、ファイルの一番最後に一行だけ追記しました。
bindkey "^W" backward-delete-word bindkey -k up history-search-backward bindkey -k down history-search-forward endif endif set path = ($path $HOME/local/python/bin)
.cshrc で変更した内容を反映させます。
% source ~/.cshrc % rehash
パスを通す前はエラーが返ってきた「which」コマンドですが、今回はきちんと python3、pip3 のパスが表示されます。
% which python3 /home/XXXXXX/local/python/bin/python3 % which pip3 /home/XXXXXX/local/python/bin/pip3 %
バージョン情報もきちんと表示されます。
% python3 --version Python 3.9.0 % pip3 --version pip 20.2.3 from /home/XXXXXX/local/python/lib/python3.9/site-packages/pip (python 3.9) %
最後に圧縮ファイルのダウンロードに使ったフォルダとファイルを削除して完了です。
% rm -r ~/work/python3
冒頭でも触れましたが、Python プログラミングにレンタルサーバーは向いていません。
レンタルサーバーと VPS 両方試した上で VPS をお勧めしますので、下記の記事も参考にしていただければと思います。
▶︎【7社比較】レンタルサーバーの大クセ Python は本当は使いづらい!?
▶︎レンタルサーバーで Python は茨の道!VPS が楽得でおすすめ
と同時に、さくらのレンタルサーバーで Python3 をインストールしたみなさんであればもう下記の記事まで突っ走っても良いかもしれないとも思っています。
▶︎さくらレンタルサーバーでスクレイピング定期実行 & DB 保存
熱意に拍手を送ります。
まずログインに必要な情報を確認しておきます。
アカウント名と初期ドメインはさくらのレンタルサーバのコントロールパネルでも確認できます。
▶︎さくらのレンタルサーバ スタンダードのお申込みはこちら(公式ページ)
ターミナルを起動し、「ssh アカウント名@初期ドメイン」の形式で入力します。
例えば、アカウント名が「abcabc」、初期ドメインが「abcabc.sakura.ne.jp」だった場合、「ssh abcabc@abcabc.sakura.ne.jp」となります。入力して Enter。
% ssh abcabc@abcabc.sakura.ne.jp
初回は下記のようなメッセージが表示され、yes か no を求められますが、yes と入力して Enter で大丈夫です。
The authenticity of host 'アカウント名.sakura.ne.jp (XXX.XX.XXX.XX)' can't be established. ECDSA key fingerprint is XXXXXX:XxXXXxxXX+XXXXXXXXxxxxxxXXxXxxxxXXxXXXX. Are you sure you want to continue connecting (yes/no/[fingerprint])?
yes そして Enterすると下記のメッセージが表示され、続けてパスワードを求められます。
Warning: Permanently added 'アカウント名.sakura.ne.jp,XXX.XX.XXX.XX' (ECDSA) to the list of known hosts.
下記の様にパスワードを求められるので入力します。(タイプしても表示されないので注意)
abcabc@abcabc.sakura.ne.jp's password:
FreeBSD 9.1-RELEASE-p24 (SAKURA17) #0: Thu Feb 5 10:03:29 JST 2015 Welcome to FreeBSD! %
上記の様に「%」が表示されたら無事ログイン完了です。
ログインついでに現在インストールされている PHP のバージョンも確認してみます。コマンド「php –version」を実行します。
% php --version PHP 7.4.25 (cli) (built: Nov 11 2021 13:56:22) ( NTS ) Copyright (c) The PHP Group Zend Engine v3.4.0, Copyright (c) Zend Technologies with Zend OPcache v7.4.25, Copyright (c), by Zend Technologies %
と言うわけで現在は PHP 7.4.25 が入っていますね。
さくらのレンタルサーバ スタンダードプランの契約をしている人。FTPサーバーへアクセスが出来る人。
とりあえず独自ドメインの取得からWordPressサイトを解説まで、さくらのレンタルサーバーを使って進めていきます。
8ステップもあって初めてだと少し大変かもしれませんが、なるべく分かりやすい様に画像もたくさんつけているので1つずつやっていきましょう。
今回はみなさんが見ているこのサイト「notemite.jp」の立ち上げを例として進めていきます。
さくらのレンタルサーバ スタンダードのお申込みはこちら(公式ページ)
まずは独自ドメインを取得します。
ドメインとは「〇〇.com」や「〇〇.co.jp」など、ウェブサイトの住所のようなもので、独自ドメインを取得すればその文字列を自分の任意のものに出来ます。このステップで自分のウェブサイトの住所を取得しましょう。
さくらのレンタルサーバー管理画面 > ドメイン/SSL > 独自ドメイン申し込みをクリック。
遷移先のページで「新規追加」をクリックすると、下の画像の様にドメイン検索画面が表示されます。
もしくは下記リンクで直接ドメイン検索画面へ飛べます。
https://secure.sakura.ad.jp/order/domain/
この画面で自分が使いたいドメイン名を検索します。「notemite」で検索すると、notemite.jp や notemite.jp、notemite.org など、検索した文字列が含まれるドメイン名が表示されます。好みのものがあったら「申し込む」をクリックして手続きを進めます。
支払い方法を選択して進みます。私はクレジットカードを選択しました。
「この内容で申し込む」をクリックすると申し込みが送信されます。
申し込みを送信したら下記リンクから管理画面へ戻ります。
https://secure.sakura.ad.jp/menu/top/
「ドメインの確認」をクリックすると契約しているドメインが表示されます。
ドメイン申請後、契約ドメイン画面で有効期限が「新規申込中」となりますが、私の場合は10分ぐらいで下の画像の様に有効期限が表示され使用可能になりました。
上記の様な表示になったらドメインの取得は完了です。次は FTP サーバ上でこのドメインのフォルダを作ります。
ここから FTP クライアントでサーバーにアクセスしますが、Cyberduck を例に説明します。
Cyberduck を開いたら「新規接続」をクリックします。
さくらのレンタルサーバのコントロールパネル内に「FTP情報」を確認します。
サーバ、ユーザ名、パスワードを入力します。
FTPサーバでドメインのディレクトリ(フォルダ)を作成します。FTPサーバーの「www」フォルダにアクセスします。
*今回は notemite.jp のドメインを例として進めていきますので、既に取得している別のドメインのフォルダは黒塗りで隠しています。
使っているツールによって画面が違いますが、私が使っている Cyberduck ではこんな感じ。画面上部に /home/〇〇〇/www とある通り、FTP サーバーの「www」フォルダの中を表示している状態です。
今回はドメイン名そのままで「notemite」というフォルダを作成します。
「www」フォルダの中に「notemite」フォルダが作成されました。これでこのステップは完了です。
このステップでは、取得した独自ドメインをさくらレンタルサーバーの管理画面上で登録します。
さくらのレンタルサーバー管理画面 > ドメイン/SSL > ドメイン新規追加クリック
「Step2.ドメインの追加」の部分で対象のドメインを選択します。
「追加」ボタンをクリックすると、ドメインリストの中に取得したドメイン名が表示されます。
追加したドメインの「設定」ボタンをクリックします。
「マルチドメインとして利用する」を選択し、「Web公開フォルダ」では先ほどFTPサーバー上で作ったフォルダのパスを入力します。
「保存する」ボタンをクリックしてこのステップは完了です。
WordPress サイト上で作成したブログ記事やコメント、その他様々な設定は全てデータベースに保存されます。このステップではそのデータベースを作成します。
さくらレンタルサーバのコントロールパネル > データベース > 新規追加
好みのデータベース名を入力し「作成」をクリックします。
表示されるデータベースホスト(データベースサーバ)、ユーザー名、接続先パスワード、データベース名を後で使うのでメモしておきます。
WordPress に使用するデータベースが作成されました。これでこのステップは完了です。
さて、もうすぐ WordPress のインストールですが、その前にまた FTP サーバに戻って、先ほど作成した「notemite」フォルダ(皆さんはそれぞれ任意のフォルダ)の中にさらに WordPress 用のフォルダを作成します。
ディレクトリ内にWordpress専用のディレクトリ(フォルダを作成)(/wp/)を作成
ここでは好きなフォルダ名を付けていただいて大丈夫ですが、わかりやすく「wp」としておきます。
これで「notemite」フォルダの中に「wp」フォルダが作成されました。次のステップでこのフォルダの中に WordPress の全てがインストールされます。
まず、さくらのレンタルサーバ > サーバコントロールパネル > WordPressインストールを開きます。
すると様々な情報を入力する画面に切り替わります。
「インストールURL」の部分で、WordPress をインストールする場所を指定します。今回、notemite.jp の配下に「wp」フォルダを用意しています。なので下記の様に指定します。「インストール先ディレクトリ」が FTP サーバー上のフォルダと一致しています。
「テーブルの接頭語」は正直なんでも大丈夫ですが、立ち上げるサイトに関係ある言葉だとわかりやすいと思います。後でもう一度出てくるのでメモしておきましょう。
データベース名、ユーザー名、パスワード、ホスト名、テーブル接頭辞の入力を求められますが、これは先ほどさくらレンタルサーバの管理画面でデータベースを作成した時のものを入力します。
次にサイトのタイトル、そしてユーザー名とパスワード、メールアドレスを入力します。「検索エンジンでの表示」のチェックマークは入れずに「WordPressをインストール」をクリックします。
おつかれさまでした。これでWordPressサイトの立ち上げは完了です。
FTPサーバーの WordPress 用フォルダ(今回は「wp」フォルダ)にある index.php と .htaccess ファイルを、サイトのルートディレクトリ(「サイトのアドレス」)へコピーします。
移動ではなくあくまでコピーなので注意してください。
ファイルをコピーできたら、ドメインフォルダの index.php ファイルを開きます。
require から始まり ‘/wp-blog-header.php’; で終わる文があるので次の修正を行ないます。
WordPress 用に作ったフォルダ名「wp」を記述しました。
次は同じドメインフォルダの .htaccess ファイルを開きます。
「RewriteBase」と「RewriteRule」のところに「wp」フォルダの記述があるので削除します。
↑の赤線の部分を削除します。
「wp」フォルダの部分を削除して保存したら .htaccess の設定も完了です。
WordPress > 設定 > 一般設定 > サイトアドレス(URL)をから専用ディレクトリの箇所を消す
上の画像の様に「サイトアドレス(URL)」の部分が WordPress 用フォルダを含んだURLになっていると思いますが、これを削除します。
これでOK。「WordPress アドレス(URL)」の方は触らなくて大丈夫です。
「変更を保存」をクリックでこのステップも完了。お疲れ様でした!
この作業の後で必ず一度 WordPress からログアウトし再度ログインしてください。
私はこれをしなかったせいで設定が完全に反映されず、記事の投稿が上手くできない状態が半日続きました。。。
シェルスクリプトの記事を書く中で、投稿ページには「–」と書いていたのに公開された記事を確認したら「–」と表示されてしまっていた。
WordPress の投稿ページではきちんと「–」になっていました。
ところが、実際に公開されたページをみてみると下記の通り。
なぜか変わってしまっている。
調べてみると、WordPress の「wp-includes」フォルダ内「formatting.php」というファイルに記述されている関数「wptexturize()」が原因でした。
この関数はテキストを自動的に変換する機能で、例えばふつうの引用符をスマート引用符へ変えたり、特定の記号の並びをアポストロフィ、ダッシュ、省略符号(…)、商標記号、乗算記号などへ変えたり等、通常便利であろう変換を行うものです。
下の表はその自動変換がされる一例です。
元のテキスト | 変換されたテキスト | シンボル名 |
“—“ | “—” | em ダッシュ |
” — “ | “—” | em ダッシュ |
“–“ | “–” | en ダッシュ |
” – “ | “–” | en ダッシュ |
“…” | “…” | 省略記号 |
“ | “ | 開始引用符 |
“hello | “hello | 開始引用符 |
‘hello | ‘hello | 開始引用符 |
” | ” | 終了引用符 |
world.” | world.” | 終了引用符 |
world.’ | world.’ | 終了引用符 |
” ™” | ” ™” | 商標記号 |
1234″ | 1234″ | ダブルプライム記号 |
1234′ | 1234′ | プライム記号 |
’99 | ’99 | 西暦の省略表現前のアポストロフィ |
Webster’s | Webster’s | アポストロフィ |
1234×1234 | 1234×1234 | 乗算記号 |
ということですが、remove_filter() 関数を使ってこの自動変換(wptexturize)を止めることができる様なので、早速 function.php の一番下に下記コードを貼り付けます。
/*wptexturize 無効化*/ remove_filter( 'the_content', 'wptexturize' );
すると下の画像の通り、投稿ページで入力した通りの表記(–)が反映されました。
この時点で投稿内容では自動変換が止まりましたが、記事タイトル等に関してはまだ変換が行われる状態なので、もう一行追加します。
/*wptexturize 無効化*/ remove_filter( 'the_content', 'wptexturize' ); remove_filter( 'the_title', 'wptexturize' );
一行目の「the_content」の部分を「the_title」に変えただけです。これで記事タイトルに対しても自動変換がされなくなりました。
OS:Mac OS Catalina バージョン 10.15.4
まずはターミナル上で「brew update」を実行し、Homebrew 自体とインストール可能なソフトウェアのリストを更新します。
~ % brew update Updated 1 tap (homebrew/core). ==> Updated Formulae acpica imagemagick nss solr atlantis imagemagick@6 onnxruntime solr@7.7 efl kyma-cli operator-sdk stellar-core evince lazydocker pandoc-crossref terragrunt exploitdb lerna picard-tools vault fcct librsvg plantuml vim firebase-cli mavsdk pnpm vte3 gatsby-cli mu prestosql watson helmfile ncdu re-flex hlint node-sass redis ~ %
ターミナル上で「brew install wget」を実行すると、Wget のインストール処理が始まります。
~ % brew install wget ==> Downloading https://homebrew.bintray.com/bottles/gettext-0.20.2_1.catalina.b ==> Downloading from https://akamai.bintray.com/71/71f4ded03e8258b5e6896eebb00d2 ######################################################################## 100.0% ==> Downloading https://homebrew.bintray.com/bottles/libunistring-0.9.10.catalin ==> Downloading from https://akamai.bintray.com/ce/ce746662b98d93511b86920011b5c ######################################################################## 100.0% ==> Downloading https://homebrew.bintray.com/bottles/libidn2-2.3.0.catalina.bott ==> Downloading from https://akamai.bintray.com/09/0908585cca518a83f101b2edc0417 ######################################################################## 100.0% ==> Downloading https://homebrew.bintray.com/bottles/openssl%401.1-1.1.1g.catali ==> Downloading from https://akamai.bintray.com/19/1926679569c6af5337de812d86f4d ######################################################################## 100.0% ==> Downloading https://homebrew.bintray.com/bottles/wget-1.20.3_2.catalina.bott ==> Downloading from https://akamai.bintray.com/ef/ef65c759c5097a36323fa9c777564 ######################################################################## 100.0% ==> Installing dependencies for wget: gettext, libunistring, libidn2 and openssl@1.1 ==> Installing wget dependency: gettext ==> Pouring gettext-0.20.2_1.catalina.bottle.tar.gz 🍺 /usr/local/Cellar/gettext/0.20.2_1: 1,923 files, 18.6MB ==> Installing wget dependency: libunistring ==> Pouring libunistring-0.9.10.catalina.bottle.tar.gz 🍺 /usr/local/Cellar/libunistring/0.9.10: 54 files, 4.4MB ==> Installing wget dependency: libidn2 ==> Pouring libidn2-2.3.0.catalina.bottle.tar.gz 🍺 /usr/local/Cellar/libidn2/2.3.0: 70 files, 727.8KB ==> Installing wget dependency: openssl@1.1 ==> Pouring openssl@1.1-1.1.1g.catalina.bottle.tar.gz ==> Caveats A CA file has been bootstrapped using certificates from the system keychain. To add additional certificates, place .pem files in /usr/local/etc/openssl@1.1/certs and run /usr/local/opt/openssl@1.1/bin/c_rehash openssl@1.1 is keg-only, which means it was not symlinked into /usr/local, because macOS provides LibreSSL. If you need to have openssl@1.1 first in your PATH run: echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc For compilers to find openssl@1.1 you may need to set: export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" ==> Summary 🍺 /usr/local/Cellar/openssl@1.1/1.1.1g: 8,059 files, 18MB ==> Installing wget ==> Pouring wget-1.20.3_2.catalina.bottle.tar.gz 🍺 /usr/local/Cellar/wget/1.20.3_2: 50 files, 4.0MB ==> Caveats ==> openssl@1.1 A CA file has been bootstrapped using certificates from the system keychain. To add additional certificates, place .pem files in /usr/local/etc/openssl@1.1/certs and run /usr/local/opt/openssl@1.1/bin/c_rehash openssl@1.1 is keg-only, which means it was not symlinked into /usr/local, because macOS provides LibreSSL. If you need to have openssl@1.1 first in your PATH run: echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc For compilers to find openssl@1.1 you may need to set: export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib" export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include" ~ %
入力待ち状態になったら完了です。途中ビールのアイコンが表出されるのかわいいですね。
インストールが完了した後、ターミナルで「wget –version」を実行すると、Wget のバージョン情報や著作権に関する案内、バグ報告の質問の連絡先が表出されます。
~ % wget --version GNU Wget 1.20.3 built on darwin19.0.0. -cares +digest -gpgme +https +ipv6 +iri +large-file -metalink +nls +ntlm +opie -psl +ssl/openssl Wgetrc: /usr/local/etc/wgetrc (system) ロケール: /usr/local/Cellar/wget/1.20.3_2/share/locale コンパイル: clang -DHAVE_CONFIG_H -DSYSTEM_WGETRC="/usr/local/etc/wgetrc" -DLOCALEDIR="/usr/local/Cellar/wget/1.20.3_2/share/locale" -I. -I../lib -I../lib -I/usr/local/opt/openssl@1.1/include -DNDEBUG -g -O2 リンク: clang -DNDEBUG -g -O2 -lidn2 -L/usr/local/opt/openssl@1.1/lib -lssl -lcrypto -ldl -lz ftp-opie.o openssl.o http-ntlm.o ../lib/libgnu.a -liconv -lintl -Wl,-framework -Wl,CoreFoundation -lunistring Copyright (C) 2015 Free Software Foundation, Inc. ライセンス GPLv3+: GNU GPL バージョン 3 あるいはそれ以降のバージョン <http://www.gnu.org/licenses/gpl.html>. このソフトウェアはフリーソフトウェアです。自由に変更、再配布ができます。 法律が許すかぎり、全くの無保証です。 Hrvoje Niksic <hniksic@xemacs.org> によって書かれました。 バグ報告や質問は<bug-wget@gnu.org>へ ~ %
Homebrew を Macbook へインストールする際のステップです。
OS:Mac OS Catalina バージョン 10.15.4
Homebrew の公式サイトへアクセス。
トップページに表示されているコードをコピーし、ターミナルへペースト&「Enter」
*コードは 2020 年 5 月時点のものです。
~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
するとまず下記の通りインストール時に何が起こるかの説明が表示されます。
==> This script will install: /usr/local/bin/brew /usr/local/share/doc/homebrew /usr/local/share/man/man1/brew.1 /usr/local/share/zsh/site-functions/_brew /usr/local/etc/bash_completion.d/brew /usr/local/Homebrew ==> The following existing directories will be made group writable: /usr/local/bin /usr/local/lib /usr/local/share ==> The following existing directories will have their owner set to *****: /usr/local/bin /usr/local/lib /usr/local/share ==> The following existing directories will have their group set to admin: /usr/local/bin /usr/local/share ==> The following new directories will be created: /usr/local/etc /usr/local/include /usr/local/sbin /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks ==> The Xcode Command Line Tools will be installed. Press RETURN to continue or any other key to abort
そのままリターンキーを叩くとパスワード確認後インストールへ。他のキーを叩くと切断されます。ということでリターンキーをポチ。
==> /usr/bin/sudo /bin/chmod u+rwx /usr/local/bin /usr/local/lib /usr/local/share ==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/bin /usr/local/lib /usr/local/share ==> /usr/bin/sudo /usr/sbin/chown ***** /usr/local/bin /usr/local/lib /usr/local/share ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/bin /usr/local/share ==> /usr/bin/sudo /bin/mkdir -p /usr/local/etc /usr/local/include /usr/local/sbin /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks ==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/etc /usr/local/include /usr/local/sbin /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks ==> /usr/bin/sudo /usr/sbin/chown ***** /usr/local/etc /usr/local/include /usr/local/sbin /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks ==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/etc /usr/local/include /usr/local/sbin /usr/local/var /usr/local/opt /usr/local/share/zsh /usr/local/share/zsh/site-functions /usr/local/var/homebrew /usr/local/var/homebrew/linked /usr/local/Cellar /usr/local/Caskroom /usr/local/Homebrew /usr/local/Frameworks ==> /usr/bin/sudo /bin/mkdir -p /Users/*****/Library/Caches/Homebrew ==> /usr/bin/sudo /bin/chmod g+rwx /Users/*****/Library/Caches/Homebrew ==> /usr/bin/sudo /usr/sbin/chown ***** /Users/*****/Library/Caches/Homebrew ==> Searching online for the Command Line Tools ==> /usr/bin/sudo /usr/bin/touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress ==> Installing Command Line Tools for Xcode-11.5 ==> /usr/bin/sudo /usr/sbin/softwareupdate -i Command\ Line\ Tools\ for\ Xcode-11.5 Software Update Tool Downloading Command Line Tools for Xcode
上記の最後の行、「Xcode 用のコマンドラインツールをダウンロードしています」で一旦止まりますがそのまま待ちます。
その後下記の様な表示がされます。
Downloading Command Line Tools for Xcode Downloaded Command Line Tools for Xcode Installing Command Line Tools for Xcode Done with Command Line Tools for Xcode Done. ==> /usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress Password:
Xcode 用 コマンドラインツールのダウンロード&インストールの完了、そしてパスワードを再度求められます。
パスワードを入力すると再度処理が始まりズラズラっとターミナル上に表出されていきます。
Password: ==> /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools ==> Downloading and installing Homebrew... remote: Enumerating objects: 68, done. remote: Counting objects: 100% (68/68), done. remote: Compressing objects: 100% (64/64), done. remote: Total 137483 (delta 5), reused 55 (delta 4), pack-reused 137415 Receiving objects: 100% (137483/137483), 33.39 MiB | 346.00 KiB/s, done. Resolving deltas: 100% (101071/101071), done. From https://github.com/Homebrew/brew * [new branch] master -> origin/master * [new tag] 2.3.0 -> 2.3.0 〜一部省略〜 * [new tag] 2.2.9 -> 2.2.9 HEAD is now at 77e09fc16 Merge pull request #7661 from MikeMcQuaid/man-url-install ==> Homebrew is run entirely by unpaid volunteers. Please consider donating: https://github.com/Homebrew/brew#donations ==> Tapping homebrew/core Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'... remote: Enumerating objects: 726765, done. remote: Total 726765 (delta 0), reused 0 (delta 0), pack-reused 726765 Receiving objects: 100% (726765/726765), 294.50 MiB | 324.00 KiB/s, done. Resolving deltas: 100% (480049/480049), done. Tapped 2 commands and 5029 formulae (5,298 files, 322.8MB). Already up-to-date. ==> Installation successful! ==> Homebrew has enabled anonymous aggregate formulae and cask analytics. Read the analytics documentation (and how to opt-out) here: https://docs.brew.sh/Analytics No analytics data has been sent yet (or will be during this `install` run). ==> Homebrew is run entirely by unpaid volunteers. Please consider donating: https://github.com/Homebrew/brew#donations ==> Next steps: - Run `brew help` to get started - Further documentation: https://docs.brew.sh ~ %
上記の中盤過ぎに「==> Installation successful!」と表示が出ているので問題なく処理が完了した様です。
「ターミナルで brew help と入力すればいくつか情報が得られるし、https://docs.brew.sh にもより詳細な情報があるよ」とのこと。ちなみに「brew help」を実行すると下記の内容が表示されます。
~ % brew help Example usage: brew search [TEXT|/REGEX/] brew info [FORMULA...] brew install FORMULA... brew update brew upgrade [FORMULA...] brew uninstall FORMULA... brew list [FORMULA...] Troubleshooting: brew config brew doctor brew install --verbose --debug FORMULA Contributing: brew create [URL [--no-fetch]] brew edit [FORMULA...] Further help: brew commands brew help [COMMAND] man brew https://docs.brew.sh
いまいちよく分からないですね!ひとまず一旦無視して追々必要に応じて調べていこうと思います。
ターミナルに「brew –version」と入力して Enter。ちゃんとどのバージョンがインストールされているか表示されています。ということでインストールはOKです。
~ % brew --version Homebrew 2.3.0 Homebrew/homebrew-core (git revision 2adae5; last commit 2020-05-30) ~ %
Mac で Python の Beautifulsoup4 をインストールする方法を記載します。
OS: macOS Catalina バージョン 10.15.4
Python: Python 3.8.3
ターミナルを立ち上げてコマンド「pip3 install beautifulsoup4」と入力し、Enter。
~ % pip3 install beautifulsoup4
すると下記の様なログが書き出されます。
~ % pip3 install beautifulsoup4 Collecting beautifulsoup4 Downloading https://files.pythonhosted.org/packages/66/25/ff030e2437265616a1e9b25ccc864e0371a0bc3adb7c5a404fd661c6f4f6/beautifulsoup4-4.9.1-py3-none-any.whl (115kB) |████████████████████████████████| 122kB 635kB/s Collecting soupsieve>1.2 (from beautifulsoup4) Downloading https://files.pythonhosted.org/packages/6f/8f/457f4a5390eeae1cc3aeab89deb7724c965be841ffca6cfca9197482e470/soupsieve-2.0.1-py3-none-any.whl Installing collected packages: soupsieve, beautifulsoup4 Successfully installed beautifulsoup4-4.9.1 soupsieve-2.0.1 WARNING: You are using pip version 19.2.3, however version 20.1 is available. You should consider upgrading via the 'pip install --upgrade pip' command. ~ %
一瞬でダウンロードとインストールが完了し、入力待ち状態になりました。これで完了です。