Magentoインストール · 5 min read · Nov 26, 2025
Ubuntu 20.04におけるApache2とLet's Encryptを使用したMagento E-Commerceプラットフォームのインストール

Magentoは、数分で完全に機能するeCommerceストアを作成できる無料のオープンソースのeコマースWebアプリケーションです。PHPで書かれており、強力な機能と柔軟性、ユーザーフレンドリーなインターフェースを組み合わせています。シンプルさと強力な管理パネルにより、自己ホスト型オンラインストアの最も人気のあるソリューションの1つです。サイト管理、SEO、カタログ管理、製品およびカタログのブラウジング、注文管理、チェックアウト、プロモーションおよびコンバージョンツールなど、豊富な機能セットが付属しています。
このチュートリアルでは、Ubuntu 20.04にApacheとLet’s Encrypt SSLを使用してMagento E-commerceプラットフォームをインストールする方法を示します。
前提条件
- 4 GBのRAMを搭載したUbuntu 20.04を実行しているサーバー。
- サーバーにポイントされた有効なドメイン名。
- サーバーに設定されたrootパスワード。
LAMPサーバーのインストール
MagentoはWebサーバー上で動作し、PHPで書かれており、データベースとしてMariaDBを使用します。したがって、サーバーにLAMPスタックをインストールする必要があります。
まず、次のコマンドを使用してApache WebサーバーとMariaDBサーバーをインストールします:
apt-get install apache2 mariadb-server mariadb-client -yMagentoの最新バージョンはPHP 7.1.3+および7.2.xと互換性があります。したがって、サーバーに必要な拡張機能を持つサポートされているPHPバージョンをインストールする必要があります。
デフォルトでは、Ubuntu 20.04にはPHPバージョン7.4が付属しています。したがって、他のPHPバージョンをインストールするために、システムにOndrej PPAを追加する必要があります。
次のコマンドを使用してOndrej PHP PPAを追加できます:
apt-get install software-properties-common -y
add-apt-repository ppa:ondrej/php次に、リポジトリを更新し、次のコマンドを使用して他の必要な拡張機能を持つPHPをインストールします:
apt-get install php7.2 libapache2-mod-php7.2 php7.2-bcmath php7.2-common php7.2-mbstring php7.2-xmlrpc php7.2-soap php7.2-gd php7.2-xml php7.2-intl php7.2-mysql php7.2-cli php7.2-ldap php7.2-zip php7.2-curl wget curl unzip -y完了したら、次のステップに進むことができます。
MariaDBデータベースの設定
デフォルトでは、MariaDBはセキュリティが確保されていません。したがって、MariaDBのrootパスワードを設定してセキュリティを強化することをお勧めします。次のコマンドを使用して行うことができます:
mysql_secure_installation以下のようにすべての質問に答えます:
Enter current password for root (enter for none):
Set root password? [Y/n] Y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
MariaDBのセキュリティが確保されたら、MariaDBシェルにログインします:
mysql -u root -pMariaDBのrootパスワードを入力し、Magento用のデータベースとユーザーを作成します:
MariaDB [(none)]> CREATE DATABASE magentodb;
MariaDB [(none)]> CREATE USER 'magento'@'localhost' IDENTIFIED BY 'password';次に、次のコマンドを使用してMagentoデータベースにすべての権限を付与します:
MariaDB [(none)]> GRANT ALL ON magentodb.* TO 'magento'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;次に、権限をフラッシュし、次のコマンドを使用してMariaDBシェルから退出します:
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;完了したら、次のステップに進むことができます。
Magentoのダウンロード
このチュートリアルを書いている時点で、Magentoの最新バージョンは2.3.5です。Magentoの公式ダウンロードページからダウンロードできます。
ダウンロードが完了したら、次のコマンドを使用してダウンロードしたファイルをApacheのWebルートディレクトリに抽出します:
mkdir /var/www/html/magento
tar -xvjf magento-ce* -C /var/www/html/magento/次に、Magentoディレクトリに適切な所有権と権限を付与します:
chown -R www-data:www-data /var/www/html/magento/
chmod -R 755 /var/www/html/magento/完了したら、次のステップに進むことができます。
Magento用のApacheの設定
次に、Magentoウェブサイトを提供するための新しいApache仮想ホスト設定ファイルを作成します。
nano /etc/apache2/sites-available/magento.conf次の行を追加します:
ServerAdmin [email protected]
DocumentRoot /var/www/html/magento/
ServerName magento.linuxbuz.com
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
ファイルを保存して閉じたら、次のコマンドを使用してMagento仮想ホストとApacheリライトモジュールを有効にします:
a2ensite magento.conf
a2enmod rewrite最後に、次のコマンドを使用してApacheサービスを再起動し、変更を適用します:
systemctl restart apache2この時点で、Apache WebサーバーはMagentoを提供するように設定されています。
Let’s Encrypt SSLでMagentoを保護する
Let’s Encryptの無料SSLでウェブサイトを保護することは常に良いアイデアです。まず、サーバーにCertbotクライアントをインストールして、ウェブサイトのLet’s Encrypt SSLをダウンロードおよび設定します。
apt-get install certbot python3-certbot-apache -yCertbotがインストールされたら、次のコマンドを実行してウェブサイトのLet’s Encrypt SSLをダウンロードしてインストールします:
certbot --apache -d magento.linuxbuz.com有効なメールアドレスを提供し、以下のようにサービス利用規約に同意するよう求められます:
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for magento.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/magento-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/magento-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/magento-le-ssl.conf
次に、HTTPトラフィックをHTTPSにリダイレクトするかどうかを選択するよう求められます:
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
2を入力してEnterを押してインストールを完了します。
Redirecting vhost in /etc/apache2/sites-enabled/magento.conf to ssl vhost in /etc/apache2/sites-available/magento-le-ssl.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://magento.linuxbuz.com
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=magento.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/magento.linuxbuz.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/magento.linuxbuz.com/privkey.pem
Your cert will expire on 2020-08-11. To obtain a new or tweaked
version of this certificate in the future, simply run certbot again
with the "certonly" option. To non-interactively renew *all* of
your certificates, run "certbot renew"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
Magentoウェブサイトにアクセス
この時点で、あなたのMagentoウェブサイトはLet’s Encrypt SSLで保護されています。
今、ウェブブラウザを開き、URL https://magento.linuxbuz.com を入力します。MagentoのWebベースのインストールウィザードにリダイレクトされます:

