LNMP环境配置
Linux,NGINX,PHP,MYSQL
PHP 依赖库安装
安装GD库 -让php支持gif,png,jpeg格式
GD库需要以下模块的支持
jpeg,libpng,freetype,libXpm-devel
wget http://www.ijg.org/files/jpegsrc.v9.tar.gz
tar -zxvf jpegsrc.v9.tar.gz
cd jpeg-9
./configure --prefix=/usr/local/jpeg9/ --enable-shared --enable-static
make & make install
libpng
wget http://jaist.dl.sourceforge.net/project/libpng/libpng16/1.6.13/libpng-1.6.13.tar.gz
tar -zxvf libpng-1.6.13.tar.gz
cd libpng-1.6.13
./configure --prefix=/usr/local/libpng
make & make install
freetype
wget http://jaist.dl.sourceforge.net/project/freetype/freetype2/2.5.3/freetype-2.5.3.tar.gz
tar -zxvf freetype-2.5.3.tar.gz
cd freetype-2.5.3 ./configure --prefix=/usr/local/freetype make & make install
libXpm-devel
apt-get install libxpm-dev
#如果编译报错,建立软连接
ln -s /usr/lib/x86_64-linux-gnu/libXpm.so /usr/lib/
ln -s /usr/lib/x86_64-linux-gnu/libXpm.so.4.11.0 /usr/lib/
ln -s /usr/lib/x86_64-linux-gnu/libXpm.so.4 /usr/lib/
现在需要的模块都已经编译好了
正式开始安装GD库
https://bitbucket.org/libgd/gd-libgd/downloads
wget https://bbuseruploads.s3.amazonaws.com/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz
tar -zxvf libgd-2.1.0.tar.gz
cd libgd-2.1.0
./configure --prefix=/usr/local/gd2 --with-jpeg=/usr/local/jpeg9/ --with-png=/usr/local/libpng/ --with-zlib=/usr/local/zlib-1.2.8/ --with-freetype=/usr/local/freetype/
make & make install
安装curl库
wget http://curl.haxx.se/download/curl-7.37.1.tar.gz
tar -zxvf curl-7.37.1.tar.gz
cd curl-7.37.1
./configure --prefix=/usr/local/curl
make & make install
PHP 安装
安装php前我们还得解决libxml2 和 libxslt
http://www.xmlsoft.org/downloads.html
wget ftp://xmlsoft.org/libxml2/libxml2-2.9.1.tar.gz
tar -zxvf libxml2-2.9.1.tar.gz
cd libxml2-2.9.1
需要指定python
./configure --prefix=/usr/local/libxml2 --with-python=/usr/lib/python2.7
make & make install
http://xmlsoft.org/XSLT/downloads.html
wget ftp://xmlsoft.org/libxslt/libxslt-1.1.28.tar.gz
tar -zxvf libxslt-1.1.28.tar.gz cd libxslt-1.1.28
./configure --prefix=/usr/local/libxslt --with-libxml-prefix=/usr/local/libxml2
make & make install
安装 Libiconv
http://directory.fsf.org/wiki/Libiconv
wget http://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz
tar -zxvf libiconv-1.14.tar.gz cd libiconv-1.14
./configure --prefix=/usr/local/libiconv
make
#出现错误
make[2]: *** [progname.o] Error 1
make[2]: Leaving directory `/opt/libiconv-1.14/srclib'
make[1]: *** [all] Error 2
make[1]: Leaving directory `/opt/libiconv-1.14/srclib'
make: *** [all] Error 2
#执行
cd srclib
sed -i -e '/gets is a security/d' ./stdio.in.h
make
make install
安装 BZip2
http://www.bzip.org/downloads.html
wget http://www.bzip.org/1.0.6/bzip2-1.0.6.tar.gz
tar -zxvf bzip2-1.0.6.tar.gz -C /usr/src cd /usr/src/bzip2-1.0.6/ make make install
好了,经过漫长的编译,终于要装php了
http://php.net/downloads.php
wget http://cn2.php.net/distributions/php-5.6.0.tar.gz
tar -zxvf php-5.6.0.tar.gz
cd php-5.6.0/
./configure --prefix=/usr/local/php-5.6.0 --with-config-file-path=/usr/local/php-5.6.0/etc --with-curl=/usr/local/curl/ --with-freetype-dir=/usr/local/freetype -with-png-dir=/usr/local/libpng/ --with-libxml-dir=/usr/local/libxml2/ --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-zlib-dir=/usr/local/zlib-1.2.8/ --with-xsl=/usr/local/libxslt/ --with-jpeg-dir=/usr/local/jpeg9/ --with-iconv-dir=/usr/local/libiconv/ --with-bz2=/usr/local/bzip2/ --with-openssl-dir=/usr/local/ssl --with-gd=/usr/local/gd2/ --with-xpm-dir=/usr/lib/x86_64-linux-gnu --enable-ftp --enable-sockets --enable-soap --enable-bcmath --enable-xslt --enable-mbstring --enable-calendar --with-gettext --enable-dom --enable-xml --enable-fpm --with-png
make & make install
配置PHP
cp /usr/local/php-5.6.0/php.ini-production /usr/local/php-5.6.0/etc/php.ini cp /usr/local/php-5.6.0/etc/php-fpm.conf.default /usr/local/php-5.6.0/etc/php-fpm.conf #添加 nobody 用户 启动PHP groupadd nobody
启动
/usr/local/php-5.6.0/sbin/php-fpm
执行以上命令,如果没报错一般情况下表示启动正常,如果不放心,也可以通过端口判断是PHP否启动
# netstat -lnt | grep 9000 tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
配置Nginx
mkdir /usr/local/php-portal/logs/ # 用于存放nginx日志.请看2.3的配置文件 mkdir -p /usr/local/php-portal/site # 站点根目录 vim /usr/local/php-portal/site/info.php
<?php
phpinfo();
?>
# 退出保存
编辑nginx.conf
vim /usr/local/nginx/conf/nginx.conf # 增加 PHP Server server { listen 8081; server_name localhost; access_log /usr/local/php-portal/logs/access.log; index index.php index.html index.html; root /usr/local/php-portal/site; location / { try_files $uri $uri/ /index.php?$args; } location ~ .*.(php)?$ { expires -1s; try_files $uri =404; fastcgi_split_path_info ^(.+.php)(/.+)$; include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; } }
启动Nginx
/usr/local/nginx/sbin/nginx
访问测试页
http://192.168.124.132:8081/info.php