MySQLをXAMPPでLinuxにインストールする方法をまとめています。
XAMPPは、Windows、Mac OS、Linux(Debian, RedHat, CentOS, Ubuntu, Fedora, Gentoo, Arch, SUSEに対応)にMariaDB、PHP、Perl、Apacheが簡単にインストールできるツールです。
現在のXAMPPは、MySQLではなく過去にMySQLから派生(フォーク)したMariaDBというデータベースをインストールします。
今回は、Linux(Ubuntu 19.10)にxammpを使ってMySQLをインストールする方法を解説します。


XAMPPのダウンロード&インストール
XAMPP Installers and Downloads for Apache Friends (xampp 公式サイト)
wgetコマンドでインストーラをダウンロードします。
ファイルのパスは、公式サイトの「Linux向けXAMPP」のダウンロードリンクのパスを指定してください。
- $ wget https://www.apachefriends.org/xampp-files/7.4.1/xampp-linux-x64-7.4.1-1-installer.run
- --2020-01-25 04:01:44-- https://www.apachefriends.org/xampp-files/7.4.1/xampp-linux-x64-7.4.1-1-installer.run
- Resolving www.apachefriends.org (www.apachefriends.org)... 3.225.120.173, 107.21.20.65, 107.23.159.238
- :
- :
chmodでインストーラに実行権限を付与し、sudoで実行します。今回は全てのファイルをインストールしましたが、不要な場合はDeveloper用ファイルはインストールしないようにしてください。
- $ chmod +x ./xampp-linux-x64-7.4.1-1-installer.run
- $ ./xampp-linux-x64-7.4.1-1-installer.run
- Error: There has been an error.
- This installer requires root privileges. Please become superuser before
- executing the installer
- Press [Enter] to continue:
- $ sudo ./xampp-linux-x64-7.4.1-1-installer.run
- ----------------------------------------------------------------------------
- Welcome to the XAMPP Setup Wizard.
- ----------------------------------------------------------------------------
- Select the components you want to install; clear the components you do not want
- to install. Click Next when you are ready to continue.
- XAMPP Core Files : Y (Cannot be edited)
- XAMPP Developer Files [Y/n] :y
- Is the selection above correct? [Y/n]: y
- ----------------------------------------------------------------------------
- Installation Directory
- XAMPP will be installed to /opt/lampp
- Press [Enter] to continue:
- ----------------------------------------------------------------------------
- Setup is now ready to begin installing XAMPP on your computer.
- Do you want to continue? [Y/n]: y
- ----------------------------------------------------------------------------
- Please wait while Setup installs XAMPP on your computer.
- Installing
- 0% ______________ 50% ______________ 100%
- #########################################
- ----------------------------------------------------------------------------
- Setup has finished installing XAMPP on your computer.
インストールが完了すると、xamppのサービスと、Apache、MySQL、FTPDが自動的に起動します。
XAMPPの起動確認は、xampp statusで確認
以下のコマンドで起動状態を確認できます。
- $ cd /opt/lampp
- $ sudo ./xampp status
- Version: XAMPP for Linux 7.4.1-1
- Apache is running.
- MySQL is running.
- ProFTPD is running.
また、ブラウザでhttp://localhostを開くと、以下の画面が開き、Webサーバサービス・Apacheが動作していることを確認できます。
xamppサービスの起動と停止コマンド
以下のコマンドでサービスの起動停止が可能です。
- sudo /opt/lampp/xampp start サービス起動
- sudo /opt/lampp/xampp stop サービス停止
起動・停止時にnetstat: command not foundが表示される場合は、sudo apt-get install net-tools でnetstatコマンドをインストールしてください。
- $ sudo /opt/lampp/xampp start
- XAMPP: Starting Apache.../opt/lampp/share/xampp/xampplib: line 22: netstat: command not found
- /opt/lampp/share/xampp/xampplib: line 22: netstat: command not found
- ok.
- XAMPP: Starting MySQL.../opt/lampp/share/xampp/xampplib: line 22: netstat: command not found
- ok.
- XAMPP: Starting ProFTPD.../opt/lampp/share/xampp/xampplib: line 22: netstat: command not found
- ok.
GUIのコントロールパネルを表示する
GUIコントロールパネルを表示する場合は、以下のコマンドを実行します。
- $ cd /opt/lampp/
- $ sudo ./manager-linux-x64.run
XAMPPのセキュリティ対策を最低限実施するユーティリティ
xampはデフォルトインストール直後は、下記の点でセキュリティ面に問題があります。
- MySQLにネットワーク経由でアクセス可能になっている
- phpMyAdmin用のユーザpmaにパスワードが設定されていない
- MySQLのrootユーザにパスワードが設定されていない
- phpMyAdminのrootユーザにパスワードが設定されていない
- ユーザdaemonのFTPパスワードがxamppに設定されている
上記に最低限対応するには、以下のコマンドを実行します。実行途中で、パスワードの入力等が必要になります。
- $ sudo /opt/lampp/lampp security
- XAMPP: Quick security check...
- XAMPP: MySQL is accessable via network.
- XAMPP: Normaly that's not recommended. Do you want me to turn it off? [yes] yes
- XAMPP: Turned off.
- XAMPP: Stopping MySQL...ok.
- XAMPP: Starting MySQL...ok.
- XAMPP: The MySQL/phpMyAdmin user pma has no password set!!!
- XAMPP: Do you want to set a password? [yes] yes
- XAMPP: Password:
- XAMPP: Password (again):
- XAMPP: Setting new MySQL pma password.
- XAMPP: Setting phpMyAdmin's pma password to the new one.
- XAMPP: MySQL has no root passwort set!!!
- XAMPP: Do you want to set a password? [yes] yes
- XAMPP: Write the password somewhere down to make sure you won't forget it!!!
- XAMPP: Password:
- XAMPP: Password (again):
- XAMPP: Setting new MySQL root password.
- XAMPP: Change phpMyAdmin's authentication method.
- XAMPP: The FTP password for user 'daemon' is still set to 'xampp'.
- XAMPP: Do you want to change the password? [yes] yes
- XAMPP: Password:
- XAMPP: Password (again):
- XAMPP: Reload ProFTPD...ok.
- XAMPP: Done.
MariaDBに接続確認を行う
以下のコマンドで、MariaDBとの接続確認をおこないます。
コマンドのパスが通っていないため、フルパスでmysqlコマンドを指定します。
- $ /opt/lampp/bin/mysql -u root -p
- Enter password:
- Welcome to the MariaDB monitor. Commands end with ; or \g.
- Your MariaDB connection id is 17
- Server version: 10.4.11-MariaDB Source distribution
- Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
- Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
- MariaDB [(none)]>
まとめ

- XAMPPでインストールされるのは、MySQLではなくMariaDB
- デフォルトインストール直後は、セキュリティ的に問題あり
- LinuxでGUIのコントロールパネルを使って、サービスの起動停止も可能