系统:Cenos 6.5 X64
软件:
tengine-2.0.3.tar.gz
pcre-8.33.tar.bz2
mysql-5.6.12.tar.gz
php-5.5.14.tar.bz2
一、安装nginx
1.1 安装nginx所需的pcre-devel库,使nginx支持HTTP Rewrite模块
[[email protected]]# ./configure --prefix=/home/webserver/pcre && make && make install
1.2 安装nginx
[[email protected] ~]# yum-y install openssl openssl-devel
[[email protected] ~]# tarzxf tengine-2.0.3.tar.gz
[[email protected] ~]# cdtengine-2.0.3
[[email protected]]# ./configure \
--prefix=/home/webserver/nginx\
--with-http_stub_status_module \
--with-pcre=/root/pcre8.33/ \
--with-http_realip_module
#注意pcre不是安装到的位置,而是pcre源码包的位置
[[email protected]]# make && make install
二、安装Mysql:
2.1 安装mysql
[[email protected]]# useradd -s /sbin/nologin mysql
[[email protected]]# yum -y install cmake ncurses ncurses-devel
[[email protected]]# cmake . -DCMAKE_INSTALL_PREFIX=/home/webserver/mysql-DMYSQL_UNIX_ADDR=/home/webserver/mysql/mysql.sock -DDEFAULT_CHARSET=utf8-DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1-DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1-DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1-DMYSQL_DATADIR=/home/webserver/database -DMYSQL_USER=mysql
[[email protected]]# make && make install
[[email protected]]# chown -R mysql:mysql /home/webserver/mysql/
2.2 初始化数据库:
[[email protected]]# chmod +xscripts/mysql_install_db
[[email protected]]# ./scripts/mysql_install_db --user=mysql --basedir=/home/webserver/mysql--datadir=/home/webserver/database
2.3 创建配置文件:
[[email protected] mysql-5.6.12]#cp support-files/my-default.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
2.4 创建启动脚本:
[[email protected]]# cp support-files/mysql.server /etc/init.d/mysqld
[[email protected]]# chmod +x /etc/init.d/mysqld
[[email protected]]# chkconfig --add mysqld
[[email protected] mysql-5.6.12]# ckconfig mysqld on
[[email protected]]# chkconfig mysqld --list
mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
2.5 加mysql bin目录到$PATH中
[[email protected]]# echo ‘export PATH=$PATH:/home/webserver/mysql/bin‘ >>/etc/profile
[[email protected]]# source /etc/profile
2.6 启动mysql:
[[email protected]]# /etc/init.d/mysqld start
Starting MySQL...SUCCESS!
2.7 设置mysql root用户密码:
[[email protected]]# mysqladmin -u rootpassword ‘zrer90‘
三、安装PHP
3.1 安装php依赖库
3.1.1:安装jpeg9
[[email protected] ~]# wgethttp://www.ijg.org/files/jpegsrc.v9.tar.gz
[[email protected] ~]# tar-zxvf jpegsrc.v9.tar.gz
[[email protected] ~]# cdjpeg-9/
[[email protected] jpeg-9]#./configure --prefix=/home/webserver/libs --enable-shared --enable-static &&make && make install
3.1.2:安装png
[[email protected] ~]# wgethttp://prdownloads.sourceforge.net/libpng/libpng-1.6.2.tar.gz
[[email protected] ~]# tarzxf libpng-1.6.2.tar.gz
[[email protected] ~]# cdlibpng-1.6.2
[[email protected]]# ./configure --prefix=/home/webserver/libs/ && make&& make install
3.1.3:安装freetype
[[email protected] ~]# wgethttp://download.savannah.gnu.org/releases/freetype/freetype-2.4.12.tar.gz
[[email protected] ~]# tarzxf freetype-2.4.12.tar.gz
[[email protected] ~]# cdfreetype-2.4.12
[[email protected]]# ./configure --prefix=/home/webserver/libs && make&& make install
3.1.4:安装libmcrypt:
[[email protected] ~]#wget http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
[[email protected] ~]# tarzxf libmcrypt-2.5.8.tar.gz
[[email protected]]# ./configure --prefix=/home/webserver/libs && make && make install
[[email protected]]# cd libltdl/
[[email protected]]# ./configure --prefix=/home/webserver/libs/ --enable-ltdl-install && make && make install
3.1.5:安装mhash:
[[email protected] ~]# wgethttp://downloads.sourceforge.net/mhash/mhash-0.9.9.9.tar.gz
[[email protected] ~]# tarzxf mhash-0.9.9.9.tar.gz
[[email protected] ~]# cdmhash-0.9.9.9
[[email protected]]# ./configure --prefix=/home/webserver/libs/ && make&& make install
[[email protected] ~]#export LDFLAGS="-L/home/webserver/libs/lib -L/usr/lib"
[[email protected] ~]#export CFLAGS="-I/home/webserver/libs/include -I/usr/include"
###这命令的作用是把安装的lib库连接到/usr/lib下,因为php安装时默认只搜索/urs/lib,不设置的话可能会造成后面mcrypt编译的时候找不到mhash库.
3.1.6:安装mcrypt:
[[email protected] ~]# exportLD_LIBRARY_PATH=/home/webserver/libs/lib:/home/webserver/libs
##这命令的作用是设置gcc编译环境变量
[[email protected] ~]# wgethttp://downloads.sourceforge.net/mcrypt/mcrypt-2.6.8.tar.gz
[[email protected]]# ./configure --prefix=/home/webserver/libs/ --with-libmcrypt-prefix=/home/webserver/libs && make && make install
3.2 安装PHP:
[[email protected] ~]# yum-y install curl curl-devel libxml2libxml2-devel zlib-devel zlib
[[email protected]]#./configure --prefix=/home/webserver/php --with-config-file-path=/home/webserver/php/etc--with-mysql=/home/webserver/mysql/--with-mysqli=/home/webserver/mysql/bin/mysql_config --with-iconv-dir--with-freetype-dir=/home/webserver/libs --with-jpeg-dir=/home/webserver/libs/--with-png-dir=/home/webserver/libs --with-zlib --with-libxml-dir=/usr/bin/xml2-config --enable-xml --enable-bcmath--enable-sysvsem --enable-inline-optimization --with-curl --with-mhash --with-openssl--enable-shmop --enable-mbstring --with-gd --enable-gd-native-ttf --enable-pcntl--enable-sockets --with-xmlrpc --enable-zip--with-pdo-mysql=/home/webserver/mysql/ --with-mcrypt=/home/webserver/libs --enable-fpm --disable-rpath --enable-mbregex --enable-soap --enable-opcache
[[email protected]]# make && maek install
3.3 创建PHP配置文件,删除系统自带的配置文件,将配置文件做软连接到/etc/ php.ini
[[email protected]]# cp php.ini-production /home/webserver/php/etc/php.ini
[[email protected]]# rm -rf /etc/php.ini
[[email protected]]# ln -s /home/webserver/php/etc/php.ini /etc/php.ini
3.4 修改PHP配置文件开启短标记,开启opcache
[[email protected]]# vim /home/webserver/php/etc/php.ini
short_open_tag = on (默认为OFF)
display_errors = OFF
[opcache]
zend_extension="opcache.so"
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.optimization_level=1
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4096
opcache.revalidate_freq=60
opcache.fast_shutdown=1
[[email protected]~]# cd /home/webserver/php/etc/
[[email protected]]# cp php-fpm.conf.default php-fpm.conf
[[email protected]]# vim php-fpm.conf
[global]
; Pid file
; Note: the defaultprefix is /home/webserver/php/var
; Default Value: none
;pid = run/php-fpm.pid
pid = run/php-fpm.pid #开启php-fpm pid文件
四、配置nginx和php
4.1 创建nginx运行用户www
[[email protected] ~]# useradd -s /sbin/nologin www
4.2 修改nginx配置文件 ,
user www;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location ~ .*\.(php|php5)?$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf; #将*.php 或者.php5的请求转交给本地php-fpm处理
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
4.3 使用nginx –t测试nginx配置文件
[[email protected] ~]# /home/webserver/nginx/sbin/nginx -t
the configuration file/home/webserver/nginx/conf/nginx.conf syntax is ok
configuration file/home/webserver/nginx/conf/nginx.conf test is successful
4.4 启动nginx,启动php
[[email protected] ~]#/home/webserver/nginx/sbin/nginx
[[email protected] ~]#/home/webserver/php/sbin/php-fpm
4.5 下载探针文件到nginx安装目录下的 html目录下。
4.6 浏览器访问探针文件,查看lnmp安装情况,测试与mysql链接情况
4.7 所遇到的报错:
安装mcrypt时报错:
checking whether mhash >= 0.8.15...no
configure: error: "You need at leastlibmhash 0.8.15 to compile this program. http://mhash.sf.net/"
原因:
mhash编译默认安装路径是 /usr/local/,相关库在 /usr/local/lib 下。而 php 只搜索 /usr/lib/ 这个位置。所以会出现找不到 mhash 相关库的情况。
解决方法:
通过软链接的方法把 /usr/local/lib 目录下的 mhash 相关的库文件链接到 /usr/lib/ 目录下。
重装PHP报错:
configure: error: GD build test failed.Please check the config.log for details.
解决办法:
vim /etc/ld.so.conf 在这个文件里面加入configure所使用的lib路径
ldconfig
报错:
checking for known struct flockdefinition... configure: error: Don‘t know how to define struct flock on thissystem, set --enable-opcache=no
解决办法:
ln -s/home/webserver/mysql/lib/libmysqlclient.so /usr/lib
ln -s/home/webserver/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
vim /etc/ld.so.conf 在这个文件内加入软连接到的 /usr/lib路径
ldconfig
lnmp环境源码编译安装记录