LNMP服务搭建

搭建环境:一台主机 192.168.56.12
安装nginx,mysql,php
关闭防火墙,selinux

1.编译安装nginx
//创建系统用户
[[email protected] ~]# useradd -r -M -s /sbin/nologin nginx
//安装依赖环境
[[email protected] ~]# yum -y install pcre-devel openssl openssl-devel gd-devel
[[email protected] ~]# yum -y groups mark install ‘Development Tools‘

//创建日志存放目录,并更改属主属主
[[email protected] ~]# mkdir -p /var/log/nginx
[[email protected] ~]# chown -R nginx.nginx /var/log/nginx
//下载nginx,可在官网先下来
[[email protected] ~]# cd /usr/src/
[[email protected] src]# ls
debug kernels
[[email protected] src]# ls
debug kernels nginx-1.14.0.tar.gz

//编译安装
[[email protected] src]# cd nginx-1.14.0
[[email protected] nginx-1.14.0]# ./configure \

--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--with-debug \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_image_filter_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-log-path=/var/log/nginx/access.log \
--error-log-path=/var/log/nginx/error.log

出现 checking for OS

  • Linux 3.10.0-693.el7.x86_64 x86_64
    checking for C compiler ... not found
    ./configure: error: C compiler cc is not found
    则需要安装依赖包gcc
    [[email protected] nginx-1.14.0]# yum install gcc -y
    [[email protected] nginx-1.14.0]# make && make install

//配置环境变量并使其生效
[[email protected] ~]# echo ‘export PATH=/usr/local/nginx/sbin:$PATH‘ > /etc/profile.d/nginx.sh
[[email protected] ~]# . /etc/profile.d/nginx.sh

//服务控制方式,使用nginx命令
-t //检查配置文件语法
-v //输出nginx的版本
-c //指定配置文件的路径
-s //发送服务控制信号,可选值有{stop,quit,reopen,reload}

