千家信息网

linux如何安装lnmp

发表于:2026-11-03 作者:千家信息网编辑
千家信息网最后更新 2026年11月03日,这篇文章将为大家详细讲解有关linux如何安装lnmp,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。Nginx是一个HTTP和反向代理web高性能的服
千家信息网最后更新 2026年11月03日linux如何安装lnmp

这篇文章将为大家详细讲解有关linux如何安装lnmp,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

Nginx是一个HTTP和反向代理web高性能的服务器,其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。

一,安装nginx

*nginx的官方网站:*

**http://nginx.org/en/download.html****

*Mainline version* *主线版本*

*Stable version* *稳定版本*

*Legacy versions* *遗产版本 /历史版本*

1.下载

安装前确认安装扩展 没有的直接 yum install wget gcc gcc-c++ pcre-devel zlib-devel openssl openssl-devel

[root@localhost ~]# cd /usr/local/src/[root@localhost src]# wget http://nginx.org/download/nginx-1.12.2.tar.gz

2.解压

[root@localhost src]# tar zxvf nginx-1.12.2.tar.gz

/** 取消Debug编译模式 START***/

cd nginx-1.12.2

vi auto/cc/gcc #将这句注释掉 取消Debug编译模式 大概在172行 #CFLAGS="$CFLAGS -g"

/**取消Debug编译模式 END******/

\3. 预编译

 cd nginx-1.12.2 ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_v2_module --with-http_stub_status_module --with-pcre --with-http_gzip_static_module --with-http_dav_module   --with-http_addition_module  --with-http_sub_module --with-http_flv_module  --with-http_mp4_module

解释

–with-http_gzip_static_module :支持压缩

–with-http_stub_status_module :支持nginx状态查询

–with-http_ssl_module :支持https

–with-pcre :为了支持rewrite重写功能,必须制定pcre

–with-http_dav_module #启用支持(增加PUT,DELETE,MKCOL:创建集合,COPY和MOVE方法)
–with-http_addition_module #启用支持(作为一个输出过滤器,支持不完全缓冲,分部分相应请求) –with-http_sub_module #启用支持(允许一些其他文本替换Nginx相应中的一些文本) –with-http_flv_module #启用支持(提供支持flv视频文件支持) –with-http_mp4_module #启用支持(提供支持mp4视频文件支持,提供伪流媒体服务端支持)

**make -j 4 && make install 4核编译****

\4. [root@localhost src]# make && make install

5.添加系统变量(方便启停服务)

[root@localhost nginx-1.12.2]# vim /etc/profile

我一般是在56行添加 export PATH=/usr/local/nginx/sbin:$PATH

重启配置 source /etc/profile

[root@localhost nginx-1.12.2]# nginx -V

