CentOS 7 用户怎样安装 LNMP

2025-03-14 00:49:13
推荐回答(1个)
回答1:

LNMP一般是指Linux + Nginx+MySQL + PHP.

1、Nginx安装

[root@Linux ~]# yum -y install gcc gcc-c++ autoconf automake openssl openssl-devel pcre-devel zlib-devel #安装编译软件库

[root@Linux ~]# wget http://nginx.org/download/nginx-1.6.2.tar.gz #下载nginx 1.6.2源码包

[root@Linux ~]# tar zxvf nginx-1.6.2.tar.gz

[root@Linux ~]# cd nginx-1.6.2

[root@Linux nginx-1.6.2]# ./configure --with-http_stub_status_mocule --prefix=/opt/nginx #编译设置模块

[root@Linux nginx-1.6.2]# make && make install安装

[root@Linux ~]# /opt/nginx/sbin/nginx -s reload #nginx重新启动

[root@Linux ~]# /opt/nginx/sbin/nginx #nginx启动

[root@Linux ~]# /opt/nginx/sbin/nginx -t #nginx检测配置

2、PHP的安装和配置

[root@Linux ~]# yum install -y gcc-c++ libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel mysql mysql-devel #安装php依赖软件库

[root@Linux ~]# wget http://am1.php.net/distributions/php-5.6.3.tar.gz #下载php5.6源码包

[root@Linux ~]# tar -zxvf php-5.6.3.tar.gz

[root@Linux ~]# cd php-5.6.3

[root@Linux php-5.6.3]# ./configure --prefix=/usr/local/php --with-mysql=mysqlnd--with-mysqli=mysqlnd --enable-fpm --with-pear --with-curl --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv --with-mhash --with-zlib --enable-mbstring --disable-debug #编译设置模块

[root@Linux php-5.6.3]# make && make install #编译安装

[root@Linux php-5.6.3]# cp php.ini-production /opt/php/lib/php.ini #复制php配置文件

[root@Linux php-5.6.3]# /opt/php/sbin/php-fpm #启动php-fpm

[root@Linux php-5.6.3]# /opt/php/sbin/php-fpm -t #检测配置是否正确

在centos上成功编译安装nginx 1.6、php 5.6并成功启动nginx和php-fpm后,访问php提示”File not found.”,同时在错误日志中看到:

2013/10/22 20:05:49 [error] 12691#0: *6 FastCGI sent in stderr: “Primary script unknown” while reading response header from upstream, client: 192.168.168.1, server: localhost, request: “GET / HTTP/1.1″, upstream: “fastcgi://127.0.0.1:9000″, host: “192.168.168.133”:

在Nginx配置文件中找到定义调用脚本文件的地方,如:

fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;

修改成如下方式($document_root):

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

nginx gzip设置

gzip on;

gzip_min_length 1k;

gzip_buffers 4 16k;

gzip_http_version 1.1;

gzip_comp_level 2;

gzip_types text/plain application/x-javascript text/css applocation/xml;

gzip_vary on;

3、MySQL的安装

[root@lamp ~]# yum install mysql mysql-server mysql-devel
启动mysql服务:/etc/init.d/mysqld start

设置mysql密码:
直接使用”mysql”进入数据库模式,
mysql> USE mysql;
mysql> UPDATE user SET Password=PASSWORD(‘newpassword’) WHERE user=’root';
mysql> FLUSH PRIVILEGES;

来源:PHP程序员雷雪松的博客