##序章

LAMPスタックは、Webサーバーを稼働させるために使用されるオープンソースソフトウェアのグループです。 頭字語は、Linux、Apache、MySQL、およびPHPの略です。 サーバーはすでにFedoraを実行しているので、Linux部分が処理されます。 残りをインストールする方法は次のとおりです。

前提条件

このtutorailを開始する前に、Fedora 22ドロップレットを実行し、SSH経由でログインする必要があります。

##設定

LAMPプログラムのインストールを開始する前に、まずすべての更新をダウンロードしてインストールする必要があります。バージョン22では、Fedoraのデフォルトのパッケージマネージャーとしてdnfupdatednfがyumに置き換えられています。

sudo dnf update

##ステップ1-Apacheをインストールする

Apacheは、世界のWebサーバーの50% of以上で実行される無料のオープンソースソフトウェアです。

apacheをインストールするには、ターミナルを開き、次のコマンドを入力します。

sudo dnf install httpd

インストールすると、VPSでApacheの実行を開始できます。

sudo systemctl start httpd.service

それでおしまい。 Apacheがインストールされているかどうかを確認するには、ブラウザをサーバーのIPアドレスに誘導します(例: http://12.34.56.789 )。 デフォルトのFedoraページが表示されます

###ドロップレットのIPアドレスを見つける方法

次のコマンドを実行して、サーバーのIPアドレスを明らかにすることができます。

ifconfig eth0 | grep inet | awk '{ print $2 }'

##ステップ2—MySQLをインストールする

MySQL / MariaDBは、仮想サーバー上のデータを整理および取得するために使用される強力なデータベース管理システムです。

MySQLをインストールするには、ターミナルを開き、次のコマンドを入力します。

sudo dnf install mysql mysql-server
sudo systemctl start mariadb.service

インストールが完了したら、ルートMySQLパスワードを設定できます。

sudo /usr/bin/mysql_secure_installation

プロンプトで、現在のルートパスワードの入力を求められます。

MySQLをインストールしたばかりなので、MySQLがない可能性が高いので、Enterキーを押して空白のままにします。

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

次に、rootパスワードを設定するかどうかを尋ねるプロンプトが表示されます。 先に進み、Yを選択して、指示に従います。

Fedoraは、MySQLのセットアッププロセスを自動化し、一連の「はい」または「いいえ」の質問をします。

すべてのオプションに「はい」と言うのが最も簡単です。 最後に、MySQLは新しい変更をリロードして実装します。

<pre>By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

##ステップ3—PHPをインストールする

PHPは、動的Webページの作成に広く使用されているオープンソースのWebスクリプト言語です。

仮想プライベートサーバーにPHPをインストールするには、ターミナルを開いて次のコマンドを入力します。

sudo dnf install php php-mysql

PHPプロンプトに「はい」と答えると、PHPはそれ自体をインストールします。

###PHPモジュール

PHPには、サーバーに追加できるさまざまな便利なライブラリとモジュールもあります。 次のように入力すると、使用可能なライブラリを確認できます。

dnf search php-

ターミナルは、可能なモジュールのリストを表示します。 最初は次のようになります。

php-fpdf-doc.noarch : Documentation for php-fpdf
php-libvirt-doc.noarch : Document of php-libvirt
php-pear-Auth-radius.noarch : RADIUS support for php-pear-Auth
php-pear-Auth-samba.noarch : Samba support for php-pear-Auth
ice-php-devel.i686 : PHP tools for developping Ice applications
ice-php-devel.x86_64 : PHP tools for developping Ice applications
perl-PHP-Serialization.noarch : Converts between PHP's serialize() output and
                              : the equivalent Perl structure
php-IDNA_Convert.noarch : Provides conversion of internationalized strings to
                        : UTF8
php-Kohana.noarch : The Swift PHP Framework
php-LightweightPicasaAPI.noarch : A lightweight API for Picasa in PHP
php-PHPMailer.noarch : PHP email transport class with a lot of features
php-Smarty.noarch : Template/Presentation Framework for PHP
php-ZendFramework.noarch : Leading open-source PHP framework
php-ZendFramework-Auth-Adapter-Ldap.noarch : Zend Framework LDAP
                                           : Authentication Adapter
php-ZendFramework-Cache-Backend-Apc.noarch : Zend Framework APC cache backend

各モジュールの機能の詳細を確認するには、ターミナルに次のコマンドを入力し、モジュールの名前を学習したいライブラリに置き換えます。

dnf info name of the module

モジュールをインストールすることを決定したら、次のように入力します。

sudo dnf install name of the module

各モジュールの名前をスペースで区切ることにより、一度に複数のライブラリをインストールできます。

おめでとう! これで、ドロップレットにLAMPスタックができました。

また、サーバーの起動時にプロセスが自動的に実行されるように設定する必要があります(Apacheが起動するとphpが自動的に実行されます)。

sudo chkconfig httpd on
sudo chkconfig mariadb on

##ステップ4—結果:サーバーでPHPを確認する

LAMPは仮想サーバーにインストールされていますが、簡単なphp情報ページを作成することで、コンポーネントをオンラインで確認できます。

これを設定するには、最初にnanoテキストエディタをインストールし、新しいファイルを作成します。

sudo dnf install nano
sudo nano /var/www/html/info.php

次の行を追加します。

<?php
phpinfo();
?>

次に、保存して終了します。

apacheを再起動して、すべての変更が仮想サーバーで有効になるようにします。

sudo systemctl restart httpd.service

最後に、php情報ページにアクセスします(例のIPアドレスを正しいアドレスに置き換えてください): http://12.34.56.789/info.php

これは次のようになります。