安装Nginx
要使用官方Nginx源,无需手动编译避免繁琐操作。
手动配置yum源
[root@nginx~]vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
执行yum安装
[root@nginx ~]# yum install nginx -y
启动nginx并加入开机自启
[root@nginx ~]# systemctl start nginx
[root@nginx ~]# systemctl enable nginx
安装php(7.1版)
移除旧版php
[root@nginx ~]# yum remove php-mysql-5.4 php php-fpm php-common -y
配置扩展源
[root@nginx nginx]# yum localinstall -y http://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安装php7.1版
[root@nginx ~]# yum -y install php71w php71w-cli php71w-common php71w-devel
php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm
php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
统一系统权限,修改php-fpm运行的用户和组身份
[root@web02 ~]# sed -i '/^user/c user = www' /etc/php-fpm.d/www.conf
[root@web02 ~]# sed -i '/^group/c group = www' /etc/php-fpm.d/www.conf
创建用户(www)
useradd www
启动php-fpm管理进程,并加入开机自启
root@nginx ~]# systemctl start php-fpm
[root@nginx ~]# systemctl enable php-fpm
配置Nginx连接php,并进行测试
[root@nginx conf.d]# cat /etc/nginx/conf.d/blog.zhangweibin.conf
server {
listen 80;
server_name www.zhangweibin.com;
locationn / {
root /code/test;
index index.php index.html;
}
location ~ \.php$ {
root /code/test;
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
创建对应站点目录
[root@Nginx conf.d]# mkdir /code/test
[root@Nginx conf.d]# vim /code/test/index.php
####该文件内容为测试php成功连接
<?
phpinfo();
?>
检查Nginx配置
[root@nginx ~]# nginx -t
重载Nginx
[root@nginx ~]# systemctl reload nginx
hosts解析
10.0.0.60 test.zhangweibin.com
测试
浏览器访问:http://test.zhangweibin.com
安装Mysql(5.7版)
配置Mysql扩展源
[root@nginx ~]# rpm -ivh http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm
yum安装
[root@nginx ~]# yum install mysql-community-server -y
启动Mysql,并加入开机自启
[root@nginx ~]# systemctl start mysqld
[root@nginx ~]# systemctl enable mysqld
使用Mysq初始密码登录数据库
[root@nginx ~]# mysql -uroot -p$(awk '/temporary password/{print $NF}' /var/log/mysqld.log)
修改数据库密码
修改默认密码规则
数据库默认密码规则必须携带大小写字母、特殊符号,字符长度大于8否则会报错。
mysql> set password for root@localhost = password('123456');
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
因此设定较为简单的密码时需要首先修改set global validate_password_policy和_length参数值
mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)
修改密码
mysql> set password for root@localhost = password('123456');
Query OK, 0 rows affected, 1 warning (0.00 sec)
测试php能否连接Mysql
[root@nginx ~]# vim /code/test/mysqli.php
<?php
$servername = "localhost";
$username = "root";
$password = "6256133";
> // 创建连接
$conn = mysqli_connect($servername, $username, $password);
> // 检测连接
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "连接成功";
?>
部署workpress
下载workpress数据包
[root@nginx ~]# wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
解压到站点目录
[root@nginx ~]# tar xf wordpress-4.9.4-zh_CN.tar.gz -C /code/test
修改权限
[root@nginx ~]# chown -R www.www /code/test/
创建workpress数据库
[root@http-server ~]# mysql -uroot -p123456
mysql> create database wordpress;
mysql> exit