nginx增加91端口,使得访问ip:83访问的是博客页面。
一、安装php服务
yum -y install wget
yum -y install curl
yum -y install gcc make zlib-devel pcre pcre-devel openssl-devel
yum -y install gcc*
yum install autoconf
yum -y install lsof vim
关闭防火墙
setenforce 0
systemctl stop firewalld
1.导入源
yum install epel-release
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum update
yum -y install php72w-cli php72w-common php72w-devel php72w-mysql
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
sudo yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm
2、安装yum-utils
3、开始安装
yum -y install php74 php74-php-devel
yum install php74-php-gd php74-php-pdo php74-php-mbstring php74-php-cli php74-php-fpm php74-php-mysqlnd -y
4、修改php-fpm 配置
vim /etc/opt/remi/php74/php-fpm.d/www.conf
把user = apache和group = apache 改成 user = www group = www 在这个配置文件中前面加上;就是注释 ;user = apache ;group = apache
4、启动 php-fpm
创建 www的用户 useradd www 启动php-fpm 访问 systemctl restart php74-php-fpm 检查是否启动: 方式一:lsof -i:9000 方式二:systemctl restart php74-php-fpm 查看php 版本 php74 -v
二、安装nginx
1.安装rpm 包
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
2.安装nginx
yum install -y nginx
3.启动Nginx
#修改配置
vim /etc/nginx/nginx.conf
user nginx; 改成 user www; 保存并退出
修改服务配置后要重启服务
systemctl restart nginx.service
启动服务
systemctl start nginx.service
停止服务服务
systemctl start nginx.service
4.测试php-fpm 连接
创建/opt/www 并vim /opt/www/test_php.php
<?php phpinfo(); ?>
保存并退出
授权: chown -R www.www /opt/www
vim /etc/nginx/conf.d/s2.conf
server { listen 83; server_name localhost; location / { root /opt/www; index index.php index.html; } location ~ \.php$ { root /opt/www; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; } }
重启nginx访问ip:端口/test_php.php
如果出现报错先关闭setenforce 0,systemctl stop firewalld
例如:http://192.168.145.136:83/test_php.php
出现这个页面就证明你的nginx可以连接php-fpm 服务
三、安装mysql
参考yum 安装mysql
yum 安装mysql
安装包获取
MySQL :: Download MySQL Community Server MySQL :: Download MySQL Yum Repository
官方yum源方式安装
wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
如果需要升级包可以用下面的命令
rpm -Uvh mysql80-community-release-el7-3.noarch.rpm
二、安装需要的版本
查看所有版本
yum repolist all | grep mysql
这里5.7版本是不可用的 8.0的能用 所以需要先禁用8.0的然后开启5.7版本的
yum-config-manager --disable mysql80-community
#注意#: 如果运行 yum-config-manager命令提示 -bash: yum-config-manager: command not found 命令未找到,因为 yum-config-manager 在 yum-utils包里面。由于系统默认没有这个命令,需要另外进行安装
安装yum-config-manager
yum -y install yum-utils
如果报错如下: The GPG keys listed for the “MySQL 5.7 Community Server” repository are already installed but they are not correct for this package. Check that the correct key URLs are configured for this repository
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
启用5.7版本
yum-config-manager --enable mysql57-community
三、安装MySQL
yum install -y mysql-community-server
验证MySQL
mysql --version
四、启动MySQL
查看启动状态
systemctl status mysqld.service
启动
systemctl start mysqld.service
登录MySQL
MySql服务器初始化会创建 'root@localhost’的一个超级用户账号。设置超级用户的密码并将其存储在错误日志文件中
grep 'temporary password' /var/log/mysqld.log
使用临时密码登录Mysql
mysql -uroot -p'nYZWlu&Qr4S('
重置密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'ggxl886...';
如果密码设置的太简单可能会报错,如下:
解决方法:
set global validate_password_length=6; set global validate_password_policy=0; show variables like "%validate%";
五、开启远程连接
进入mysql库执行命令
use mysql select host ,user from user;
修改权限
把root用户的host改为%
update user set host = "%" where user = "root";
刷新权限
flush privileges;
测试连接
六、MySQL相关服务命令 启动mysql服务:systemctl start mysqld.service
停止mysql服务:systemctl stop mysqld.service
重启mysql服务:systemctl restart mysqld.service
查看mysql服务当前状态:systemctl status mysqld.service
设置mysql服务开机自启动:systemctl enable mysqld.service
停止mysql服务开机自启动:systemctl disable mysqld.service
七、MySQL数据库
1.创建数据库时
create database <数据库名>
2.创建表
create table test( name varchar(20) not null, id int not null, age int not null ) default charset = utf8;
忘记密码后解决办法:
vim /etc/my.conf [mysqld] # 加上 skip-grant-tables 保存并退出后重启mysql 然后登录mysql -u root -p 回车直接登录mysql 更新密码: update mysql.user set authentication_string=PASSWORD("123456") where user="root"; 刷新: flush privileges; 退出后vim /etc/my.conf 把新加的skip-grant-tables 前面增加# 注释掉 保存退出后重启mysqld
确保:
nginx 安装并启动成功 lsof -i:83 访问页面: http://ip/test_php.php (证明: nginx 和php-fpm 是配置成功的) php-fpm 安装并启动成功 systemctl status php-fpm lsof -i:9000 mysql 安装并启动成功 systemctl status mysqld lsof -i:3306
四、下载博客
地址:WordPress主题 | WordPress.org China 简体中文
tar -xf latest-zh_CN.tar.gz解压到/opt/下
下载 wget https://cn.wordpress.org/wordpress-5.6.2-zh_CN.tar.gz 解压: tar -xf latest-zh_CN.tar.gz 移动到/opt/下 mv wordpress/ /opt/
# 切换到博客的目录下 cd /opt/wordpress/ # 复制 wp-config-sample.php 为wp-config.php cp wp-config-sample.php wp-config.php # 修改 define( 'DB_NAME', 'database_name_here' ); define( 'DB_USER', 'username_here' ); define( 'DB_PASSWORD', 'password_here' ); define( 'DB_HOST', 'localhost' ); 改为 define( 'DB_NAME', 'wordpress' ); # 数据库的库名 define( 'DB_USER', 'root' ); # 数据库的登录用户名 define( 'DB_PASSWORD', '123456' ); # 数据库的登录的密码 define( 'DB_HOST', '10.31.154.123' );# 数据库的登录的ip # 设置wordpress的权限 chown -R www.www /opt/wordpress/
创建数据库
用命令创建:
要登录数据库后
create database 数据库名称;
案例
create database cccc;
用navicat
点击数据库,右键----> 新建数据库---->
更改配置:
vim /etc/nginx/conf.d/s2.conf
root /opt/www; 替换成 root /opt/wordpress;
访问页面
登录