当前位置:首页 > Linux > 正文内容

CentOS 7.9下yum安装nginx 、php、mariadb

sa2022-02-05Linux

添加nginx yum资源库:

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

image.png

安装nginx

yum -y install nginx

查看安装版本

image.png

启动nginx ,并将nginx服务加入自启

systemctl start nginx
systemctl enable nginx

防火墙放行80端口

firewall-cmd --zone=public --add-port=80/tcp --permanent

重启防火墙后查看80端口是否放行成功

[root@localhost html]# firewall-cmd --list-ports
80/tcp

测试访问正常

image.png

安装php 7.4 

yum update
yum -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum -y install yum-utils
yum-config-manager --enable remi-php74
yum install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mcrypt \
 php-mbstring php-curl php-xml php-pear php-bcmath php-json  \
 php-xmlrpc php-pdo  php-pecl-zip php-intl php-common php-imap php-odbc

安装opcache,参考 PHP官方进行配置,https://www.php.net/manual/zh/opcache.installation.php 

yum install php-opcache
vim /etc/php.d/10-opcache.ini

opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1

启动并自启动php-fpm

systemctl start php-fpm
systemctl enable php-fpm

image.png

安装mariadb

清除预装的mariadb或mysql组件

rpm -aq|grep -E "mariadb|mysql"|xargs yum remove -y;

image.png

下载完成后再次运行命令,查看是否卸载完成

rpm -aq|grep -E "mariadb|mysql"

image.png

运行下面的命令确认相关配置文件和目录的残余项

[root@vmtest01centos79 /]# find / -name mysql;
/etc/selinux/targeted/active/modules/100/mysql
/usr/lib64/mysql
[root@vmtest01centos79 /]# find / -name my.cnf;
[root@vmtest01centos79 /]# find / -name mariadb;

删除:

/usr/lib64/mysql


添加MariaDB源 ,vi /etc/yum.repos.d/MariaDB.repo

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

或将官网源更换为中科大源

[mariadb]
#mariadb 10.5
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.5/centos7-amd64/
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1

阿里云源

[mariadb]
#mariadb 10.6
name = MariaDB
baseurl = https://mirrors.aliyun.com/mariadb/yum/10.6/centos7-amd64/
gpgkey=https://mirrors.aliyun.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1

运行:

yum clean
yum makecache

安装:

yum install -y mariadb-server mariadb


启动并设置自启mariadb服务并登陆数据库

image.png

启动mariadb 后运行

mariadb-secure-installation

image.png

根据提示初始化数据库

image.png

若初始化后存在输入mysql命令不验证密码直接进入数据库的问题,运行

use mysql;
alter user 'root'@'localhost' IDENTIFIED BY 'yourpassword';

配置nginx解析php

image.png

添加或修改下面内容:

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
location ~ \.php$ {
     root /usr/share/nginx/html;
     fastcgi_pass    127.0.0.1:9000;
     fastcgi_index   index.php;
     fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
     include         fastcgi_params;
}

测试php文件是否可执行

image.png

查看其它组件是否正常,如mariadb

image.png

image.png


版权声明:本文由老瓦罐儿煨汤发布,如需转载请注明出处。

本文链接:https://www.zhangchen.cc/?id=21

评论列表

游戏攻略网
2024-07-24

识别码:hslrni92580WN-文章写的真不错https://www.gaofeick.com/识别码:zkwxgb97356LP-文章写的真不错https://www.gaofeick.com/

发表评论

访客

◎欢迎参与讨论,请在这里发表您的看法和观点。