美文网首页
yum安装lnmp

yum安装lnmp

作者: 挑战_bae7 | 来源:发表于2020-12-17 14:31 被阅读0次

1.安装nginx

cat > /etc/yum.repos.d/nginx.repo <<EOF
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/\$releasever/\$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
EOF
yum install nginx -y
systemctl start nginx
systemctl enable nginx

2.安装php

配置php72yum源
 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 -y remove php*
yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-fpm php72w-gd php72w-mbstring php72w-mysqlnd php72w-opcache php72w-pdo php72w-xml
systemctl start php-fpm
systemctl enable php-fpm

3.安装mysql

rpm -ivh http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm
yum install mysql-community-server -y
systemctl start mysqld
systemctl enable mysqld

4.配置nginx 测试

 vim /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;
    location / {
        root  /soft/code;
        index  index.html index.htm;
    }
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
location ~ \.php$ {
    root           html;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  /soft/code$fastcgi_script_name;
    include        fastcgi_params;
}
}
[root@localhost code]# cat info.php 
<?php
phpinfo();
?>
mysqli连接
[root@localhost code]# cat mysqli.php 
<?php
$servername = "127.0.0.1";
$username = "root";
$password = "";
 
// 创建连接
$conn = new mysqli($servername, $username, $password);
 
// 检测连接
if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
} 
echo "连接成功";
?>
mysqlpdo连接
[root@localhost code]# cat pdo.php 
<?php
$servername = "127.0.0.1";
$username = "root";
$password = "";
 
try {
    $conn = new PDO("mysql:host=$servername;", $username, $password);
    echo "连接成功"; 
}
catch(PDOException $e)
{
    echo $e->getMessage();
}
?>

5.排错PHP连接mysql数据报错 No such file or directory

这是因为修改mysql socket 位置造成的 修改 
vim /etc/php.ini 
.....
pdo_mysql.default_socket=
.....
mysqli.default_socket =
.....
修改成/tmp/mysql.socket 重启php-fpm
如果发现连接还是报错的话,把servername 改成127.0.0.1,别用localhost

6.nginx 访问php原理

图片.png
nginx fastcgi 访问 php
1.⽤用户发送http请求报⽂文给nginx服务器器
2.nginx会根据⽂文件url和后缀来判断请求
3.如果请求的是静态内容,nginx会将结果直接返回给⽤用户
4.如果请求的是动态内容,nginx会将请求交给fastcgi客户端,通过fastcgi_pass将这个请求发送给php-fpm
5.php-fpm收到请求后会通过本地监听的socket交给wrapper
6.wrapper收到请求会⽣生成新的线程调⽤用php动态程序解析服务器器
7.如果⽤用户请求的是博⽂文、或者内容、PHP会请求MySQL查询结果
8.如果⽤用户请求的是图⽚片、附件、PHP会请求nfs存储查询结果
9.php会将查询到的结果交给Nginx
10.nginx会⽣生成⼀一个响应报⽂文返还给⽤用户

7.PHP配置及优化

//打开php的安全模式,控制php执⾏行行危险函数, 默认是Off,改为On
sql.safe_mode = Off
//关闭php头部信息, 隐藏版本号, 默认是On,该为Off
expose_php = On
//错误信息输出控制
display_error = Off
error_reporting = E_WARNING & E_ERROR
//记录错误⽇日志⾄至后台, ⽅方便便追溯
log_errors = On
error_log = /var/log/php_error.log
//每个脚本时间最⼤大内存
memory_limit = 128M
//上传⽂文件最⼤大许可,默认2M, 建议调整为16,32M
upload_max_filesize = 2M
//禁⽌止远程执⾏行行phpshell,默认On, 建议Off
allow_url_fopen = On
//时区调整,默认PRC, 建议调整为Asia/Shanghai
date.timezone = PRC

//整体优化后配置⽂文件
sql.safe_mode = Off
expose_php = Off
display_error = Off
error_reporting = E_WARNING & E_ERROR
log_errors = On
error_log = /var/log/php_error.log
upload_max_filesize = 50M
allow_url_fopen = Off
date.timezone = Asia/Shanghai
[root@nginx ~]# cat /etc/php-fpm.d/www.conf
[global]
pid = /var/run/php-fpm.pid
#php-fpm程序错误⽇日志
error_log = /var/log/php/php-fpm.log
log_level = warning
rlimit_files = 655350
events.mechanism = epoll
[www]
user = nginx
group = nginx
listen = 127.0.0.1:9000
listen.owner = www
listen.group = www
listen.mode = 0660

listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 512
pm.start_servers = 10
pm.min_spare_servers = 10
pm.max_spare_servers = 30
pm.process_idle_timeout = 15s;
pm.max_requests = 2048
#php-www模块错误⽇日志
php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/php/php-www.log
php_admin_flag[log_errors] = on
#php慢查询⽇日志
request_slowlog_timeout = 5s
slowlog = /var/log/php/php-slow.log

PHP5-FPM配置详解释
[global]
#pid设置, 记录程序启动后pid
pid = /var/run/php-fpm.pid
#php-fpm程序启动错误⽇日志路路径
error_log = /soft/log/php/php-fpm_error.log
# 错误级别. 可⽤用级别为: alert(必须⽴立即处理理),error(错误情况), warning(警告情况), not
ice(⼀一般重要信息), debug(调试信息). 默认: notice.
log_level = warning
#设置⽂文件打开描述符的rlimit限制.
rlimit_files = 65535
events.mechanism = epoll
#启动进程的⽤用户和组
[www]
user = www
group = www
# fpm监听端⼝口
listen = 127.0.0.1:9000
# unix socket设置选项,如果使⽤用tcp⽅方式访问,这⾥里里注释即可。
listen.owner = www
listen.group = www
# 允许访问FastCGI进程的IP,any不不限制
listen.allowed_clients = 127.0.0.1
# pm设置动态调度
pm = dynamic
# 同⼀一时刻最⼤大的php-fpm⼦子进程数量量
pm.max_children = 200
# 动态⽅方式下的起始php-fpm进程数量
pm.start_servers = 20
# 动态⽅方式下服务器器空闲时最⼩小php-fpm进程数量量
pm.min_spare_servers = 10
# 动态⽅方式下服务器器空闲时最⼤大php-fpm进程数量量
pm.max_spare_servers = 30
# 最⼤大请求
pm.max_requests = 1024
pm.process_idle_timeout = 15s;
# FPM状态⻚页⾯面,⽤用于监控php-fpm状态使⽤用
pm.status_path = /status
# 错误⽇日志
php_flag[display_errors] = off
php_admin_value[error_log] = /soft/log/php/php-www_error.log
php_admin_flag[log_errors] = on
# 配置php慢查询, 以及慢查询记录⽇日志位置
request_slowlog_timeout = 5s
slowlog = /soft/log/php/php-slow.log

7.部署wordpress

注意wordpress版本支持php版本
wget https://cn.wordpress.org/latest-zh_CN.tar.gz
tar xf latest-zh_CN.tar.gz -C /soft/code/
create database wordpress; 
grant all on wordpress.* to wordpress@'127.0.0.1' identified by '123456'; 
cd /soft/code/wordpress
cp wp-config-sample.php wp-config.php  修改里面连接mysql的信息 
或者 根据wordpress 生成的文件创建这个文件

相关文章

  • 在CentOS环境搭建wordpress

    准备 LNMP 环境 安装 Nginx 使用yum安装 Nginx: yum install nginx -y 修...

  • centos7 安装lnmp

    yum安装lnmp(linux+nginx+php7.1+mysql5.7) yum安装nginx 安装nginx...

  • LNMP搭建

    LNMP之nginx安装 编译安装 1、准备yum仓库 :~#cd/etc/yum.repos.d/:~#wget...

  • 项目分步9:配置监控服务

    部署运行环境LNMP 安装LNMP环境 [root@zabbix55 ~]# yum -y install gcc...

  • lnmp的搭建

    lnmp = linux + nginx + mysql + php 1.首先安装nginx(yum安装和编译安装...

  • yum安装lnmp

    1.安装nginx 2.安装php 3.安装mysql 4.配置nginx 测试 5.排错PHP连接mysql数据...

  • centos7 YUM安装lnmp

    1、安装LNMP之前要安装EPEL,以便安装源以外的软件,如Nginx,phpMyAdmin等。 yum inst...

  • 12.CentOS7.5源码编译搭建LNMP架构+Swoole+

    部署 LNMP 架构需要安装依赖包 安装 epel 扩展 yum 源 一、安装并配置Nginx 所需依赖包 另外:...

  • LNMP架构搭建

    急速安装lnmp 编译版本 安装msyql+PHP 系统centos6.5 安装 开发软件包yum -y grou...

  • centOS 7.0.md

    [TOC] 安装lnmp架构 配置 YUM 源 CentOS 7 的 默认 YUM 源里的软件包版本可能不是最新的...

网友评论

      本文标题:yum安装lnmp

      本文链接:https://www.haomeiwen.com/subject/hpgagktx.html