Linux中用php-fpm,mysql,nginx安装博客

本文详细介绍了如何在Linux环境中通过php-fpm、mysql和nginx搭建博客系统。首先,通过VMware Workstation Pro和Xshell连接虚拟机。接着,安装php服务,包括导入源、安装yum-utils、启动php-fpm。然后,安装nginx并修改配置以允许连接php-fpm。再安装mysql,包括选择版本、禁用与启用版本、初始化数据库,并开启远程连接。最后,下载博客文件,配置数据库连接,并完成安装。

一,下载VMware Workstation Pro,Xshell 7,连接虚拟机

 

 二,安装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

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

yum update

yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm

2、安装yum-utils

yum-utils 可以扩展yum的默认功能,用于管理yum存储库以及程序包,而无需进行任何手动配置,yum-utils提供的程序之一是yum-config-manager,可以使用它来启用Remi存储库作为默认存储库,以安装不同的PHP版本。

[root@localhost ~]# yum install yum-utils

3、开始安装

[root@localhost ~]#  yum -y install php74 php74-php-devel
[root@localhost ~]# yum install php74-php-gd  php74-php-pdo 
php74-php-mbstring php74-php-cli php74-php-fpm php74-php-mysqlnd -y

4、修改php-fpm 配置

[root@localhost ~]# vim /etc/opt/remi/php74/php-fpm.d/www.conf

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

5、启动 php-fpm

创建 www的用户

[root@localhost ~]# useradd www

 启动php-fpm 访问

[root@localhost ~]# systemctl restart php74-php-fpm

检查是否启动:

php-fpm成功启动如下:

[root@localhost ~]# systemctl status php74-php-fpm
● php74-php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php74-php-fpm.service; disabled; vendor preset: disabled)
   Active: active (running) since 三 2023-06-14 16:24:57 CST; 54min ago
 Main PID: 15879 (php-fpm)
   Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
   CGroup: /system.slice/php74-php-fpm.service
           ├─15879 php-fpm: master process (/etc/opt/remi/php74/php-fpm.conf)
           ├─15880 php-fpm: pool www
           ├─15881 php-fpm: pool www
           ├─15882 php-fpm: pool www
           ├─15883 php-fpm: pool www
           └─15884 php-fpm: pool www

6月 14 16:24:56 localhost.localdomain systemd[1]: Starting The PHP FastCGI Process Manager...
6月 14 16:24:57 localhost.localdomain systemd[1]: Started The PHP FastCGI Process Manager.
[root@localhost ~]#

 查看php 版本

[root@localhost ~]# php74  -v
PHP 7.4.33 (cli) (built: Jun  6 2023 15:55:08) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
[root@localhost ~]#

 三、安装nginx

1.安装rpm 包

[root@localhost ~]# rpm -Uvh http://nginx.org/packages/centos/7/noarch/
RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

 2.安装nginx

[root@localhost ~]# yum install -y nginx

 3.启动Nginx

[root@localhost ~]# vim /etc/nginx/nginx.conf

 修改配置
user  nginx; 改成 user  www;  保存并退出

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

[root@localhost ~]# systemctl restart nginx.service

4.测试php-fpm 连接

创建/opt/www 文件夹    并vim /opt/www/test_php.php,添加内容

<?php
        phpinfo();
?>

 保存并退出,授权

[root@localhost ~]# vim /opt/www/test_php.php

 添加配置文件 

[root@localhost ~]# vim /etc/nginx/conf.d/s2.conf

添加以下内容 ,端口为83

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 ,如果出现报错先关闭防火墙,代码如下

[root@localhost ~]# setenforce 0
[root@localhost ~]# systemctl stop firewalld

 出现这个页面就证明你的nginx可以连接php-fpm 服务

四、安装mysql

 1.官方yum源方式安装

[root@localhost ~]# wget https://dev.mysql.com/get/mysql80
-community-release-el7-3.noarch.rpm

如果需要升级包可以用下面的命令

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

2、安装需要的版本

查看所有版本

[root@localhost ~]# yum repolist all | grep mysql

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

[root@localhost ~]# 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

3、安装MySQL

yum install -y mysql-community-server 

验证MySQL

mysql --version

4、启动MySQL

查看启动状态

systemctl status mysqld.service

 启动

systemctl start mysqld.service

登录MySQL

MySql服务器初始化会创建 'root@localhost’的一个超级用户账号。设置超级用户的密码并将其存储在错误日志文件中

grep 'temporary password' /var/log/mysqld.log

使用上行代码里的临时密码登录Mysql

mysql -uroot -p'd26gtss3wj'

重置密码

ALTER USER 'root'@'localhost' IDENTIFIED BY '123456';

如果密码设置的太简单可能会报错,解决方法:

set global validate_password_length=6;

set global  validate_password_policy=0;

show variables like "%validate%";

5、开启远程连接

进入mysql库执行命令

use mysql
select host ,user from user; 

修改权限

把root用户的host改为%

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

刷新权限

flush privileges;

测试连接

 连接成功

 

 

 下载Navicat Premium ,主机为IP地址

五、下载博客

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
[root@localhost wordpress]# vim wp-config.php

 改为
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;

开启无痕模式浏览器 ,网址http://ip:端口/wp-admin/install.php

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值