码迷,mamicode.com
首页 > 其他好文 > 详细

安装lnmp

时间:2015-04-14 20:15:41      阅读:346      评论:0      收藏:0      [点我收藏+]

标签:lnmp



公司最近要配置lnmp的环境作为游戏的web服务器,应公司要求用尽了浑身解数,过程如下:



环境:

[root@scj ~]# cat /etc/issue          (系统)

CentOS release 6.4 (Final)

Kernel \r on an \m

[root@scj ~]# uname -r                (内核)

2.6.32-358.el6.i686



selinux和iptables:

关闭selinux:

vi /etc/sysconfig/selinux

#找到SELINUX=****改成SELINUX=disabled

关闭防火墙:

iptables -F

/etc/init.d/iptables stop

chkconfig iptables off




安装必要的库和依赖包:

yum -y install patch cmake make gcc gcc-c++ gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glib2 glib2-devel bzip2 bzip2-devel libevent libevent-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel vim-minimal nano fonts-chinese gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap




安装nginx:

cd /usr/local/src/

安装pcre库:

使nginx支持rewrite URL地址重写,先安装pcre库

wget http://sourceforge.net/projects/pcre/files/pcre/8.35/pcre-8.35.tar.gz

tar -zxf pcre-8.35.tar.gz

cd pcre-8.35

./configure                         (不用指定--prefix)

make

make install


安装nginx:

wget http://nginx.org/download/nginx-1.6.2.tar.gz

tar -zxf nginx-1.6.2.tar.gz 

cd nginx-1.6.2

./configure  --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module

make

make install


启动nginx:

/usr/local/nginx/sbin/nginx          (此命令为启动nginx)

注意:在启动的时候可能会报下面这个错误:

/usr/local/nginx/sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory

解决办法:

[root@www nginx-1.6.2]# find / -name libpcre.so.1

/usr/local/src/pcre-8.35/.libs/libpcre.so.1

/usr/local/lib/libpcre.so.1

找到库文件的位置,然后将其添加到/etc/ld.so.conf这个文件里:

vi /etc/ld.so.conf

添加一行:/usr/local/lib

执行:ldconfig 

再执行:/usr/local/nginx/sbin/nginx      (启动)

查看是否启动:

[root@www lib]# netstat -tlnp | grep nginx

tcp        0      0 0.0.0.0:80                 0.0.0.0:*                   LISTEN      13765/nginx 




安装mysql:

cd /usr/local/src/

wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.22.tar.gz

tar -zxf mysql-5.6.22.tar.gz

cd mysql-5.6.22

mkdir -p /opt/mysql/data               (创建数据目录)

cmake  -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/opt/mysql/data -DSYSCONFDIR=/usr/local/mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1  -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock  -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci  -DEXTRA_CHARSETS:STRING=utf8,gbk  -DWITH_DEBUG=0

make                                  (这个过程可能会很慢,请耐心等待)

make install

groupadd mysql                        (创建mysql用户组)

useradd -s /sbin/nologin -g mysql mysql

/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/opt/mysql/data --defaults-file=/usr/local/mysql/my.cnf --user=mysql          (初始化数据库)

chown -R mysql.mysql /opt/mysql        (对数据目录授权)

vi /usr/local/mysql/my.cnf             (修改配置文件)

添加:datadir=/opt/mysql/data

      basedir=/usr/local/mysql

cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld      (复制启动脚本)

chkconfig --add mysqld

chkconfig mysqld on

/etc/init.d/mysqld start                (启动mysql)

[root@www mysql]# netstat -tlnp | grep mysql

tcp        0      0 :::3306                     :::*                        LISTEN      28839/mysqld

vi /etc/profile                         (修改PATH路径)

添加:export PATH=$PATH:/usr/local/mysql/bin

source /etc/profile

mysqladmin -u root password "123456"    (给root创建密码)

注意:执行此命令可能会报下面的错误:

[root@www mysql]# mysqladmin -u root password "123456"

mysqladmin: connect to server at ‘localhost‘ failed

error: ‘Can‘t connect to local MySQL server through socket ‘/tmp/mysqld.sock‘ (2)‘

Check that mysqld is running and that the socket: ‘/tmp/mysqld.sock‘ exists!

