LoginSignup
6
6

More than 5 years have passed since last update.

Cygwinインストールメモ

Last updated at Posted at 2017-04-23

Cygwinのインストール

 CygwinのインストーラはCygwinからダウンロードできます。
 32ビット版と64ビット版があります。CPU/OSに合わせた方をダウンロードし、インストールします。

懸念事項

 cygwin1.dllがインストールされるフォルダにパスを通しておくと、コマンドプロンプトからCygwinのコマンドが実行できるようになります。
 ですが、cygwin1.dllのフォルダにパスを通しておくと、なぜか、Cygwinのパッケージ追加・削除時に5時間くらいかかる現象が、稀によく発生することがあります。Windows10再インストール時にCygwinを再インストールし、cygwin1.dll格納フォルダにパスを通さずに運用したところ、再インストール前に発生していた、謎の超長時間インストールの現象が発生しなくなりました。何かのバグが直っただけかもしれませんが...
2017年6月25日追記
 Cygwinのパッケージ追加・削除時に5時間くらいかかる現象ですが、上記のパスの設定ではなく、Visual Studio 20xxをインストールしたことの影響のようです。Visual Studio 2015 Communityをインストールしたところ100%の確立で再現するようになりました。
 Visual StudioをインストールするPCではCygwinではなくBash on Ubuntu on Windowsの方が安全かもです。

apt-cyg

 apt-cygをインストールしておくと、Debian Linuxのapt-getの要領でパッケージ管理ができるようになります。
 apt-cygはkou1okada/apt-cygで開発されているbashスクリプトで、gnupg、gawk、wgetがインストールされている必要があります。

apt-cygのインストール方法

a. cygwinインストーラでgnupg、gawk、wgetをインストールする。
b. kou1okada/apt-cygからapt-cygをダウンロードする。
c. apt-cygに実行権限を追加する。
$ chmod +x apt-cyg
d. 初期のリポジトリ設定を実行する。
$ apt-cyg -m ftp://ftp.jaist.ac.jp/pub/cygwin/ update

この後、
$ apt-cyg install <package-name>
で、指定したパッケージと依存関係にあるパッケージをインストールしてくれるようになります。
apt-cygのコマンドオプションはapt-cyg/README.mdに書かれています。

C言語開発に必要(そうな)パッケージのインストール

$ apt-cyg install autoconf automake binutils gettext gettext-devel \
    gcc gcc-core gcc-g++ gdb \
    gcc-mingw gcc-mingw-core gcc-mingw-g++ mingw-runtime \
    libgcrypt-devel libiconv libtool nasm patchutils pkg-config ncurses expat

Apache2のインストール

$ apt-cyg install apache2

httpdコマンドによる起動と停止

  • Apacheの起動
    $ /usr/sbin/httpd.exe -k start

  • Apacheの停止
    $ /usr/sbin/httpd.exe -k stop

WindowsのサービスとしてApacheを登録する

  • Windowsのサービスとして登録する
    $ cygrunsrv -I apache2 -d "Cygwin Apache2" -p /usr/sbin/httpd2 -a -DFOREGROUND -e "CYGWIN=server"

  • Apacheサービスの起動
    $ cygrunsrv -S apache2

  • Apacheサービスの終了:サービス終了
    $ cygrunsrv -E apache2

  • Apacheサービスの削除
    $ cygrunsrv -R apache2

httpd.conf

ユーザディレクトリの公開

/etc/httpd/conf/httpd.confの変更
#LoadModule userdir_module modules/mod_userdir.so
↓ mod_userdir.soのLoad設定を有効にする
LoadModule userdir_module modules/mod_userdir.so

#User home directories
#Include conf/extra/httpd-userdir.conf
↓ userdir.confの読込みを有効にする
Include conf/extra/httpd-userdir.conf

Cygwin Apache2でPHPを使う

apacheのphpモジュールのインストール

$ apt-cyg install httpd-mod_php7

動作確認

/srv/www/test.phpを下記の内容で作成

/srv/www/test.php
<? phpinfo(); ?>

ブラウザで http://localhost/test.php を参照し、PHPの設定情報が表示されれば、正しく設定されています。

Cygwin Apache2でPythonを使う

apacheのphpモジュールのインストール

$ apt-cyg install python-httplib2

/etc/httpd/conf/httpd.confの設定変更

/etc/httpd/conf/httpd.confの変更箇所
#LoadModule cgi_module modules/mod_cgi.so
↓ mod_cgi.soの有効か
LoadModule cgi_module modules/mod_cgi.so

#AddHandler cgi-script .cgi
↓ 拡張子.cgiの設定追加
AddHandler cgi-script .cgi

動作確認

下記の内容で/srv/www/cgi-bin/test.cgiを作成
/srv/www/cgi-bin/test.cgi
#!/usr/bin/python
print 'Content-Type: text/html\n\n'
print "Hello Work ... orz"
パーミッション変更

$ chmod 755 /srv/www/cgi-bin/test.cgi

ブラウザで http://localhost/cgi-bin/test.cgi を参照し、「Hello Work ... orz」が表示されれば設定完了です。

MySQLのインストール

