CraftCMS · 5 min read · Sep 26, 2025
Ubuntu 22.04 LTSにApacheとLet's Encrypt SSLを使用してCraftCMSをインストールする方法

Craftは、開発者とコンテンツ作成者のためのオープンソースで柔軟性があり、機能豊富なコンテンツ管理システムです。強力なウェブサイトを構築するために必要なすべてのカスタマイズ機能を提供します。単一のダッシュボードからさまざまなサイトのコンテンツを管理できます。WordPressやDrupalの代替ソリューションとして、特注のデジタル体験を構築するために使用されます。機能を追加するための数百の無料および有料のプラグインがあります。
この記事では、Ubuntu 22.04にApacheとLet’s Encrypt SSLを使用してCraft CMSをインストールする方法を説明します。
前提条件
- Ubuntu 22.04を実行しているサーバー。
- サーバーIPにポイントされた有効なドメイン名。
- サーバーに設定されたルートパスワード。
LAMPサーバーのインストール
Craft CMSはウェブサーバー上で動作し、PHPで記述され、データベースバックエンドとしてMariaDBを使用します。したがって、これらのパッケージをすべてサーバーにインストールする必要があります。
次のコマンドを実行して、すべてのパッケージをインストールできます。
apt-get install apache2 mariadb-server php php-cli libapache2-mod-php php-common php-json php-curl php-gd php-imagick php-json php-mbstring php-mysql php-pgsql php-zip php-intl php-xml -yすべてのパッケージをインストールした後、PHP設定ファイルを編集してデフォルト設定を変更します。
nano /etc/php/8.1/php.ini次の設定を変更します。
memory_limit = 512M
post_max_size = 32M
upload_max_filesize = 32M
max_execution_time = 360
ファイルを保存して閉じたら、変更を適用するためにApacheサービスを再起動します。
systemctl restart apache2CraftCMS用のデータベースを作成
次に、Fork CMS用のデータベースとユーザーを作成する必要があります。まず、次のコマンドでMariaDBシェルにログインします。
mysqlログインしたら、次のコマンドでデータベースとユーザーを作成します。
MariaDB [(none)]> CREATE DATABASE craftcms;
MariaDB [(none)]> GRANT ALL ON craftcms.* TO 'craftuser' IDENTIFIED BY 'password';次に、特権をフラッシュし、次のコマンドでMariaDBシェルから退出します。
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;この時点で、Craft CMS用のMariaDBデータベースが作成されました。次のステップに進むことができます。
Composerを使用してCraft CMSをインストール
次に、最新バージョンのCraft CMSをダウンロードするためにComposerをインストールする必要があります。次のコマンドを使用してインストールできます。
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composerComposerがインストールされたら、Apacheのウェブルートディレクトリに移動し、次のコマンドを使用してCraft CMSプロジェクトを作成します。
cd /var/www/html
composer create-project craftcms/craft craftcmsデータベース設定、管理者ユーザー名、パスワード、サイトURLを提供するように求められます。以下のように表示されます。
Which database driver are you using? (mysql or pgsql) [mysql]
Database server name or IP address: [127.0.0.1]
Database port: [3306]
Database username: [root] craftuser
Database password:
Database name: craft
Database table prefix:
Testing database credentials ... success!
Saving database credentials to your .env file ... done
Install Craft now? (yes|no) [yes]:yes
Username: [admin] admin
Email: [email protected]
Password:
Confirm:
Site name: CraftCMS Site
Site URL: http://craftcms.example.com
Site language: [en-US]
> add foreign key fk_rlbmgnhpxsljkaunjwnsezfrnrkhwzpthfsq: {{%widgets}} (userId) references {{%users}} (id) ... done (time: 0.035s)
> populating the info table ... done
> saving default site data ... done
> saving the first user ... done
*** installed Craft successfully (time: 5.449s)
次に、Craft CMSディレクトリに適切な権限と所有権を設定します。
chown -R www-data:www-data /var/www/html/craftcms/
chmod -R 755 /var/www/html/craftcms/完了したら、次のステップに進むことができます。
Craft CMS用にApacheを構成
次に、Craft CMS用のApache仮想ホスト構成ファイルを作成する必要があります。次のコマンドで作成できます。
nano /etc/apache2/sites-available/craftcms.conf次の行を追加します。
ServerAdmin [email protected]
DocumentRoot /var/www/html/craftcms/web
ServerName craftcms.example.com
Options FollowSymlinks
AllowOverride All
Require all granted
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*) index.php [PT,L]
ファイルを保存して閉じたら、次のコマンドを使用してApache仮想ホストとリライトモジュールを有効にします。
a2ensite craftcms.conf
a2enmod rewrite次に、変更を適用するためにApacheサービスを再起動します。
systemctl restart apache2次のコマンドでApacheの状態を確認することもできます。
systemctl status apache2次の出力が得られます。
? apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2022-06-17 15:48:11 UTC; 31min ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 37935 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
Process: 40916 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
Main PID: 37939 (apache2)
Tasks: 6 (limit: 2292)
Memory: 53.0M
CPU: 28.718s
CGroup: /system.slice/apache2.service
??37939 /usr/sbin/apache2 -k start
??40920 /usr/sbin/apache2 -k start
??40921 /usr/sbin/apache2 -k start
??40922 /usr/sbin/apache2 -k start
??40923 /usr/sbin/apache2 -k start
??40924 /usr/sbin/apache2 -k start
Jun 17 15:48:11 ubuntu2204 systemd[1]: Starting The Apache HTTP Server...
Apacheウェブサーバーが構成されたら、次のステップに進むことができます。
Craft CMSウェブインターフェースにアクセス
今、ウェブブラウザを開き、URL http://craftcms.example.com を入力してCraft CMSウェブインターフェースにアクセスします。次のページが表示されるはずです。

