Centos下搭建LNMP环境

1.安装nginx
关于nginx的安装请参考http://blog.csdn.net/qq_30256711/article/details/78588648
2.安装二进制包mysql
useradd mysql -M -s /sbin/nologin
tar zxvf mysql-5.5.32-linux2.6-x86_64.tar.gz
mv mysql-5.5.32-linux2.6-x86_64 /usr/local/
ln -s /usr/local/MySQL-5.5.32 /usr/local/mysql
chown -R mysql.mysql mysql-5.5.32/
scripts/mysql_install_db --basedir=/usr/local/mysql-5.5.32/ \
--datadir=/usr/local/mysql-5.5.32/data --user=mysql
cp support-files/mysql.server /etc/init.d/mysqld
chmod u+x /etc/init.d/mysqld
chkconfig mysqld on
chkconfig --list mysqld
cp /usr/local/mysql/support-files/my-small.cnf /etc/my.cnf
service mysqld start
3.源码安装php
yum install zlib libxml2 libjpeg freetype libpng gd \
curl zlib-devel libxml2-devel libjpeg-devel freetype-devel \
libpng-devel gd-devel curl-devel libxslt libxslt-devel -y
tar zxvf libiconv-1.14.tar.gz
tar zxvf libmcrypt-2.5.8.tar.gz
tar zxvf mhash-0.9.9.9.tar.gz
tar zxvf mcrypt-2.6.8.tar.gz
#install libiconv
cd libiconv-1.14
./configure --prefix=/usr/local/libiconv-1.14
make && make install
cd ../libmcrypt-2.5.8
./configure
make && make install
sleep 2
/sbin/ldconfig
cd libltdl/
./configure --enable-ltdl-install
make
make install
#install mhash
cd ../../mhash-0.9.9.9
./configure
make
make install
#install mcrypt
cd ../mcrypt-2.6.8
/sbin/ldconfig
./configure LD_LIBRARY_PATH=/usr/local/lib
make
make install
#install php
tar zxf php-5.3.27.tar.gz
cd php-5.3.27
./configure --prefix=/usr/local/php-5.3.27 \
--with-mysql=/usr/local/mysql \
--with-iconv-dir=/usr/local/libiconv \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--disable-rpath \
--enable-safe-mode \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-inline-optimization \
--with-curl \
--with-curlwrappers \
--enable-mbregex \
--enable-fpm \
--enable-mbstring \
--with-mcrypt \
--with-gd \
--enable-gd-native-ttf \
--with-openssl \
--with-mhash \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-zip \
--enable-soap \
--enable-short-tags \
--enable-zend-multibyte \
--enable-static \
--with-xsl \
--with-fpm-user=nginx \
--with-fpm-group=nginx \
--with-libevent-dir \
--enable-ftp \
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/
make
make install
cp php.ini-production /usr/local/php-5.3.27/lib/php/php.ini
配置/usr/local/php-5.3.27/etc/php-fpm.conf配置文件
/usr/local/php-5.3.27/sbin/php-fpm 启动php-fpm
netstat -tlunp|grep php-fpm
4.配置服务开机自启动
cat >> /etc/rc.local <<EOF
/etc/init.d/mysqld start
/usr/local/php-5.3.27/sbin/php-fpm
/usr/local/nginx/sbin/nginx
EOF
5.nginx整合php
在nginx.conf中添加以下字段
location ~ .*\.(php|php5)?$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include        fastcgi.conf;
        }
index 添加index.php
6.php测试连接mysql
<?php
    $link_id=mysql_connect('localhost','root','haha123') or mysql_error();
    if($link_id){
        echo "mysql successful by oldboy!\n";
    }else{
 echo "mysql_error()";
}
?>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值