公有云技术php
华为云立足于互联网领域,依托于华为公司雄厚的资本和强大的云计算研发实力,面向互联网增值服务运营商、大中小型企业、政府、科研院所等广大企事业用户提供包括云主机、云托管、云存储等基础云服务、超算、内容分发与加速、视频托管与发布、企业IT、云电脑、云会议、游戏托管、应用托管等服务和解决方案html
打开浏览器访问华为云平台地址https://www.huaweicloud.com/node
点击登陆,进入登陆界面,输入帐号密码进行登陆mysql
登陆成功后进入华为云控制台linux
左上角选择虚拟私有云VPC,选择虚拟私有云,点击右上角建立虚拟私有云sql
选择访问控制中的安全组 数据库
点击名称, 入方向规则,添加规则端口80,3306apache
点击左上角选择弹性云服务器ECS,选择弹性云服务器,点击右上角购买弹性云服务器api
选择按需付费,点击下一步浏览器
选择静态BGP,点击下一步
设置密码,“云备份”选择暂不分配
查看配置,点击当即购买
建立完成
点击名称,查看云主机基本信息
登陆控制台选择云数据库,点击右上角购买数据库实例
选择完成后点击当即购买,显示数据库基本信息
点击提交以后点击返回
等待建立完成,点击登陆
输入帐号密码,点击登陆
点击链接管理,查看信息
点击安全组,进行关联实例
返回控制台,点击云硬盘
点击右上角购买磁盘
选择完成,点击当即购买,显示基本信息
点击提交以后点击返回
点击挂载
查看磁盘信息,并进行分区
# fdisk -l
Disk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0002af06
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83886079 41942016 83 Linux
Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
[root@ecs-ab57 ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x0b673d44.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039):
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set
Command (m for help): p
Disk /dev/vdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0b673d44
Device Boot Start End Blocks Id System
/dev/vdb1 2048 41943039 20970496 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
进行挂载
# partprobe
# mkfs -t ext4 /dev/vdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242624 blocks
262131 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2153775104
160 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
建立文件系统
# mkdir df /mnt/sdk
# mount /dev/vdb1 /mnt/sdk/
# df -TH
Filesystem Type Size Used Avail Use% Mounted on
devtmpfs devtmpfs 2.0G 0 2.0G 0% /dev
tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs tmpfs 2.0G 9.1M 2.0G 1% /run
tmpfs tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/vda1 ext4 43G 2.2G 38G 6% /
tmpfs tmpfs 398M 0 398M 0% /run/user/0
/dev/vdb1 ext4 22G 47M 20G 1% /mnt/sdk
回到控制台选择对象存储服务,选择建立桶
点击当即建立
使用建立的EC2实例
链接到已建立的EC2实例。
为确保全部软件包都处于最新状态,须要对实例执行内核升级,此过程可能须要几分钟的时间,但能确保EC2系统拥有最新的安全更新和缺陷修复。
# yum upgrade -y
查看Amazon Linux的版本。
# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
清除防火墙规则
# iptables -t filter -F
# iptables -t filter -X
永久关闭SELinux
# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
# getenforce
Disabled
# reboot
当实例处于最新状态后,即可以安装Apache Web服务器、MariaDB和PHP软件包。
# yum install -y httpd mariadb-server php php-mysql
启动Apache Web服务器并设置开机自启。
# systemctl start httpd
# systemctl enable httpd
在Web浏览器中,输入实例的公有IP地址。若是/var/www/html中没有内容,则会看到Apache测试页面
若是未能看到Apache测试页面,请检查当前EC2使用的安全组是否包含容许HTTP(端口80)流量的规则
Apache httpd提供的文件保存在Apache文档根目录/var/www/html中,默认状况下归根用户全部
在Apache文档根目录中建立一个PHP文件。
# echo "<?php phpinfo();?>" > /var/www/html/phpinfo.php
能正常打开相应的PHP信息页面,说明PHP已经正常启动;若是在页面中能找到mysql、mysqli的信息内容,说明对PHP平台能正常访问mysql和mysqli接口
删除phpinfo.php文件
# rm -rf /var/www/html/phpinfo.php
在EC2上测试MariaDB的连通性。
# systemctl start mariadb
# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
# mysql -h 192.168.1.74 -P 3306 -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 2102
Server version: 5.7.29-2-log MySQL Community Server - (GPL)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]>
将提供的压缩包wordpress-5.0.2-zh_CN.tar.gz上传至EC2实例/root目录并解压。
# ll
total 10840
drwxr-xr-x 2 root root 4096 May 21 17:17 df
-rw-r--r-- 1 root root 11093953 Nov 7 2019 wordpress-5.0.2-zh_CN.tar.gz
# tar -zxvf wordpress-5.0.2-zh_CN.tar.gz
复制解压后的wordpress目录到/var/www/html目录下。
# cp -rf wordpress /var/www/html/
在浏览器输入http://EC2_IP/wordpress,便可访问WordPress欢迎页面
为了让WordPress正常运行,在数据库中建立数据库以及相应的帐号。
# mysql -h 192.168.1.74 -P 3306 -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 2257
Server version: 5.7.29-2-log MySQL Community Server - (GPL)
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> create database wordpress;
Query OK, 1 row affected (0.01 sec)
MySQL [(none)]> GRANT ALL ON wordpress.* TO 'guo'@'localhost' IDENTIFIED BY "00000000";
Query OK, 0 rows affected, 2 warnings (0.00 sec)
MySQL [(none)]> GRANT ALL ON wordpress.* TO 'guo'@'%' IDENTIFIED BY "00000000";
Query OK, 0 rows affected, 1 warning (0.00 sec)
MySQL [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MySQL [(none)]> quit
Bye
返回网页,继续完成WordPress的初始化操做
在WordPress安装界面会提示没法写入wp-config.php文件,须要手动建立
手动建立wp-config.php文件
# cat /var/www/html/wordpress/wp-config.php
<?php
/**
* WordPress基础配置文件。
*
* 这个文件被安装程序用于自动生成wp-config.php配置文件,
* 能够不使用网站生成,须要手动复制这个文件,
* 并重命名为“wp-config.php”,而后填入相关信息。
*
* 本文件包含如下配置选项:
*
* * MySQL设置
* * 密钥
* * 数据库表名前缀
* * ABSPATH * * @link https://codex.wordpress.org/zh-cn:%E7%BC%96%E8%BE%91_wp-config.php
*
* @package WordPress
*/
// ** MySQL:设置的具体信息来自正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'wordpress');
/** MySQL数据库用户名 */
define('DB_USER', 'root');
/** MySQL数据库密码 */
define('DB_PASSWORD', 'Gao9400@');
/** MySQL主机 */
define('DB_HOST', '192.168.1.74');
/** 建立数据表时默认的文字编码 */
define('DB_CHARSET', 'utf8mb4');
/** 数据库整理类型。如不肯定请勿更改 */
define('DB_COLLATE', '');
/**#@+
* 身份认证密钥。
*
* 修改成任意独一无二的字串!
* 或者直接访问{@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org密钥生成服务}
* 任何修改都会致使全部cookies失效,全部用户将必须从新登陆。
*
* @since 2.6.0
*/
define('AUTH_KEY', 'o96P/{uub3_/m#VY3,KU:c7C:eT,*},T3tU2!Z@N<d[9/K<SdKuw-QJ8!|@+~*oN');
define('SECURE_AUTH_KEY', '1akka,TV:bg>.=qA+y6T{,rVZn)@ wifG3FH4Y[=ZTQ)I8`p,m&]}@<f-,^s@ck{');
define('LOGGED_IN_KEY', '+9dE2i$2G_mCm~[@M^j`/)VcI[F+`js %ud>zr)h+<-hr^<0EI~+)kJcBM6vU~u{');
define('NONCE_KEY', 'I<kv;2[QpC!qw.:f}K%^97. i5PrL~xOE]ieF-#bZtL*jSzB7JxCR^[WEZ,_sn6/');
define('AUTH_SALT', 'xjFz0z>,Ia<E`B!TU0-.QPs7:AqUJ;c3PTNR5WJl5|g20<_&2<(S-(QGz?!Z[}+Q');
define('SECURE_AUTH_SALT', 'yf*?I>#jB9=E8^+:7v<WEkEBPtMW&==yU-,xZdc+TF%EWt{~zxP&VN2w,h^-5Hep');
define('LOGGED_IN_SALT', 'T.f}uR24d4U= EQUo}AnhT;.mvsN.;N(?=3kW)O^D1|R!10{u<t2*pJjj>]J9S&x');
define('NONCE_SALT', 'e32+aG!7F0 LNs|jIm&Od<#~Z9@[kHCAkKsHZ@1<mqX5roA;n+OQFUy=b)xu5l4T');
/**#@-*/
/**
* WordPress数据表前缀。
*
* 若是须要在同一数据库内安装多个WordPress,请为每一个WordPress设置不一样的
* 数据表前缀。前缀名只能为数字、字母加下划线。
*/
$table_prefix = 'wp_';
/**
* 开发者专用:WordPress调试模式。
*
* 将这个值改成true,WordPress将显示全部用于开发的提示。
* 强烈建议插件开发者在开发环境中启用WP_DEBUG。
*
*/
define('WP_DEBUG', false);
/* 好了!请不要再继续编辑。请保存本文件。使用愉快! */
/** WordPress目录的绝对路径。 */
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
/** 设置WordPress变量和包含文件。 */
require_once(ABSPATH . 'wp-settings.php');
WordPress permalink须要使用Apache.htaccess文件才能正常工做,但默认状况下这些文件在Amazon Linux上处于禁用状态。
修改httpd.conf文件中如下内容。
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All #修改此处
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
WordPress中的某些可用功能要求具备对Apache文档根目录的写入权限,例如,经过“Administration(管理)”屏幕上传媒体
将/var/www及其内容的文件全部权授予apache用户。
# chown -R apache /var/www
将/var/www及其内容的组全部权授予apache组。
# chgrp -R apache /var/www
更改/var/www及其子目录的目录权限,添加组写入权限并设置将来子目录上的组ID。
# chmod 2775 /var/www
# find /var/www -type d -exec sudo chmod 2775 {} \;
递归地更改/var/www及其子目录的文件权限,以添加组写入权限。
# find /var/www -type f -exec sudo chmod 0664 {} \;
重启Apache Web服务器,让新组和权限生效。
# systemctl restart httpd
在浏览器上再次访问WordPress页面,进入WordPress登陆信息配置界面,根据需求,设置相应的站点名称、用户名和密码。
单击 “安装WordPress”按钮,开始WordPress的安装
单击“登陆”按钮,进入WordPress登陆界面