in AWS

使用AWS云安装WordPress + RDS MySQL

创建EC2实例

使用以下AWS实例:

===

Amazon Linux AMI 2018.03.0 (HVM), SSD Volume Type – ami-05c859630889c79c8
The Amazon Linux AMI is an EBS-backed, AWS-supported image. The default image includes AWS command line tools, Python, Ruby, Perl, and Java. The repositories include Docker, PHP, MySQL, PostgreSQL, and other packages.
Root device type: ebs Virtualization type: hvm ENA Enabled: Yes

===

在创建时填写以下启动脚本:

#!/bin/bash
yum install httpd php php-mysql -y
cd /var/www/html
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
cp -r wordpress/* /var/www/html/
rm -rf wordpress
rm -rf latest.tar.gz
chmod -R 755 wp-content
chown -R apache:apache wp-content
service httpd start
chkconfig httpd on

使用默认的安全组Security Group,另外再添加一个安全组MyWebDMZ,添加想要放行的端口。
创建好EC2实例后,检查一下:

[ec2-user@ip-172-31-30-59 ~]$ sudo su
[root@ip-172-31-30-59 ec2-user]#
[root@ip-172-31-30-59 ec2-user]# ifconfig
eth0      Link encap:Ethernet  HWaddr 02:AB:70:43:3F:EA
          inet addr:172.31.30.59  Bcast:172.31.31.255  Mask:255.255.240.0
          inet6 addr: fe80::ab:70ff:fe43:3fea/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:9001  Metric:1
          RX packets:21323 errors:0 dropped:0 overruns:0 frame:0
          TX packets:4319 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:30415088 (29.0 MiB)  TX bytes:293071 (286.2 KiB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:2 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:140 (140.0 b)  TX bytes:140 (140.0 b)

[root@ip-172-31-30-59 ec2-user]#
[root@ip-172-31-30-59 ec2-user]# ls /var/www/html/
index.php    readme.html      wp-admin            wp-comments-post.php  wp-content   wp-includes        wp-load.php   wp-mail.php      wp-signup.php     xmlrpc.php
license.txt  wp-activate.php  wp-blog-header.php  wp-config-sample.php  wp-cron.php  wp-links-opml.php  wp-login.php  wp-settings.php  wp-trackback.php
[root@ip-172-31-30-59 ec2-user]# service httpd status
httpd (pid  2783) is running...
[root@ip-172-31-30-59 ec2-user]#

创建RDS MySQL 5.7.22

下面来创建RDS Mysql数据库,默认版本号是MySQL 5.7.22,选Free tier.

数据库的设置如下:

===

DB instance identifier
wordpress-test –>这个不是数据库名,不要搞混了

Master username
xionghuilin

Setup the password

Use default VPC

===

数据库创建好后, 连接信息如下:

===

Connectivity & security
Endpoint & port
Endpoint
wordpress-test.cn63rtxgzraf.ap-southeast-1.rds.amazonaws.com
Port
3306

===

设置Wordpress, 出错:PHP版本过低

开始出现以下错误:
==Your server is running PHP version 5.3.29 but WordPress 5.2.4 requires at least 5.6.20.==

[root@ip-172-31-30-59 ec2-user]# php -v
PHP 5.3.29 (cli) (built: May 12 2015 22:42:19)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2014 Zend Technologies
[root@ip-172-31-30-59 ec2-user]#

参考链接
PHP版本过低,下面升级PHP到5.6,安装EPEL and Remi YUM源。

[root@ip-172-31-30-59 ec2-user]# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@ip-172-31-30-59 ec2-user]# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@ip-172-31-30-59 ec2-user]# yum install yum-utils
Loaded plugins: priorities, update-motd, upgrade-helper
833 packages excluded due to repository priority protections
Package yum-utils-1.1.31-46.30.amzn1.noarch already installed and latest version
Nothing to do

安装PHP 5.6

[root@ip-172-31-30-59 ec2-user]# yum-config-manager --enable remi-php56   [Install PHP 5.6]
[root@ip-172-31-30-59 ec2-user]# yum install php php-mcrypt php-cli php-gd php-curl php-mysql php-ldap php-zip php-fileinfo

显示以下:

==packages excluded due to repository priority protections==

参考链接,做以下修改就可以使用新加的YUM源。

[root@ip-172-31-30-59 ec2-user]# vim /etc/yum/pluginconf.d/priorities.conf
[root@ip-172-31-30-59 ec2-user]# cat /etc/yum/pluginconf.d/priorities.conf
[main]
enabled = 0
[root@ip-172-31-30-59 ec2-user]#

安装还是出错:

Error: Package: php-5.6.40-14.el7.remi.x86_64 (remi-php56)
           Requires: libpcre.so.1()(64bit)
Error: Package: gd-last-2.2.5-8.el7.remi.x86_64 (remi-safe)
           Requires: libpng15.so.15(PNG15_0)(64bit)
Error: Package: php-ldap-5.6.40-14.el7.remi.x86_64 (remi-php56)
           Requires: libsasl2.so.3()(64bit)
Error: Package: gd-last-2.2.5-8.el7.remi.x86_64 (remi-safe)
           Requires: libpng15.so.15()(64bit)
Error: Package: php-cli-5.6.40-14.el7.remi.x86_64 (remi-php56)
           Requires: libpcre.so.1()(64bit)
Error: Package: php-5.6.40-14.el7.remi.x86_64 (remi-php56)

参考链接
使用以下办法升级php

====

service httpd stop
yum erase httpd httpd-tools apr apr-util
remove php-*
yum install php56

====

[root@ip-172-31-30-59 ec2-user]# yum list installed | grep php
php56.x86_64                         5.6.40-1.142.amzn1            @amzn-updates
php56-cli.x86_64                     5.6.40-1.142.amzn1            @amzn-updates
php56-common.x86_64                  5.6.40-1.142.amzn1            @amzn-updates
php56-jsonc.x86_64                   1.3.10-1.20.amzn1             @amzn-main
php56-process.x86_64                 5.6.40-1.142.amzn1            @amzn-updates
php56-xml.x86_64                     5.6.40-1.142.amzn1            @amzn-updates
[root@ip-172-31-30-59 ec2-user]#
[root@ip-172-31-30-59 ec2-user]# php -v
PHP 5.6.40 (cli) (built: Mar  8 2019 18:17:39)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
[root@ip-172-31-30-59 ec2-user]#
[root@ip-172-31-30-59 ec2-user]# service httpd status
httpd is stopped
[root@ip-172-31-30-59 ec2-user]# service httpd start
Starting httpd:                                            [  OK  ]
[root@ip-172-31-30-59 ec2-user]# service httpd status
httpd (pid  24308) is running...
[root@ip-172-31-30-59 ec2-user]#

再次出现以下错误:

====

==Your PHP installation appears to be missing the MySQL extension which is required by WordPress.==

====

解决办法,首先安装MySQL

[root@ip-172-31-30-59 ec2-user]# yum install mysql

再安装 php56-mysqlnd,

[root@ip-172-31-30-59 ec2-user]# yum install php56-mysqlnd

结果如下:

[root@ip-172-31-30-59 ec2-user]# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]
[root@ip-172-31-30-59 ec2-user]# httpd -v
Server version: Apache/2.4.41 (Amazon)
Server built:   Oct 15 2019 22:21:35
[root@ip-172-31-30-59 ec2-user]# php -v
PHP 5.6.40 (cli) (built: Mar  8 2019 18:17:39)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
[root@ip-172-31-30-59 ec2-user]#

再次设置Wordpress, 成功

访问EC2的公网地址:http://54.251.141.70,进入到Wordpress设置界面,无错误,依次输入以下设置。

  • Database name –> wordpress-test –> 这个不是数据库名,数据库需要创建,以下出错。
  • Database username –> xionghuilin
  • Database password –> password
  • Database host –> 先前创建的 the RDS MySQL end point: wordpress-test.cn63rtxgzraf.ap-southeast-1.rds.amazonaws.com
  • Table prefix (if you want to run more than one WordPress in a single database)

确保EC2和RDS MySQL在同一个安全组里(Security Group)。

这里在输入以上信息后,出现了以下错误:

Error establishing a database connection
This either means that the username and password information in your wp-config.php file is incorrect or we can’t contact the database server at wordpress-test.cn63rtxgzraf.ap-southeast-1.rds.amazonaws.com. This could mean your host’s database server is down.

Are you sure you have the correct username and password?
Are you sure that you have typed the correct hostname?
Are you sure that the database server is running?
If you’re unsure what these terms mean you should probably contact your host. If you still need help you can always visit the WordPress Support Forums.

Try again

这里是因为没有创建初始数据wordpress-test的原因,可以在创建RDS MySQL实例的时候创建,参考此链接,也可以直接用sql指令创建, SQL命令如下:

[root@ip-172-31-30-59 ec2-user]# mysql -u xionghuilin -h wordpress-test.cn63rtxgzraf.ap-southeast-1.rds.amazonaws.com -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 28
Server version: 5.7.22-log Source distribution

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE DATABASE wordpress-2019;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-2019' at line 1
mysql> CREATE DATABASE wordpress2019;
Query OK, 1 row affected (0.00 sec)

mysql>

用以下设置再试,问题解决!

  • Database name –> wordpress2019
  • Database username –> xionghuilin
  • Database password –> password
  • Database host –> 先前创建的 the RDS MySQL end point: wordpress-test.cn63rtxgzraf.ap-southeast-1.rds.amazonaws.com
  • Table prefix (if you want to run more than one WordPress in a single database)

以上问题解决了,下一步有以下问题,按提示即可解决。

rry, but I can’t write the wp-config.php file.

You can create the wp-config.php file manually and paste the following text into it.

按照要求,创建wp-config.php,把内容复制进去即可,

[root@ip-172-31-30-59 ec2-user]# vim /var/www/html/wp-config.php

创建好wp-config.php,继续安装,剩下的设置就是水到渠成了。

写一个Blog,
Write a blog

效果如下:

Publish a blog

Reference

How to Install Php5.6 in amazon linux
What does that mean: packages excluded due to repository priority protections
HOW TO UPGRADE PHP 5.4 TO PHP 5.6 ON CENTOS 7.5 (1804)
AWS RDS – does not create initial database – Acloudguru

Write a Comment

Comment