手动安装和配置Drupal9的运行环境(LNMP)

逆流の鱼, 29 十一月, 2021

安装centos7

centos8太占内存了,还是选用centos7,在云主机控制台选择安装centos7。

安装后第一件事是更新

yum update
yum install epel-release

配置swap

/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=4096
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1
chmod 600 /var/swap.1
vim /etc/fstab

在fstab加入以下一行,用于重启后自动加载swap:

/var/swap.1     swap    swap    sw      0       0

安装vim高亮语法(支持nginx和php配置文件)

cd /usr/share/vim/vim74/syntax/
wget https://raw.githubusercontent.com/chr4/nginx.vim/master/syntax/nginx.vim
vim /usr/share/vim/vim74/filetype.vim

加上几行

" nginx configuration
au BufRead,BufNewFile /etc/nginx/* set ft=nginx

" php-fpm configuration
au BufRead,BufNewFile /etc/php-fpm.d/* set ft=dosini

挂载数据盘

fdisk -l
mount /dev/xvdb1 /mnt
lsblk

安装最新版mariadb

curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
yum install MariaDB-server.x86_64
systemctl start mariadb.service
systemctl enable mariadb.service
/usr/bin/mariadb-secure-installation
#测试一下密码
mysqladmin -uroot -p version

安装nginx

yum install nginx
systemctl start nginx.service
systemctl enable nginx.service

安装php8

(安装8.0,因为drupal9.2还没兼容php8.1)

yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install yum-utils
yum-config-manager --enable remi-php80
yum install php php-fpm php-mbstring php-mysqlnd php-xml php-gd
yum install php-pecl-apcu.x86_64
vim /etc/php-fpm.d/www.conf

安装https

yum install certbot.noarch
certbot --nginx -d your.domain.com
#查看证书
certbot certificates
#加域名
/bin/certbot --duplicate --nginx -d your-second.domain.com

自动更新证书

在crontab里加入以下两行代码(必须有path,不然会出错)。证书有效期是90天,每月更新一次卓卓有余。

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
15 3 3 * * /usr/bin/certbot renew --quiet

安装phpMyAdmin

wget https://files.phpmyadmin.net/phpMyAdmin/5.1.1/phpMyAdmin-5.1.1-all-languages.zip
unzip phpMyAdmin-5.1.1-all-languages.zip
mv phpMyAdmin-5.1.1-all-languages /usr/share/phpMyAdmin
cd /usr/share/phpMyAdmin
cp config.sample.inc.php config.inc.php
vim config.inc.php
mkdir tmp
chown apache.apache tmp

安装composer

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"
mv composer.phar /usr/local/bin/composer

安装Drupal

composer create-project drupal/recommended-project drupal9
cd drupal9
composer require drupal/admin_toolbar
composer require drupal/antibot
composer require drupal/backup_migrate
composer require drush/drush

安装Drush

vendor/bin/drush太不方便了,需要随时随地drush

wget -O drush.phar https://github.com/drush-ops/drush-launcher/releases/latest/download/drush.phar
chmod +x drush.phar
mv drush.phar /usr/local/bin/drush

 

评论