Linux下搭建LNMP环境

一、安装NGINX

二、安装MySQL或MariaDB

三、安装PHP

1、移除其他版本php软件

1
yum remove php-mysql php php-fpm php-common

2、更新yum源

1
2
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

3、安装PHP

1
yum install -y php71w php71w-cli php71w-common php71w-devel php71w-embedded  php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache  php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb

 

四、建立nginx和php关系

1、nginx配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
server {
    listen       80;
    server_name  blog.yinghui.com;
    location / {
        root   /html/blog;
        index index.php index.html index.htm;
    }
    location ~ \.php$ {
    fastcgi_pass  127.0.0.1:9000;
    root     /html/blog;
    fastcgi_index  index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    include fastcgi_params;
    }
}

2、测试(访问文件)

1
2
3
4
[root@web01 /html/blog]# cat test_info.php
<?php
   phpinfo();
?>

 

五、测试php和mariadb关系(打开网页显示mysql successful by root!则表示建立关系成功)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[root@web01 /html/blog]#cat test_mysql.php
<?php
     $servername = "localhost";
     $username = "root";
     $password = "123";
     //$link_id=mysql_connect('主机名','用户','密码');
     //mysql -u用户 -p密码 -h 主机
     $conn = mysqli_connect($servername, $username, $password);
     if ($conn) {
           echo "mysql successful by root !\n";
        }else{
           die("Connection failed: " . mysqli_connect_error());
        }
?>

 

六、伪静态配置

第一个步骤:在wordpress后台修改页面配置
登录后台---设置---固定链接---自定义结构--/%post_id%.html

 

第二个步骤:实现nginx伪静态配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
server {
      listen   80;
      server_name   blog.etiantian.org;
      rewrite /wp-admin$ $scheme://$host$uri/permanent;
      location / {
            root   /html/blog;
            index  index.php index.html;
            try_files $uri $uri/ /index.php?$args==$uri;
      }
      location ~ \.php$ {
            root /html/blog;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_param HTTPS on;          #支持HTTPS
            fastcgi_pass  127.0.0.1:9000;
            include fastcgi_params;
      }
 }

  

posted @   映辉  阅读(151)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示