//启动nginx
[[email protected] ~]# nginx
[[email protected] ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :80 :
LISTEN 0 128
:22 :
LISTEN 0 100 127.0.0.1:25 :
LISTEN 0 128 :::22 :::
LISTEN 0 100 ::1:25 :::

2.安装mysql二进制包
//安装依赖包
[[email protected] ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
//创建用户和组
[[email protected] ~]# groupadd -r -g 306 mysql
[[email protected] ~]# useradd -M -s /sbin/nologin -g 306 -u 306 mysql
//下载软件包
[[email protected] ~]# cd /usr/src/
[[email protected] src]# wget https://downloads.mysql.com/archives/get/file/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
// 解压至/usr/local
[[email protected] src]# tar xf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
[[email protected] src]# cd /usr/local/
[[email protected] local]# ls
bin games lib libexec nginx share
etc include lib64 mysql-5.7.22-linux-glibc2.12-x86_64 sbin src
[[email protected] local]# ln -sv mysql-5.7.22-linux-glibc2.12-x86_64/ mysql
‘mysql’ -> ‘mysql-5.7.22-linux-glibc2.12-x86_64/’

//更改/usr/local/mysql的属主属组
[[email protected] local]# chown -R mysql.mysql /usr/local/mysql
[[email protected] local]# ll -d /usr/local/mysql
lrwxrwxrwx. 1 mysql mysql 36 Aug 25 22:00 /usr/local/mysql -> mysql-5.7.22-linux-glibc2.12-x86_64/

//添加环境变量
[[email protected] ~]# ls /usr/local/mysql
bin COPYING docs include lib man README share support-files
[[email protected] ~]# echo ‘export PATH=/usr/local/mysql/bin:$PATH‘ > /etc/profile.d/mysql.sh
[[email protected] ~]# . /etc/profile.d/mysql.sh
[[email protected] ~]# echo $PATH
/usr/local/mysql/bin:/usr/local/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

//建立数据存放目录,并更改属主属组
[[email protected] ~]# mkdir /opt/data
[[email protected] ~]# chown -R mysql.mysql /opt/data/
[[email protected] ~]# ll /opt/
total 0
drwxr-xr-x. 2 mysql mysql 6 Aug 25 22:02 data

//初始化数据库
[[email protected] ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/opt/data/
//初始化后会在屏幕输出内容最后一行产生一个随机密码,需要记下来登录数据库用
[[email protected] ~]# echo ‘fWqjgTJxt7*R‘ > /etc/pass.txt

//配置mysql
[[email protected] ~]# ln -sv /usr/local/mysql/include/ /usr/local/include/mysql
‘/usr/local/include/mysql’ -> ‘/usr/local/mysql/include/’
[[email protected] ~]# echo ‘/usr/local/mysql/lib‘ > /etc/ld.so.conf.d/mysql.conf
[[email protected] ~]# ldconfig -v
//生成配置文件
[[email protected] ~]# cat > /etc/my.cnf <<EOF

[mysqld]
basedir = /usr/local/mysql
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
EOF

//配置服务启动脚本
[[email protected] ~]# cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
[[email protected] ~]# sed -ri ‘s#^(basedir=).#\1/usr/local/mysql#g‘ /etc/init.d/mysqld
[[email protected] ~]# sed -ri ‘s#^(datadir=).
#\1/opt/data#g‘ /etc/init.d/mysqld

//启动mysql
[[email protected] ~]# service mysqld start
Starting MySQL.Logging to ‘/opt/data/hyj.com.err‘.
. SUCCESS!

//登录数据库修改密码
[[email protected] ~]# cat /etc/pass.txt
fWqjgTJxt7R
[[email protected] ~]# mysql -uroot -pfWqjgTJxt7
R
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.22
...
...

mysql> set password=password(‘ran1027.‘);
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> quit
Bye

3.安装php
//配置yum源
[[email protected] ~]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
[[email protected] yum.repos.d]# sed -i ‘s/\$releasever/7/g‘ /etc/yum.repos.d/CentOS7-Base-163.repo
[[email protected] yum.repos.d]# sed -i ‘s/^enabled=.*/enabled=1/g‘ /etc/yum.repos.d/CentOS7-Base-163.repo
//安装扩展源
[[email protected] yum.repos.d]# yum -y install epel-release
//安装依赖包
[[email protected] ~]# yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel

//下载php
[[email protected] ~]# cd /usr/src/
[[email protected] src]# wget http://cn.php.net/distributions/php-7.2.8.tar.xz
//编译安装php
[[email protected] src]# tar xf php-7.2.8.tar.xz
[[email protected] src]# cd php-7.2.8
[[email protected] php-7.2.8]# ./configure --prefix=/usr/local/php7 \

--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir=/usr \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-jpeg-dir \
--with-png-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--with-bz2 \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip
[[email protected] ~]# make && make install

//安装后配置
[[email protected] ~]# echo ‘export PATH=/usr/local/php7/bin:$PATH‘ > /etc/profile.d/php7.sh
[[email protected] ~]# source /etc/profile.d/php7.sh
[[email protected] ~]# which php
/usr/local/php7/bin/php
[[email protected] ~]# php -v
PHP 7.2.8 (cli) (built: Aug 25 2018 22:34:56) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies

//配置php-fpm
[[email protected] php-7.2.8]# cp php.ini-production /etc/php.ini
[[email protected] php-7.2.8]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[[email protected] php-7.2.8]# chmod +x /etc/rc.d/init.d/php-fpm
[[email protected] php-7.2.8]# cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
[[email protected] php-7.2.8]# cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

//编辑php-fpm的配置文件(/usr/local/php7/etc/php-fpm.conf)
//配置相关选项为自己所需要的值
[[email protected]j ~]# vim /usr/local/php7/etc/php-fpm.conf
...
...
pm.max_children = 50 //最多同时提供50个进程提供50个并发服务
pm.start_servers = 5 //启动时启动5个进程
pm.min_spare_servers = 2 //最小空闲进程数
pm.max_spare_servers = 8 //最大空闲进程数

//启动php-fpm
//默认情况下,fpm监听在127.0.0.1的9000端口
[[email protected] ~]# service php-fpm start
Starting php-fpm done
[[email protected] ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 :80 :
LISTEN 0 128
:22 :
LISTEN 0 100 127.0.0.1:25 :
LISTEN 0 128 127.0.0.1:9000 :
LISTEN 0 128 :::22 :::
LISTEN 0 100 ::1:25 :::

LISTEN 0 80 :::3306 :::*

4.配置nginx
FastCGI的相关配置参数
LNMP:php需要启用fpm模型
配置如下:
[[email protected] ~]# vim /usr/local/nginx/conf/nginx.conf

  location / {
        root html;
        index index.html index.htm;
    }

//添加以下内容,php脚本请求全部转发到FastCGI处理,使用默认配置
location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

//配置完后重新加载nginx
[[email protected] ~]# nginx -s reload

//在nginx下的html目录下创建测试文件
[[email protected] ~]# cd /usr/local/nginx/html/
[[email protected] html]# cat > ranwoaini.php <<EOF

<?php
phpinfo();
?>
EOF

在浏览器上输入192.168.56.12/ranwoaini.php访问,出现以下界面则说明服务搭建成功

原文地址:http://blog.51cto.com/13729085/2164427

时间: 2024-10-12 09:39:32

LNMP服务搭建的相关文章

图文详解如何快捷搭建LNMP服务环境

上一篇与大家一起学习了下如何搭建LAMP环境的知识,今天小编再和大家分享下如何快捷地搭建LNMP环境,并搭建起一个网站.Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.目前很受站长们的青睐,尤其是要求不是很高的中小型网站. 一.下载LNMP一键安装包 下载地址:http://soft.vpser.net/lnmp/lnmp1.2-full.tar.gz 国内备用地址:https://api.sinas3.com/v1/SAE_lnmp/soft/ln

centos6 LNMP的搭建(linux+nginx+mysql+php)

LNMP的搭建(linux+nginx+mysql+php) 简介 LNMP代表的就是:Linux系统下Nginx+MySQL+PHP网站服务器架构. Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统.代表版本有:debian.centos.ubuntu.fedora.gentoo等. Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器. Mysql是一个小型关系型数据库管理系统. PHP是一种在服务器端执行的嵌入HTML文档

LNMP的搭建及URL重写测试

内容: 1.LNMP的搭建 2.搭建基于LNMP的discuz论坛(www.hill.com) 3.实现https 4.实现访问http时自动跳转至https以及防盗链设置.URL重写测试 一.LNMP的搭建 我们知道,在apache与php的结合方式有三种,而nginx与php的结合目前只有一种是行之有效的:php-fpm 1.yum直接安装快速搭建LNMP,官方下载nginx的预安装包(rpm包),当然也可以编译安装 #yum install -y prce-devel zlib-devel

LNMP环境搭建ZABBIX3.0

1.LNMP环境搭建,这里就不详细介绍了,但是有几点需要注意 1)mysql如果是二进制或者编译安装,php编译的时候需要一下编译参数 --with-mysqli=/application/mysql-5.5.32/bin/mysql_config //后面的路径是你的mysql_config的具体路径,如果不加此参数会导致安装zabbix的时候找不到mysql support 2)mysql建立zabbix数据库的时候要指定utf8建库,再导入zabbix的数据 3)php编译的时候要加下面的

阿里云(ECS)Centos服务器LNMP环境搭建

阿里云( ECS ) Centos7 服务器 LNMP 环境搭建 前言 第一次接触阿里云是大四的时候,当时在校外公司做兼职,关于智能家居项目的,话说当时俺就只有一个月左右的 php 后台开发经验(还是因为无意中选修了一门电子商务的课程,要做课程设计逼迫出来的),因为公司没人接触过后台开发,所以我这个菜鸟就硬着头皮上了.刚开始入门我把精力放在公司业务功能实现上,所用的服务器环境是别人已经配置好的,就是把代码在本地写好,通过 ftp 上传到服务器目录,是用 postman 插件测试一下接口就行了,开

LNMP环境搭建——Apache篇

1.Apache DSO(Dynamic Shared Object) (1) 查看已编译模块: [root@kallen ~]# httpd -M Loaded Modules: core_module (static) mpm_prefork_module (static) http_module (static) so_module (static) auth_basic_module (shared) auth_digest_module (shared) authn_file_modu

LNMP环境搭建 Ubuntu篇

LNMP    就是linux+nginx+mysql+php.  洒家之前一直用apache服务器,还是win7系统,使用的都是xampp,esayphp,wamp等集成环境,周末闲着无聊,抱着尽量提高b格的想法动手配置了一下环境.完成之后还有点小激动.把过程分享出来,希望能帮助一些和我差不多的小白.下面开始环境配置: 首先ctrl+alt+t打开终端 1.更新软件源:  sudo apt-get update2.安装nginx  sudo apt-get install nginx3.启动n

Linux服务器集群架构部署搭建(四)WEB服务器LNMP/LAMP搭建部署及站点产品安装(1)

命运是大海,当你能够畅游时,你就要纵情游向你的所爱,因为你不知道狂流什么会到来,卷走一切希望与梦想. 作者:燁未央_Estelle声明:测试学习,不足之处,欢迎指正. 第一章 集群WEB服务器LNMP生产应用 1.1 Nginx的应用场合:根据功能来进行应用 ①静态服务器(图片,视频服务)国内使用的只有两款,另一个是lighttpd.百度贴吧.豆瓣.html.js.css.flv等. ②动态服务:nginx+fastcgi的方式运行php.jsp.动态的并发很少(根据优化达到500-1500),

LNMP平台搭建---Linux系统安装篇

在互联网网站开发领域,有一个名词,大家一定不陌生,那就是LAMP,经典的Web服务器环境,由Linux+Apache+MySQL+PHP组成,,后来,一个名叫Nginx的Web服务器开源出来了,因其更高的并发性,系统资源利用率更高,在市场上的占有率也逐步提升,在Netcraft网站上看到的数据,在1995年到2015年间,每种服务器的使用趋势: 可以看到,Apache依然是最受欢迎的Web服务器,Nginx属于后起之秀,很快占有市场.Nginx的几大特点如下: 1. 对静态资源的高速并发缓存和访