使用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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章