Craft là một hệ thống quản lý nội dung mã nguồn mở, linh hoạt và giàu tính năng dành cho các nhà phát triển và tác giả nội dung. Nó cung cấp tất cả các tính năng tùy chỉnh cần thiết để xây dựng một trang web mạnh mẽ. Nó cho phép bạn quản lý nội dung của nhiều trang web khác nhau từ một bảng điều khiển duy nhất. Đây là giải pháp thay thế cho WordPress và Drupal để xây dựng các trải nghiệm kỹ thuật số theo yêu cầu. Nó có hàng trăm plugin miễn phí và trả phí cho phép bạn thêm chức năng.
Bài đăng này sẽ giải thích cách cài đặt Craft CMS với Apache và Let's Encrypt SSL trên Ubuntu 22.04.
Bạn có thể thực hiện lệnh sau để cài đặt tất cả các gói đó:
Sau khi cài đặt tất cả các gói, hãy chỉnh sửa tệp cấu hình PHP và thay đổi mặc định cài đặt:
Thay đổi các cài đặt sau:
Lưu và đóng tệp sau đó khởi động lại dịch vụ Apache để áp dụng thay đổi:
Sau khi đăng nhập, hãy tạo cơ sở dữ liệu và người dùng bằng lệnh sau:
Tiếp theo, xóa các đặc quyền và thoát khỏi shell MariaDB bằng lệnh sau lệnh:
Tại thời điểm này, cơ sở dữ liệu MariaDB đã được tạo cho Craft CMS. Bây giờ bạn có thể tiến hành bước tiếp theo.
Sau khi cài đặt Composer, hãy điều hướng đến thư mục gốc web Apache và tạo một dự án Craft CMS bằng lệnh sau:
Bạn sẽ được yêu cầu cung cấp cài đặt cơ sở dữ liệu, tên người dùng quản trị, mật khẩu, URL trang web như hiển thị bên dưới:
Tiếp theo, thiết lập quyền và quyền sở hữu thích hợp cho thư mục Craft CMS:
Sau khi hoàn tất, bạn có thể tiến hành bước tiếp theo.
Thêm các dòng sau:
Lưu và đóng tệp sau đó kích hoạt máy chủ ảo Apache và viết lại mô-đun bằng lệnh sau:
Tiếp theo, khởi động lại dịch vụ Apache để áp dụng thay đổi:
Bạn cũng có thể kiểm tra trạng thái Apache bằng lệnh sau:
Bạn sẽ nhận được thông báo sau đầu ra:
Sau khi máy chủ web Apache của bạn được cấu hình, bạn có thể tiến hành bước tiếp theo.
data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22370%22%3E%3C/svg%3E
Nhấp vào đi đến bảng điều khiển của bạn. Bạn sẽ được chuyển hướng đến trang đăng nhập Craft CMS:
data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22395%22%3E%3C/svg%3E
Cung cấp tên người dùng quản trị, mật khẩu và nhấp vào nút đăng nhập. Bạn sẽ thấy bảng điều khiển Craft CMS trên trang sau:
data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22372%22%3E%3C/svg%3E
Sau khi cài đặt thành công, hãy chạy lệnh sau để bảo mật trang web của bạn bằng Let's Encrypt SSL:
Bạn sẽ được yêu cầu cung cấp email và chấp nhận điều khoản dịch vụ như hiển thị bên dưới:
Tiếp theo, chọn có chuyển hướng lưu lượng HTTP sang HTTPS hay không như hiển thị bên dưới:
Nhập 2 và nhấn Enter để cài đặt Let's Encrypt SSL cho bạn trang web:
Bài đăng này sẽ giải thích cách cài đặt Craft CMS với Apache và Let's Encrypt SSL trên Ubuntu 22.04.
Điều kiện tiên quyết
- Một máy chủ chạy Ubuntu 22.04.
- Tên miền hợp lệ được trỏ bằng IP máy chủ của bạn.
- Mật khẩu gốc được cấu hình trên máy chủ.
Cài đặt Máy chủ LAMP
Craft CMS chạy trên máy chủ web, được viết bằng PHP và sử dụng MariaDB làm cơ sở dữ liệu phụ trợ. Vì vậy, bạn sẽ cần cài đặt tất cả các gói đó vào máy chủ của mình.Bạn có thể thực hiện lệnh sau để cài đặt tất cả các gói đó:
Mã:
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
Mã:
nano /etc/php/8.1/php.ini
Mã:
memory_limit = 512M
post_max_size = 32M
upload_max_filesize = 32M
max_execution_time = 360
Mã:
systemctl restart apache2
Tạo cơ sở dữ liệu cho CraftCMS
Tiếp theo, bạn sẽ cần tạo cơ sở dữ liệu và người dùng cho Fork CMS. Trước tiên, hãy đăng nhập vào shell MariaDB bằng lệnh sau:
Mã:
mysql
Mã:
MariaDB [(none)]> CREATE DATABASE craftcms;
MariaDB [(none)]> GRANT ALL ON craftcms.* TO 'craftuser' IDENTIFIED BY 'password';
Mã:
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> EXIT;
Cài đặt Craft CMS bằng Compose
Tiếp theo, bạn sẽ cần cài đặt Composer để tải xuống phiên bản mới nhất của Craft CMS. Bạn có thể cài đặt bằng lệnh sau:
Mã:
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
Mã:
cd /var/www/html
composer create-project craftcms/craft craftcms
Mã:
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: [emailprotected]
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)
Mã:
chown -R www-data:www-data /var/www/html/craftcms/
chmod -R 755 /var/www/html/craftcms/
Cấu hình Apache cho Craft CMS
Tiếp theo, bạn sẽ cần tạo tệp cấu hình máy chủ ảo Apache cho Craft CMS. Bạn có thể tạo nó bằng lệnh sau:
Mã:
nano /etc/apache2/sites-available/craftcms.conf
Mã:
ServerAdmin [emailprotected] 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]
Mã:
a2ensite craftcms.conf
a2enmod rewrite
Mã:
systemctl restart apache2
Mã:
systemctl status apache2
Mã:
? 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...
Truy cập Giao diện web Craft CMS
Bây giờ, hãy mở trình duyệt web của bạn và nhập URL để truy cập giao diện web Craft CMS. Bạn sẽ thấy trang sau:data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22370%22%3E%3C/svg%3E
Nhấp vào đi đến bảng điều khiển của bạn. Bạn sẽ được chuyển hướng đến trang đăng nhập Craft CMS:
data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22395%22%3E%3C/svg%3E
Cung cấp tên người dùng quản trị, mật khẩu và nhấp vào nút đăng nhập. Bạn sẽ thấy bảng điều khiển Craft CMS trên trang sau:
data:image/svg+xml,%3Csvg%20xmlns=%22http://www.w3.org/2000/svg%22%20width=%22750%22%20height=%22372%22%3E%3C/svg%3E
Bảo mật Craft CMS bằng Let's Encrypt SSL
Tiếp theo, bạn nên bảo mật trang web của mình bằng Let's Encrypt SSL. Trước tiên, hãy cài đặt gói máy khách Certbot bằng lệnh sau:
Mã:
apt-get install python3-certbot-apache -y
Mã:
certbot --apache -d craftcms.example.com
Mã:
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): [emailprotected]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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
Mã:
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
Mã:
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