Agree and Setup Magento ボタンをクリックします。Magentoの準備状況画面が表示されるはずです:

Start Readiness Check ボタンをクリックします。準備状況チェックが完了すると、次の画面が表示されます:

Next ボタンをクリックします。データベース設定画面が表示されるはずです:

Magentoデータベース名、データベースユーザー名、パスワードを入力し、Next ボタンをクリックします。MagentoのWeb構成ウィザードが表示されるはずです:

Magentoストアと管理者アドレスを提供し、HTTPSを有効にして、Next ボタンをクリックします。ストアのカスタマイズ画面が表示されるはずです:

希望のタイムゾーン、通貨、言語を設定し、Next ボタンをクリックします。管理者ユーザー作成画面が表示されるはずです:

管理者ユーザー名、メール、パスワードを提供し、Next ボタンをクリックします。次の画面が表示されるはずです:

Install Now ボタンをクリックしてインストールを開始します。インストールが成功裏に完了すると、次の画面が表示されるはずです:

Magento管理アドレスをクリックします。Magento管理ページが表示されるはずです:

Magento管理ユーザー名、パスワードを提供し、Sign in ボタンをクリックします。次の画面にMagentoダッシュボードが表示されるはずです:

また、URL https://magento.linuxbuz.com を使用してMagentoストアにアクセスできます。次の画面が表示されるはずです:

結論
おめでとうございます!Ubuntu 20.04にLet’s Encrypt SSLを使用してMagentoを正常にインストールしました。これで、自分のオンラインストアを簡単に展開できます。質問があればお気軽にお尋ねください。
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。