码迷,mamicode.com
首页 > 其他好文 > 详细

lnmp初体验

时间:2016-05-23 19:25:58      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:lnmp

系统版本:centos6.4最小化

网络环境:无网络,本地yum源

编译环境:yum -y groupinstall "Development tools" "Server Platform Development"

nginx:nginx-1.10.0.tar.gz


tar xf nginx-1.10.0.tar.gz

cd nginx-1.10.0

./configure --prefix=/usr/local/nginx \

--sbin-path=/usr/sbin/nginx \

--conf-path=/etc/nginx/nginx.conf \

--error-log-path=/var/log/nginx/error.log \

--http-log-path=/var/log/nginx/access.log \

--pid-path=/var/run/nginx/nginx.pid \

--lock-path=/var/lock/nginx/nginx.lock \

--user=nginx \

--group=nginx \

--with-http_ssl_module \

--with-http_flv_module \

--with-http_stub_status_module \

--with-http_gzip_static_module \

--http-client-body-temp-path=/var/tmp/nginx/client/ \

--http-proxy-temp-path=/var/tmp/nginx/proxy \

--http-fastcgi-temp-path=/var/tmp/nginx/fastcgi/ \

--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \

--http-scgi-temp-path=/var/tmp/nginx/scgi \

--with-pcre

报错如下:

./configure: error: the HTTP rewrite module requires the PCRE library.

You can either disable the module by using --without-http_rewrite_module

option, or install the PCRE library into the system, or build the PCRE library

statically from the source with nginx by using --with-pcre=<path> option.

查看系统中的pcre库

[root@huang nginx-1.10.0]# rpm -qa *pcre*

pcre-7.8-6.el6.x86_64

于是

[root@huang ~]# yum -y install pcre-devel-7.8-6.el6.x86_64.rpm

然后重新编译configure

成功解决报错问题

make && make install


mysql:mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz


[root@huang ~]# tar xf mysql-5.6.30-linux-glibc2.5-x86_64.tar.gz -C /usr/local/

[root@huang ~]# cd /usr/local/

[root@huang local]# ls

bin  etc  games  include  lib  lib64  libexec  mysql-5.6.30-linux-glibc2.5-x86_64  nginx  sbin  share  src

[root@huang local]# ln -sv mysql-5.6.30-linux-glibc2.5-x86_64/ /usr/local/mysql

"/usr/local/mysql" -> "mysql-5.6.30-linux-glibc2.5-x86_64/"


[root@huang local]# groupadd -r mysql

[root@huang local]# useradd -g mysql -r -s /sbin/nologin -M mysql

[root@huang local]# id mysql

uid=498(mysql) gid=498(mysql) 组=498(mysql)

[root@huang local]# mkdir /mydata/data -pv

mkdir: 已创建目录 "/mydata"

mkdir: 已创建目录 "/mydata/data"

[root@huang local]# chown -R mysql:mysql /mydata/data/

[root@huang local]# cd /usr/local/mysql

[root@huang mysql]# chown -R root:mysql ./*

[root@huang mysql]# rm -f /etc/my.cnf

[root@huang mysql]# scripts/mysql_install_db --user=mysql --data=/mydata/data/

简单修改下my.cnf,添加如下:

datadir = /mydata/data

socket = /tmp/mysql.sock

innodb_file_per_table = on

[root@huang mysql]# cp support-files/mysql.server /etc/init.d/mysqld

[root@huang mysql]# vi /etc/profile.d/mysql.sh

添加如下:

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

[root@huang mysql]# . /etc/profile.d/mysql.sh

[root@huang mysql]# chkconfig --add mysqld

[root@huang mysql]# chkconfig mysqld on

[root@huang mysql]# service mysqld start

Starting MySQL... SUCCESS! 

[root@huang mysql]# mysql

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 1

Server version: 5.6.30 MySQL Community Server (GPL)


Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its

affiliates. Other names may be trademarks of their respective

owners.


Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.


mysql> 


vi /etc/ld.so.conf.d/mysql.conf:导出一下mysql库文件

添加/usr/local/mysql/lib

ldconfig -v:生效

导出mysql的头文件include:

ln -sv /usr/local/mysql/include /usr/include/mysql


php:php-5.5.34.tar.gz

[root@huang php-5.5.34]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --enable-sysvshm --enable-sockets --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl --with-mhash --with-mcrypt

提示错误如下:

