努力, 努力, 再努力
全部博文(220)
分类: PHP
2015-06-21 23:54:08
LNMP环境源码搭建(实测及排障)
参考 http://blog.csdn.net/stuartjing/article/details/8124491
2
2
.2
2
2
2
3
4
4
4
.
.
.
5
5
5
5
............. 6
..............6
........................6
........................ 6
.........................6
.....................6
............8
.........................8
9
9
.........................
....
............................
1. linux系统环境: centos6.5 2.6.32-431.el6.x86_64
2. nginx版本: nginx-1.8.0
3. mysql版本: PHP 5.4.42 (cli)
4. php版本: 5.0.95-log
yum install make gcc gcc-c++ autoconf automake
yum -y install zlib-devel pcre-devel openssl-devel
wget
tar -zxvf nginx-1.8.0.tar.gz
cd nginx-1.8.0
./configure --prefix=/usr/local/nginx \ #指定nginx安装目录
--with-openssl=/usr/include/openssl \ #启用openssl
--with-pcre \ #启用正则表达式
--with-debug \ #启用调试模式
--with-http_stub_status_module #启用查看nginx状态模块
生成如下信息:
creating objs/Makefile
Configuration summary
+ using system PCRE library
+ using OpenSSL library: /usr/include/openssl
+ md5: using system crypto library
+ sha1: using system crypto library
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
make && make install
/usr/local/nginx/sbin/nginx
lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 3824 root 6u IPv4 59008 0t0 TCP *:http (LISTEN)
nginx 3825 nobody 6u IPv4 59008 0t0 TCP *:http (LISTEN)
yum -y install ncurses-devel
#ncurses包:提供字符终端处理库,包括面板和菜单。
wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.95.tar.gz
tar zxvf mysql-5.0.95.tar.gz
useradd -M -s /sbin/nologin mysql
cd mysql-5.0.95
./configure --prefix=/usr/local/mysql \
--without-debug \ # 取消调试模式提高性能
--with-extra-charsets=utf8,gbk \ # 仅仅指定需要的默认字符集提高性能
--enable-assembler \ # 使用汇编模式提高性能
--with-mysqld-ldflags=-all-static \ # 以静态方式编译提高性能
--with-client-ldflags=-all-static \ #以静态方式编译提高性能
--with-unix-socket-path=/tmp/mysql.sock \ # 使用unix socket提高性能
--with-ssl
配置成功,如下提示:
Thank you for choosing MySQL!
Remember to check the platform specific part of the reference manual
for hints about installing MySQL on your platform.
Also have a look at the files in the Docs directory.
make && make install
cp support-files/my-medium.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
ln -s /usr/local/mysql/bin/* /usr/local/bin/
ln -s /usr/local/mysql/lib/mysql/lib* /usr/lib/
mysql_install_db --user=mysql
chown -R root.mysql /usr/local/mysql/
chown -R mysql.mysql /usr/local/mysql/var/
/etc/init.d/mysqld start
mysqladmin -u root password 'xxxx'
[root@slave mysql]# mysql -uroot -pxxxx
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.0.95-log Source distribution
Copyright (c) 2000, 2011, 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> quit
yum -y install libxml2-devel curl-devel libpng-devel openldap-devel
wget \
2.5.8/libmcrypt-2.5.8.tar.bz2
tar -jxvf libmcrypt-2.5.8.tar.bz2
cd libmcrypt-2.5.8
./configure
make && make install
wget \
/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2
tar -jxvf mhash-0.9.9.9.tar.bz2
cd mhash-0.9.9.9
./configure
make && make install
# 这两个包安装完成后要把动态链接库做一个软连接到/usr/lib,
以为接下来的mcrypt依赖于这两个包
ln -s /usr/local/lib/libmcrypt* /usr/lib
ln -s /usr/local/lib/libmhash.* /usr/lib/
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
wget \
MCrypt/2.6.8/mcrypt-2.6.8.tar.gz/download
tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
./configure
make && make install
报错: ./configure时如下提示
checking for libmcrypt - version >= 2.5.0... no
*** Could not run libmcrypt test program, checking why...
*** The test program compiled, but did not run. This usually means
*** that the run-time linker is not finding LIBMCRYPT or finding the wrong
*** version of LIBMCRYPT. If it is not finding LIBMCRYPT, you'll need to set your
*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point
*** to the installed location Also, make sure you have run ldconfig if that
*** is required on your system
*** If you have an old version installed, it is best to remove it, although
*** you may also be able to get things to work by modifying LD_LIBRARY_PATH
configure: error: *** libmcrypt was not found
解决方法如下:运行 export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
wget
tar -zxvf php-5.4.42.tar.gz
cd php-5.4.42
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql/ --with-zlib --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --with-curl \ --with-curlwrappers --enable-fpm --with-mcrypt --with-gd --with-openssl --with-mhash --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap
configure参数说明:
--prefix=/usr/local/php 指定php安装目录
--with-mysql=/usr/local/mysql/ 指定mysql安装目录, 对mysql的支持
--with-zlib 打开zlib库的支持,用于http压缩传输
--disable-rpath 关闭额外的运行库文件
--enable-bcmath 打开图片大小调整,用到zabbix监控的时候用到了这个模块
--enable-shmop 和 --enable-sysvsem
这样就使得你的PHP系统可以处理相关的IPC函数了
--with-curl 打开curl浏览工具的支持
--with-curlwrappers 运用curl工具打开url流
--enable-fpm 打上PHP-fpm 补丁后才有这个参数,CGI方式安装的启动程序
--with-mcrypt mcrypt算法扩展
--with-gd 打开gd库的支持
--with-openssl openssl的支持,加密传输https时用到的
--enable-sockets 打开 sockets 支持
--with-mhash mhash算法扩展
--with-ldap 支持ldap
--with-ldap-sasl 支持Cyrus SASL认证的ldap
--with-xmlrpc 打开xml-rpc的c语言
--enable-zip 打开对zip的支持
--enable-soap 启用soap支持
注意: --enable-safe-mode, --enable-fastcgi,参数已经去除不再使用
configure --help没有 --enable-xml这个参数
来源php手册:
Fastcgi is the preferred SAPI to connect PHP and Lighttpd. Fastcgi is
automagically enabled in php-cgi in PHP 5.3, but for older versions configure PHP with --enable-fastcgi.
报错1: configure: error: Cannot find ldap libraries in /usr/lib
解决办法如下:
cp -frp /usr/lib64/libldap* /usr/lib/
(5)编译及编译安装
make && make install
警告1:
make: warning: Clock skew detected. Your build may be incomplete.
这个报错与系统时间有关,可能的原因: 系统时间与当前时间不符
cp php.ini-production /usr/local/php/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
ln -s /usr/local/php/bin/php /usr/bin/
vim /usr/local/php/etc/php-fpm.conf
listen = /var/run/php-fpm/php-fpm.sock
listen.mode = 0666 #给php-fpm.sock分配写权限
mkdir /var/run/php-fpm
/usr/local/php/sbin/php-fpm
fpm: FastCGI Process Manager:FastCGI进程管理器
vim /usr/local/nginx/conf/nginx.conf
修改nginx配置文件支持php:
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.php index.html index.htm; # 添加index.php的首页文件
}
# 添加下面内容
location ~ \.php$ {
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
include fastcgi_params;
include fastcgi.conf;
}
unix:/var/run/php-fpm/php-fpm.sock; 此处是使用unix socket
也可以使用环回IP: fastcgi_pass 127.0.0.1:9000;
killall nginx
/usr/local/nginx/sbin/nginx
启动nginx时报错
nginx: [emerg] "fastcgi_pass" directive is not allowed here in /usr/local/nginx/conf/nginx.conf:68
原因: /usr/local/nginx/conf/nginx.conf
#location ~ \.php$ { 本行的注示符号 # 没有去掉导致,去掉即可
在/usr/local/nginx/html下创建index.php
vim /usr/local/nginx/html/index.php