**添加软连 ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/****

*生成服务启动脚本*

**vim /etc/init.d/nginx****

#!/bin/bash# chkconfig: - 99 2# description: Nginx Service Control ScriptPROG="/usr/local/nginx/sbin/nginx"PIDF="/usr/local/nginx/logs/nginx.pid"case "$1" in        start)        $PROG        ;;        stop)        kill -3 $(cat $PIDF)        ;;        restart)        $0 stop &> /dev/null        if [ $? -ne 0 ] ; then continue ; fi        $0 start        ;;        reload)        kill -1 $(cat $PIDF)        ;;        *)        echo "Userage: $0 { start | stop | restart | reload }"        exit 1esacexit 0

配置服务开机自动启动 [root@localhost ~]# chmod +x /etc/init.d/nginx [root@localhost ~]# chkconfig –add nginx [root@localhost ~]# chkconfig nginx on

首次启动 /usr/local/nginx/sbin/nginx

二、安装mysql 5.7

用的是rpm 好处是不用配置那么多东西 。 配置不用管。

[root@localhost ~]# cd /usr/local/src/ [root@localhost src]# wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm[root@localhost src]# rpm -ivh mysql57-community-release-el7-8.noarch.rpm[root@localhost src]# yum -y install mysql-server

(*也可以指定安装目录** yum **–installroot=/usr/local/mysql –releasever=/* -y install mysql-server 可以自己研究**)**

根据步骤安装就可以了,

默认配置文件路径: 配置文件:/etc/my.cnf 日志文件:/var/log/var/log/mysqld.log 服务启动脚本:/usr/lib/systemd/system/mysqld.service

socket文件:/var/run/mysqld/mysqld.pid

启动mysql服务

service mysqld restart

重置密码

[root@localhost ~]# grep "password" /var/log/mysqld.log

可以看到 输入 mysql -u root -p 密码 进入 第一次登陆 ,需要重置密码 要不什么也不能操作

接下来重置密码:5.7.20 为了安全密码 必须包含 数字字母符号

*alter user ‘root’@’localhost’ identified by ‘Root!!2018’;*

也可以 直接再添加新用户

grant all on . to ‘rootadmin’@’%’ identified by ‘Root@@’ with grant option;

增加root用户指定可以任意IP登录,如果想限制只能让指定IP登录请把%替换成IP地址

最后记得刷新权限;

flush privileges ;

三、安装php

需要的插件 包

yum -y install gcc gcc-c++ libxml2 libxml2-devel bzip2 bzip2-devel libmcrypt libmcrypt-devel openssl openssl-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel readline readline-devel libxslt-devel perl perl-devel psmisc.x86_64 recode recode-devel libtidy libtidy-devel  epel-release libmcrypt-devel  autoconf

1.下载

[root@localhost ~]# cd /usr/local/src/[root@localhost src]# wget http://cn2.php.net/distributions/php-5.6.32.tar.gz

2.解压

[root@localhost src]# tar zxvf php-5.6.32.tar.gz

\3. 预编译

进入目录 [root@localhost src]``# cd php-5.6.32

创建php-fpm用户,并禁止登录; [root@localhost php-5.6.32]# useradd -s /sbin/nologin php-fpm

./configure --prefix=/usr/local/php --sysconfdir=/usr/local/php/etc --with-config-file-path=/usr/local/php/etc/    --with-fpm-user=php-fpm  --with-fpm-group=php-fpm  --enable-fpm --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mhash  --with-openssl --with-zlib --with-bz2 --with-curl --with-libxml-dir --with-gd --with-jpeg-dir  --with-png-dir --with-zlib --enable-mbstring --with-mcrypt --enable-sockets --with-iconv-dir   --enable-zip --with-pcre-dir --with-pear --enable-session  --enable-gd-native-ttf  --enable-xml --with-freetype-dir --enable-gd-jis-conv --enable-inline-optimization --enable-shared  --enable-soap --enable-bcmath --enable-sysvmsg --enable-sysvsem --enable-sysvshm  --enable-mbregex --enable-pcntl --with-xmlrpc --with-gettext --enable-exif --with-readline   --enable-ftp   --enable-redis

提示错误mcrypt.h没有找到,安装libmcrypt-devel包,默认的yum源,没有这个包,需要安装epel扩展源后,才可以安装。

[root@localhost php-5.6.32]# yum install -y epel-release[root@localhost php-5.6.32]# yum install -y libmcrypt[root@localhost php-5.6.32]# yum install -y libmcrypt-devel

再次执行./configure,没有错误提示,出现Thank you for using PHP,配置OK。

完成后使用echo $?查看是否安装正确; [root@localhost php-5.6.32]# make && make install

[root@localhost php-5.6.32]# echo $?

0 0表示上一步的结果成功。

配置文件

需要将当前目录下的php.ini文件拷贝到 php的安装目录etc下

[root@localhost php-5.6.32]# cp php.ini-production /usr/local/php/etc/php.ini

php.ini 文件是在包目录下的 php.ini-development(开发), php.ini-production(生产)

拷贝php启动脚本,php-fpm配置文件,更改php-fpm权限为755;添加php-fpm开机启动;

[root@ php-5.6.32]# cp /usr/local/src/php-5.6.32/sapi/fpm/init.d.php-fpm   /etc/init.d/php-fpm [root@ php-5.6.32]# mv /usr/local/php/etc/php-fpm.conf.default   /usr/local/php/etc/php-fpm.conf  (就是去掉了末尾的.default )[root@ php-5.6.32]# chmod 755 /etc/init.d/php-fpm [root@lphp-5.6.32]# chkconfig --add php-fpm [root@lphp-5.6.32]# service php-fpm start Starting php-fpm  done[root@php-5.6.32]# chkconfig php-fpm on

将php的安装目录也加入到系统的环境变量 在最后一行加入

vim /etc/profile

export PATH=/usr/local/php/bin:$PATH

source /etc/profile 重新加载

[root@localhost ~]# php -v PHP 5.6.32 (cli) (built: Mar 12 2018 17:43:15) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies完成 接下来就是测试

—–php—安装成功

三、测试 在地址栏输入你的ip。然后测试PHP安装是否成功。确保nginx 和PHP都是运行的。

  1. 写测试页面

  2. 进入nginx的html cd /usr/local/nginx/html/


编辑 vim index.php

\2. 配置nginx

核心配置的两个 加入到nginx.conf

vim /usr/local/nginx/conf/nginx.conf

找到 location 添加 index.php

将请求转给php的9000端口 确保nginx 和PHP都是运行的哈。

location ~ .php$ {

root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME

fastcgi_script_name; include fastcgi_params; }

到此lnmp就已经安装结束了。

关于linux如何安装lnmp就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

支持 配置 文件 服务 目录 编译 密码 版本 测试 成功 模式 用户 系统 脚本 登录 接下来 不用 内容 功能 变量 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 耶加雪菲 伟宏互联网科技 互联网扶贫科技 高科技与互联网 百单互联网科技有限公司 米客互联网科技 中国互联网金融科技基金 开启互联网科技时代小说 深圳市运趣互联网科技有限公司 互联网企业和科技型企业 互联网科技与管理 宝灵互联网科技有限公司 洛阳昕诺飞互联网科技有限公司 银川新华互联网科技学校联系电话 互联网科技大赛获奖感言 山东星卡互联网科技有限公司官网 银行科技岗属于互联网吗 艺电能源互联网科技有限公司招聘 第三届互联网大会安防黑科技 互联网科技创业有什么好项目 互联网科技产业 互联网最新的科技有限公司 关于新基建和互联网科技 有木互联网科技 广州慧亚互联网科技怎么样 广州恒生互联网科技有限 互联网5g黑科技有哪些 佛山市拉法互联网科技有限公司 元气玛特互联网科技公司是外包吗 互联网公司高科技产品
0