解决方法:

/etc/init.d/mysqld stop

vi /usr/local/mysql/my.cnf

添加:[client]

      socket=/var/lib/mysql/mysql.sock     (socket文件的路径,任意路径即可)

/etc/init.d/mysqld start                   (OK)

mysql -u root -p123456                     (登陆myqsl)



安装php:

cd /usr/local/src/

安装php的依赖库

安装libmcrypt:

wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/libmcrypt/libmcrypt-2.5.7.tar.gz

tar -zxf libmcrypt-2.5.7.tar.gz

cd libmcrypt-2.5.7

./configure

make

make install


安装php:

wget http://mirrors.sohu.com/php/php-5.5.10.tar.gz

tar -zxf php-5.5.10.tar.gz

cd php-5.5.10

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-pdo-sqlite --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock --with-mcrypt --with-mhash --with-iconv-dir=/usr/local --with-gd --with-gettext --with-freetype-dir --with-jpeg-dir --with-png-dir --with-libxml-dir=/usr --with-curl --with-xmlrpc --with-zlib --with-pear --with-openssl --with-libdir --with-kerberos --enable-cgi --enable-fpm --enable-pdo --enable-opcache --enable-mbstring --enable-gd-native-ttf --enable-xml --enable-exif --enable-zip --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop --enable-json --enable-bcmath --enable-calendar --enable-ftp --enable-inline-optimization --enable-pcntl --enable-mbregex --disable-rpath

                     (使用mysqlnd驱动链接,不需要安装mysql也可安装php)

注意:这里可能会出现下面报错:

configure: error: Don‘t know how to define struct flock on this system, set --enable-opcache=no

解决方法:

ldconfig

cd /usr/local/src/libmcrypt-2.5.7/libltd1/

./configure --enable-ltdl-install

make

make install

执行后会出现如下所示:

技术分享

vi /etc/ld.so.conf

添加:/usr/local/lib/            (上面添加过了)

ldconfig                          (这一步一定要执行,重新加载库文件,否则编译php会报错)

ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la >/dev/null 2>&1

ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so >/dev/null 2>&1

ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4 >/dev/null 2>&1

ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8 >/dev/null 2>&1

                                  (上面这4行可以不用执行)

然后再:

cd /usr/local/src/php-5.5.10

执行./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-pdo-sqlite --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock --with-mcrypt --with-mhash --with-iconv-dir=/usr/local --with-gd --with-gettext --with-freetype-dir --with-jpeg-dir --with-png-dir --with-libxml-dir=/usr --with-curl --with-xmlrpc --with-zlib --with-pear --with-openssl --with-libdir --with-kerberos --enable-cgi --enable-fpm --enable-pdo --enable-opcache --enable-mbstring --enable-gd-native-ttf --enable-xml --enable-exif --enable-zip --enable-soap --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-shmop --enable-json --enable-bcmath --enable-calendar --enable-ftp --enable-inline-optimization --enable-pcntl --enable-mbregex --disable-rpath

make                              (这个过程可能会很慢,请耐心等待)

make install

cp -a php.ini-production /usr/local/php/etc/php.ini       (拷贝文件)

cp -a /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

/usr/local/php/sbin/php-fpm        (启动php-fpm)

[root@www etc]# netstat -tlnp | grep php          (查看是否启动)

tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      3222/php-fpm  




nginx与php整合:

整合:

cd /usr/local/nginx/conf/

vi nginx.conf

找到如下几行,去掉注释,并修改,注意红色部分

        location ~ \.php$ {

            root           html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            include        fastcgi_params;

        }

如图:

技术分享

/usr/local/nginx/sbin/nginx -t         (检查配置文件是否正确)

/usr/local/nginx/sbin/nginx -s reload  (reload重新加载配置文件,关闭并启动新的worker进程)


测试:

vi /usr/local/nginx/html/index.php

<?php

phpinfo();

?>

打开浏览器,访问:192.168.186.129/index.php

如图:

技术分享














本文出自 “” 博客,请务必保留此出处http://732233048.blog.51cto.com/9323668/1632143

安装lnmp

标签:lnmp

原文地址:http://732233048.blog.51cto.com/9323668/1632143

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!