コントロールパネルに移動をクリックします。Craft CMSのログインページにリダイレクトされます。

管理者ユーザー名、パスワードを入力し、ログインボタンをクリックします。次のページにCraft CMSダッシュボードが表示されるはずです。

Let’s Encrypt SSLでCraft CMSを保護
次に、Let’s Encrypt SSLでウェブサイトを保護することをお勧めします。まず、次のコマンドでCertbotクライアントパッケージをインストールします。
apt-get install python3-certbot-apache -yインストールが成功したら、次のコマンドを実行してLet’s Encrypt SSLでウェブサイトを保護します。
certbot --apache -d craftcms.example.com次のように、メールアドレスを提供し、利用規約に同意するように求められます。
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator standalone, Installer None
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
Plugins selected: Authenticator apache, Installer apache
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for craftcms.example.com
Enabled Apache rewrite module
Waiting for verification...
Cleaning up challenges
Created an SSL vhost at /etc/apache2/sites-available/craftcms-le-ssl.conf
Enabled Apache socache_shmcb module
Enabled Apache ssl module
Deploying Certificate to VirtualHost /etc/apache2/sites-available/craftcms-le-ssl.conf
Enabling available site: /etc/apache2/sites-available/craftcms-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を押して、ウェブサイトのLet’s Encrypt SSLをインストールします。
Enabled Apache rewrite module
Redirecting vhost in /etc/apache2/sites-enabled/craftcms.conf to ssl vhost in /etc/apache2/sites-available/craftcms-le-ssl.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://craftcms.example.com
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=craftcms.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/craftcms.example.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/craftcms.example.com/privkey.pem
Your cert will expire on 2022-09-17. 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"
- 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
結論
おめでとうございます!Ubuntu 22.04にApacheとLet’s Encrypt SSLを使用してCraft CMSを正常にインストールしました。これでCraftCMSの機能を探索し、Craft CMSを使用して強力なウェブサイトを作成することができます。質問があればお気軽にお尋ねください。
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。