$ apt-cyg install mysql mysql-server

初期設定

管理者権限でCygwinを起動し、mysql_install_dbコマンドの実行

$ mysql_install_db

・・・結構時間かかる・・・

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MariaDB root USER !
To do so, start the server, then issue the following commands:

'/usr/bin/mysqladmin' -u root password 'new-password'
'/usr/bin/mysqladmin' -u root -h hogehoge password 'new-password'

Alternatively you can run:
'/usr/bin/mysql_secure_installation'

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the MariaDB Knowledgebase at http://mariadb.com/kb or the
MySQL manual for more instructions.

You can start the MariaDB daemon with:
cd '/usr' ; /usr/bin/mysqld_safe --datadir='/var/lib/mysql'

You can test the MariaDB daemon with mysql-test-run.pl
cd '/usr/mysql-test' ; perl mysql-test-run.pl

Please report any problems at http://mariadb.org/jira

The latest information about MariaDB is available at http://mariadb.org/.
You can find additional information about the MySQL part at:
http://dev.mysql.com
Support MariaDB development by buying support/new features from MariaDB
Corporation Ab. You can contact us about this at sales@mariadb.com.
Alternatively consider joining our community based development effort:
http://mariadb.com/kb/en/contributing-to-the-mariadb-project/

設定ファイルのコピー

$ cp /usr/share/mysql/my-medium.cnf /etc/my.cnf

MySQLサーバの起動

$ /usr/bin/mysqld_safe --datadir='/var/lib/mysql' &

root権限でMySQLサーバに接続

$ mysql -u root

MySQLのrootパスワードの設定

mysql> SET PASSWORD FOR root@localhost=PASSWORD('ここにパスワードを指定');

MySQL接続ユーザの確認

mysql> SELECT user,host from mysql.user;

MySQLサーバの停止

$ kill `cat /usr/local/mysql/data/ホスト名.pid`

mysql_install_dbの実行ログを見た感じ、support-files/mysql.serverで起動制御できそうですが、件のファイルがどこにあるのかわかりませんでした。昔は、/usr/share/mysqlにインストールされたのですが...

PostgreSQLのインストール

$ apt-cyg install postgresql postgresql-client

初期設定

 管理者権限でcygserver-configを実行し、cygserverの設定が必要です。
 一見、postgresqlとは関係なさそうに見えますが、Linuxカーネルが提供している共有メモリの仕組みをCygwin上で実行するためには必要なおまじないのようで、cygserverが起動していない状態でpg_ctl initを実行しても、途中でエラー終了します。

cygserver-configの実行

$ cygserver-config
Overwrite existing /etc/cygserver.conf file? (yes/no) yes
Generating /etc/cygserver.conf file


Warning: The following function requires administrator privileges!

Do you want to install cygserver as service?
(Say "no" if it's already installed as service) (yes/no) yes

The service has been installed under LocalSystem account.
To start it, call `net start cygserver' or `cygrunsrv -S cygserver'.

Further configuration options are available by editing the configuration
file /etc/cygserver.conf.  Please read the inline information in that
file carefully. The best option for the start is to just leave it alone.

Basic Cygserver configuration finished. Have fun!

cygserverの起動

$ cygrunsrv -S cygserver

cygserver起動後、pg_ctlコマンドを実行するとエラー終了しないはずです。

SSH Server

インストール

$ atp-cyg install openssh

設定

 管理者モードでCygwinを起動し、

$ ssh-host-config

を実行します。コンフィグ設定中に、いくつか質問されますが、ほとんどyesで問題ないはずです。
ssh-host-configでWindowsサービスとしてCygwin SSHを登録した場合、下記のコマンドでCygwin SSHの起動、停止を実行で決ます。

  • Cygwin SSHサービスの起動
    $ cygrunsrv -S sshd

  • Cygwin SSHサービスの起動
    $ cygrunsrv -E sshd

Cygwinをアンインストールする等の理由でCygwin SSHサービスを削除したい場合は、

$ cygrunsrv -R sshd

で削除します。

SSHログインアカウント

 ssh-host-configコマンドを実行すると、Windowsの登録アカウントをもとにSSHログインアカウントが作成されます。が、Microsoftアカウントの場合、Windows上に保存されるアカウント名が若干短縮されることがあり、SSHログインするときに苦慮することがあります。
 C:\Users\の下の、たぶんこれだろうと思えるフォルダ名と、Windowsログインパスワードの組み合わせでSSHログインできるはずです。

Windows機能の利用

Windowsのファイルシステムを参照する

$ cd cd /cygdrive/c/

でCドライブが参照できます。Dドライブ以降は察してください。

データCD/DVDのisoイメージ作成

 雑誌付録のデータCD/DVDを、バックアップがてらisoイメージで保存したい場合、下記のコマンドを管理者権限で実行するとisoイメージを作成できます。

$ dd if=/dev/scd0 of=data.iso

最近のノートPCはCD/DVDドライブ付いてないし、資格試験の問題集とかの付属DVDを入れ替える時とかに便利です。
ちなみに、音楽CDや映画/アニメ等の市販のDVDのisoイメージファイルは作れません。

6
6
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6