本文共 5506 字,大约阅读时间需要 18 分钟。
CentOS 5 (64位)下lnmp平台搭建
1、安装nginx
Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。
# tar zxvf pcre-7.9.tar.gz # cd pcre-7.9 # ./configure # make && make install
# tar zxvf zlib-1.2.3.tar.gz
# cd zlib-1.2.3 # CFLAGS="-O3 -fPIC" ./configure (O为大写字母) (默认在/usr/local下) # make && make install
# tar zxf nginx-0.7.51.tar.gz
# cd nginx-0.7.51 # ./configure # make && make install 启动nginx
# /usr/local/nginx/sbin/nginx
关闭nginx
# /usr/local/nginx/sbin/nginx -s stop
2、安装mysql
(64位)
# tar zxf mysql-5.1.60-linux-x86_64-glibc23.tar.gz# mv mysql-5.1.60-linux-x86_64-glibc23 /usr/local/mysql
# cd /usr/local/mysql
# useradd -M -s /sbin/nologin mysql
# chown mysql:mysql /usr/local/mysql
# ./script/mysql_install_db --user=mysql
# cp support-files/mysql.server /etc/init.d/mysqld
# cp support-files/my-medium.cnf /etc/my.cnf
# chkconfig --add mysqld
# chkconfig --level 35 mysqld on
# /usr/local/mysql/bin/mysqld_safe --user=mysql &
# mv /tmp /tmp1
# vi /etc/my.cnf
socket = /tmp1/mysql.sock
:wq
# ln -s /tmp1/mysql.sock /tmp/mysql.sock
# ln -s /usr/local/mysql/bin/mysql /sbin/mysql
# ln -s /usr/local/mysql/bin/mysqladmin /sbin/mysqladmin
# mysqladmin -u root password "123456"
# mysql -u root -p
3、安装php 下载地址:
# tar zxvf libxml2-2.6.30.tar.gz
# cd libxml2-2.6.30 # ./configure (默认在/usr/local下) # make && make install # tar zxvf libmcrypt-2.5.8.tar.gz # cd libmcrypt-2.5.8 # ./configure --prefix=/usr/local/libmcrypt # make && make install # cd /usr/local/src/libmcrypt-2.5.8/libltdl # ./configure --enable-ltdl-install # make && make install # tar zxvf libpng-1.2.31.tar.gz # cd libpng-1.2.31 # ./configure --prefix=/usr/local/libpng # make && make install 安装GD2库前所需的jpeg6库文件,需要自己手动地创建安装需要的目录,它们在安装时不能自动创建。# mkdir /usr/local/jpeg7 //建立jpeg6软件安装目录
# mkdir /usr/local/jpeg7/bin //建立存放命令的目录 # mkdir /usr/local/jpeg7/lib //创建jpeg6库文件所在目录 # mkdir /usr/local/jpeg7/include //建立存放头文件目录 # mkdir -p /usr/local/jpeg7/man/man1 //建立存放手册的目录 # tar zxvf jpegsrc.v7.tar.gz # cd jpeg-v7 # ./configure --prefix=/usr/local/jpeg7 --enable-shared --enable-static 注: --enable-shared //建立共享库使用的GNU的libtool --enable-static //建立静态库使用的GNU的libtool # make && make install# tar zxvf freetype-2.3.5.tar.gz
# cd freetype-2.3.5 # ./configure --prefix=/usr/local/freetype # make clean # make && make install
# tar zxvf autoconf-2.61.tar.gz
# cd autoconf-2.61 # ./configure # make && make install # tar zxvf libiconv-1.13.tar.gz # cd libiconv-1.13/ # ./configure --prefix=/usr/local/libiconv # make && make install # tar xzf gettext-0.17.tar.gz # cd gettext-0.17 # ./configure # make && make install # tar zxvf gd-2.0.35.tar.gz # cd gd-2.0.35# vi gd_png.c
# include "/usr/local/libpng/include/png.c"
# ./configure --prefix=/usr/local/gd2 --with-zlib=/usr/local --with-jpeg=/usr/local/jpeg7 - -with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --enable-m4_pattern_allow
# make && make install
# make clean # make && make install # tar zxvf php-5.2.8.tar.gz # gunzip -d php-5.2.8-fpm-0.5.10.diff.tar.gz # cd php-5.2.8 # patch -p1 < /root/php-5.2.8-fpm-0.5.10.diff # ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with- mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml- dir=/usr/local --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg7 --with- freetype-dir=/usr/local/freetype --with-gd=/usr/local/gd2 --with-zlib-dir=/usr/local --with -mcrypt=/usr/local/libmcrypt --enable-soap --enable-mbstring=all --enable-sockets --disable-cli --enable-fpm --enalbe-fastcgi --enable-force-cgi-redirect # make && make install # cp php.ini-dist /usr/local/php/etc/php.ini # cd /usr/local/php/etc # cp php.ini php.ini.bak # grep -v ";" php.ini.bak > php.ini # vi /usr/local/php/etc/php.iniextension_dir="/usr/lib64/php/modules" (原为extension_dir="./" )
:wq
# cd /usr/src/php-5.2.8/ext/mcrypt # /usr/local/php/bin/phpize # ./configure --with-php-config=/usr/local/php/bin/php-config --with-mcrypt=/usr/local/libmcrypt# make && make install
# cp /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/mcrypt.so /usr/lib64/php/modules # vi /usr/local/php/etc/php.ini[mcrypt]
extension=mcrypt.so :wq 启动php-fpm
# vi /usr/local/php/etc/php-fpm.conf
Unix user of processes
<!-- <value name="user">nobody</value> --> Unix group of processes <!-- <value name="group">nobody</value> --> 改成 Unix user of processes <value name="user">www</value> Unix group of processes <value name="group">www</value> 即去掉<!-- -->
# cp /usr/src/php-5.2.8/sapi/cgi/fpm/php-fpm /etc/init.d/php-fpm
# chmod +x /etc/init.d/php-fpm # /etc/init.d/php-fpm start或
# /usr/local/php/sbin/php-fpm start
整合nginx和php
# vi /usr/local/nginx/conf/nginx.conf
server
{ listen 80; server_name ; index index.php index.htm index.html; root /usr/local/nginx/ming;
location ~ .*\.(php|php5)?$
{ #fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; (可无) fastcgi_index index.php; include fastcgi_params; }:wq
# vi /usr/local/nginx/conf/fastcgi_params; (在任意处添加如下行)
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
:wq
重启nginx
# /usr/local/nginx/sbin/nginx -s stop
# /usr/local/nginx/sbin/nginx
# vi /usr/local/nginx/ming/test.php
<?php
phpinfo(); ?> 访问: 验证php与mysql的连接:
# vi /usr/local/nginx/ming/php_mysql.php
<?php
$db=mysql_connect("localhost","root","123456") or die ("fail"); echo "connect ok!" ?> 访问:本文转自linux博客51CTO博客,原文链接http://blog.51cto.com/yangzhiming/834184如需转载请自行联系原作者
yangzhimingg