Linux用php+mysql 连接博客

该文详细介绍了如何在CentOS7系统中安装PHP(包括PHP7.4)、Nginx、MySQL,并配置相关服务。接着,演示了下载并安装WordPress,以及创建数据库和配置WordPress的过程。
摘要由CSDN通过智能技术生成

一,安装php服务

1.首先在虚拟机上安装需要的命令

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

2,导入源

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

3.安装yum-utils

yum install yum-utils

4.安装php

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

5.修改配置 

在vim /etc/opt/remi/php74/php-fpm.d/www.conf

把user = apache和group = apache 改成 user = www  group = www

6.检测是否启动php-fpm

创建 www的用户
useradd www

启动php-fpm 访问
systemctl restart php74-php-fpm

检查是否启动:
方式一:lsof -i:9000         方式二:systemctl restart php-fpm 

 二,安装nginx

1.安装包

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.启动

启动前先修改配置

将vim /etc/nginx/nginx.conf
user  nginx; 改成 user  www;  保存并退出

修改服务配置后要重启服务

systemctl restart nginx.service  #重启
systemctl start nginx.service    #开始
systemctl stop nginx.service     #停止

4.测试连接

创建/opt/www 并vim /opt/www/test_php.php 写下面的代码:

<?php
   phpinfo();
?>

5.授权

chown -R www.www    /opt/www

6.在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;
       }
    }

7.关闭防火墙重启nginx

setenforce 0
systemctl restart nginx
systemctl stop firewalld

8.访问 ip:端口/test_php.php 看是否连接成功

三,安装mysql

1.下载安装包

wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

如需升级用下面的

rpm -Uvh mysql80-community-release-el7-3.noarch.rpm

2.查看所有版本

yum repolist all | grep mysql

这里5.7版本是不可用的 8.0的能用 所以需要先禁用8.0的然后开启5.7版本的

yum -config-manager --disable mysql80-community 

3,安装yum-config-manager

yum -y install yum-utils

如果报错用下面的代码:

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

4,启用5.7版本

yum-config-manager --enable mysql57-community

5.安装

yum install -y mysql-community-server 

6.启用mysql并查看状态

systemctl start mysqld.service
systemctl status mysqld.service

 7.登录mysql

用grep 'temporary password' /var/log/mysqld.log 查看密码

使用临时密码登录mysql

mysql -uroot -p')*T&*hncu3()'

8.重置密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'ggxl886...';

如果密码设置的太简单可能会报错,如下:

set global validate_password.length=6;

set global  validate_password.policy=0;

show variables like "%validate%";

9.开启远程连接

在数据库输入

use mysql
select host ,user from user; 

修改权限

update user set host = "%" where user = "root";

刷新权限

flush privileges;

10.创建数据库

create database <数据库名> 

四,下载博客

1.下载

wget   https://cn.wordpress.org/wordpress-5.6.2-zh_CN.tar.gz

2.解压下载的文件

tar -xf latest-zh_CN.tar.gz

3.移动到/opt/下

mv wordpress/  /opt/

4.修改配置

# 切换到博客的目录下
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/

如图:

在vim /etc/nginx/conf.d/s2.conf

root /opt/www; 替换成  root /opt/wordpress;

5.创建数据库

6.访问页面

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值