configure: error: xml2-config not found. Please check your libxml2 installation.

检查系统版本:

[root@huang php-5.5.34]# rpm -qa *libxml2*

libxml2-2.7.6-8.el6_3.4.x86_64

于是:

[root@huang Packages]# yum -y install libxml2-devel-2.7.6-8.el6_3.4.x86_64.rpm

继续

[root@huang php-5.5.34]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --enable-sysvshm --enable-sockets --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl --with-mhash --with-mcrypt

继续报错如下:

configure: error: Please reinstall the BZip2 distribution

检查系统版本

[root@huang php-5.5.34]# rpm -qa *bzip*

bzip2-libs-1.0.5-7.el6_0.x86_64

bzip2-1.0.5-7.el6_0.x86_64

于是:

[root@huang Packages]# yum -y install bzip2-devel-1.0.5-7.el6_0.x86_64.rpm

继续

[root@huang php-5.5.34]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --enable-sysvshm --enable-sockets --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl --with-mhash --with-mcrypt

继续报错如下:

configure: error: Please reinstall the libcurl distribution -

    easy.h should be in <curl-dir>/include/curl/

解决:

[root@huang Packages]# yum -y install libcurl-devel-7.19.7-35.el6.x86_64.rpm

继续

[root@huang php-5.5.34]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --enable-sysvshm --enable-sockets --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl --with-mhash --with-mcrypt

继续报错如下:

configure: error: mcrypt.h not found. Please reinstall libmcrypt.

解决:

tar xf libmcrypt-2.5.7.tar.gz

cd libmcrypt-2.5.7

./configure --prefix=/app/libs/

make && make install

vi /etc/ld.so.conf

添加:

/app/libs/lib

ldconfig -v


继续configure

[root@huang php-5.5.34]# ./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --enable-fpm --enable-sysvshm --enable-sockets --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-libxml-dir=/usr --enable-xml --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --with-curl --with-mhash --with-mcrypt

将--with-mcrypt改为--with-mcrypt=/app/libs

于是成功编译完成,接下来

make && make install


为php提供配置文件:

cp php.ini-production /etc/php.ini


为php-fpm提供脚本,并添加到服务列表,生成自启动项

cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm脚本在源代码编译目录下

chmod +x /etc/init.d/php-fpm

chkconfig --add php-fpm

chkconfig php-fpm on



为php-fpm提供配置文件

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf


编辑php-fpm.conf配置文件:(配置文件也有错误日志的定义)

配置fpm相关的选项为你所需要的值,并启用pid文件

pm.max_children = 50(最大子进程个数)

pm.start_servers = 5(刚开始启动的进程数)

pm.min_spare_servers = 2

pm.max_spare_servers = 8

pid = /usr/local/php/var/run/php-fpm.pid

service php-fpm start

整合nginx和php-fpm:启用如下

1、编辑/etc/nginx/nginx.conf,启用入戏选项

location ~ \.php$ {

root  html;

fastcgi_pass   127.0.0.1:9000;

fastcgi_index   index.php;

fastcgi_param   SCRIPT_FILENAME   /scripts$fastcgi_script_name;

include         fastcgi_params;

}

2、编辑/etc/nginx/fastcgi_params,将其内容更改为如下:

fastcgi_param GATEWAY_INTERFACE       CGI/1.1;cgi接口common gateway interface

fastcgi_param SERVER_SOFTWARE nginx;服务器端的软件程序

fastcgi_param QUERY_STRING $query_string;

fastcgi_param REQUEST_METHOD $request_method;

fastcgi_param CONTENT_TYPE $content_type;

fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;

fastcgi_param REQUEST_URI $request_uri;

fastcgi_param DOCUMENT_URI         $document_uri;

fastcgi_param DOCUMENT_ROOT $document_root;

fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param REMOTE_ADDR $remote_addr;

fastcgi_param REMOTE_PORT $remote_port;

fastcgi_param SERVER_ADDR $server_addr;

fastcgi_param SERVER_PORT $server_port;

fastcgi_param SERVER_NAME $server_name;

并在所支持的主页面格式中添加php格式的主页

location / {

root   html;

index index.php index.html index.htm;

}

平滑启动nginx:

编辑下面的php测试页面:

vi index.php

<?php

phpinfo();

?>

至此lnmp环境搭建完成

lnmp初体验

标签:lnmp

原文地址:http://huangsir007.blog.51cto.com/6159353/1782175

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!