第4步:创建Drupal数据库
下面开始配置服务器。
首先运行以下命令以创建Drupal数据库。
运行以下命令以登录数据库服务器。
提示输入密码时,键入上面创建的root密码。
sudo mysql -u root -p
然后创建一个名为drupal的数据库
CREATE DATABASE drupal;
使用新密码创建名为DrupalUser的数据库用户
CREATE USER 'drupaluser'@'localhost' IDENTIFIED BY 'new_password_here';
然后授予用户完全访问数据库。
GRANT ALL ON drupal.* TO 'drupaluser'@'localhost' IDENTIFIED BY 'user_password_here' WITH GRANT OPTION;
最后,保存更改并退出。
FLUSH PRIVILEGES; EXIT;
步骤9:获取和配置Let’s Encrypt SSL证书
要获取 Let’s Encrypt SSL/TLS证书,我们应该首先安装其客户端。
客户端将自动化获取证书
要安装它,请运行以下命令。
sudo apt-get install python-certbot-apache
如果尚未安装Python-certbot-apache,则可能必须添加其PPA存储库并安装包..
sudo add-apt-repository ppa:certbot/certbot sudo apt-get update sudo apt-get install python-certbot-apache
运行下面命令,从Let’s Encrypt网站获取免费的SSL/TLS证书。
sudo certbot --apache -m admin@example.com -d example.com -d www.example.com
提示接收许可条款时,输入yes。
客户端会自动安装免费的SSL/TLS证书并配置Apache2站点 。
Please read the Terms of Service at https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2015.pdf. You must agree in order to register with the ACME server at https://acme-v01.api.letsencrypt.org/directory ------------------------------------------------------------------------------ (A)gree/(C)ancel: A
选择是(y)以共享我们的电子邮件地址
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 EFF and our work to encrypt the web, protect its users and defend doirtal rights. ------------------------------------------------------------------------------ (Y)es/(N)o: Y
继续:
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将所有流量重定向HTTPS。
SSL客户端将安装证书并将您的网站配置为通过HTTPS重定向所有流量。
Congratulations! You have successfully enabled https://example.com and https://www.example.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=example.com https://www.ssllabs.com/ssltest/analyze.html?d=www.example.com ------------------------------------------------------------------------------ IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/example.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/example.com/privkey.pem Your cert will expire on 2015-02-24. 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
下面的部分代码是 Let's Encrypt certbot 自动添加到Apache2 Drupal站点配置文件中。
Drupal网站已准备好使用HTTPS了。
<VirtualHost *:80> ServerAdmin admin@example.com DocumentRoot /var/www/html/drupal/ ServerName example.com ServerAlias www.example.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /var/www/html/drupal/> Options FollowSymlinks AllowOverride All Require all granted </Directory> <Directory /var/www/html/drupal/> RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$index.php?q= [L,QSA] </Directory> RewriteEngine on RewriteCond %{SERVER_NAME} =example.com [OR] RewriteCond %{SERVER_NAME} =www.example.com RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] </VirtualHost>
Let's Encrypt certbot 还创建了新配置文件/etc/apache2/sites-available/drupal-le-ssl.conf
这是Apache2 SSL模块配置文件,包含了其中定义的证书定义。
<IfModule mod_ssl.c> <VirtualHost *:443> ServerAdmin admin@example.com DocumentRoot /var/www/html/drupal/ ServerName example.com ServerAlias www.example.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /var/www/html/drupal/> Options FollowSymlinks AllowOverride All Require all granted </Directory> <Directory /var/www/html/drupal/> RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$index.php?q= [L,QSA] </Directory> SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf </VirtualHost> </IfModule>
使用浏览器打开
https://example.com
将出现Drupal配置向导。
按照屏幕向导,直到我们完成。
现在我们已成功安装带有Let’s Encrypt 免费的SSL证书的Drupal。
要设置一个自动续订证书的过程,请添加Cron作业以执行续订进程。
sudo crontab -e
然后添加下面的行并保存。
0 1 * * * /usr/bin/certbot renew & > /dev/null
Cron任务将尝试在到期前30天进行更新
第3步:安装PHP 7.1和相关模块
PHP 7.1不在Ubuntu默认存储库上。
要安装它,我们必须从第三方存储库中获取它。
运行下面的命令,添加以下第三方存储库。
sudo apt-get install software-properties-common sudo add-apt-repository ppa:ondrej/php
然后更新并升级到PHP 7.1
sudo apt update
运行以下命令以安装PHP 7.1和相关模块。
sudo apt install php7.1 libapache2-mod-php7.1 libapache2-mod-php7.1 php7.1-common php7.1-mbstring php7.1-xmlrpc php7.1-soap php7.1-gd php7.1-xml php7.1-intl php7.1-mysql php7.1-cli php7.1-mcrypt php7.1-ldap php7.1-zip php7.1-curl
安装PHP后,请运行以下命令以打开Apache2 PHP默认文件。
sudo nano /etc/php/7.1/apache2/php.ini
根据需求修改PHP配置,比如:
file_uploads = On allow_url_fopen = On memory_limit = 256M upload_max_filesize = 64M max_execution_time = 360 date.timezone = America/Chicago
第2步:安装MariaDB
Drupal还需要一个数据库服务器。
这里我们选用开源的MariaDB数据库服务器
使用下面的命令来安装它:
sudo apt-get install mariadb-server mariadb-client
同样,下面的命令可用于停止,启动和启用MariaDB服务。
sudo systemctl stop mysql.service sudo systemctl start mysql.service sudo systemctl enable mysql.service
运行以下命令来保护MariaDB服务器。
sudo mysql_secure_installation
出现提示时,通过遵循教程,回答以下问题。
- 输入root的当前密码(输入无):只需按Enter键
- 设置root密码? [Y/N]:Y
- 新密码:输入密码
- 重新输入新密码:重复密码
- 删除匿名用户? [Y/N]:Y
- 远程禁止root登录? [Y/N]:Y
- 删除测试数据库并访问它? [Y/N]:Y
- 现在重新加载权限表? [Y/N]:Y
重新启动MariaDB服务器
sudo systemctl restart mysql.service
第1步:安装apache2
Drupal需要Web服务器,
这里我们选用Apache2.
运行下面的命令在Ubuntu中安装apache:
sudo apt install apache2
运行以下命令可以停止,启动和启用Apache2服务(启用服务:在服务器引导时自动启动服务)。
sudo systemctl stop apache2.service sudo systemctl start apache2.service sudo systemctl enable apache2.service
第5步:下载Drupal最新版本
接下来,访问Drupal站点并下载最新的包。
或者运行以下命令下载 。
cd /tmp && cd /tmp && wget https://ftp.drupal.org/files/projects/drupal-8.4.2.tar.gz
下载后,运行以下命令以提取下载的文件
并将其移动到新的Drupal根目录中。
tar -zxvf drupal*.gz sudo mv drupal-8.4.2 /var/www/html/drupal
然后运行下面的命令以设置Drupal的正确权限正常运行。
sudo chown -R www-data:www-data /var/www/html/drupal/ sudo chmod -R 755 /var/www/html/drupal/
第8步:重新启动Apache2
要加载上面的所有设置,请通过运行下面的命令重新启动Apache2.
sudo systemctl restart apache2.service
步骤6:配置Apache2 Drupal站点
最后,为Drupal配置Apache2配置文件。
此文件将控制用户如何访问Drupal内容。
运行以下命令以创建名为Drupal .conf的新配置文件
sudo nano /etc/apache2/sites-available/drupal.conf
然后将下面的内容复制并粘贴到文件中并保存。
注意替换为我们自己的域名和目录根位置。
<VirtualHost *:80> ServerAdmin admin@example.com DocumentRoot /var/www/html/drupal ServerName example.com ServerAlias www.example.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined <Directory /var/www/html/drupal/> Options FollowSymlinks AllowOverride All Require all granted </Directory> <Directory /var/www/html/drupal> RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$index.php?q= [L,QSA] </Directory> </VirtualHost>
保存文件并退出。
第7步:启用Drupal网站
在上面配置VirtualHost后,通过运行下面的命令启用它
sudo a2ensite drupal.conf sudo a2enmod rewrite sudo a2enmod env sudo a2enmod dir sudo a2enmod mime
Drupal是一种功能强大且广受欢迎的CMS,许多网站管理员使用它来创建功能强大的网站和教程 。如果您正在寻找开源平台来轻松创建动态的、基于PHP的网站和教程 ,那么您可能想看看Drupal CMS。
要安装带Let's Encrypt支持的Drupal,请按照以下步骤操作: