centos6.5 x86_64下编译安装lnmp(上)

平台:centos6.5 x86_64最小化安装,添加163yum源

本文所用到的安装文件

准备基本库

yum -y install gcc gcc-c++ automake autoconf libtool libcrypt libjpeg libjpeg-devel libpng libpng-devel gd gd-devel libxml2 libxml2-devel zlib zlib-devel ncurses ncurses-devel curl curl-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel bison bison-devel flex


1,安装Cmake

cd /usr/local/src/

tar zxvf cmake-3.2.3.tar.gz 

cd cmake-3.2.3

./bootstrap 

gmake

gmake install


2,编译安装mysql


groupadd mysql

useradd -s /sbin/nologin -M -g mysql mysql

mkdir -p /usr/local/mysql

mkdir -p /usr/local/mysql/data

chown -R mysql:mysql /usr/local/mysql


mv /etc/my.cnf /etc/my.cnf.bk(在启动MySQL服务时,会按照一定次序搜索my.cnf,先在/etc目录下找,找不到则会搜索"$basedir/my.cnf",MySQL若使用这个配置文件启动,可能造成无法正常启动等问题。)



tar zxvf mysql-5.5.42.tar.gz

cd mysql-5.5.42


cmake \

-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \

-DMYSQL_DATADIR=/usr/local/mysql/data \

-DSYSCONFDIR=/etc \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock \

-DMYSQL_TCP_PORT=3306 \

-DENABLED_LOCAL_INFILE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DEXTRA_CHARSETS=all \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_READLINE=1 -DWITH_EMBEDDED_SERVER=1 \

-DWITH_SSL=bundled -DWITH_ZLIB=system


make && make install


3,初始化数据库


cp support-files/mysql.server /etc/init.d/mysql

chmod 775 /etc/init.d/mysql

chkconfig --add mysql

chkconfig mysql on


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

echo 'export PATH=/usr/local/mysql/bin:$PATH' >> /etc/profile


/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql


service mysql start(或者/usr/local/mysql/bin/mysql start)


4,配置数据库账号密码、权限


/usr/local/mysql/bin/mysqladmin -u root password "password"


/usr/local/mysql/bin/mysql -u root -p 输入密码password


GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password';

FLUSH PRIVILEGES;


iptables -I INPUT -p tcp --dport 3306 -j ACCEPT


5,编译安装php


cd /usr/local/src

1)字符编码转换函数库

tar zxvf libiconv-1.14.tar.gz 

cd libiconv-1.14

./configure --prefix=/usr/local --enable-static

make && make install

cd ..


2)PHP加密库

tar zxvf libmcrypt-2.5.8.tar.gz 

cd libmcrypt-2.5.8

./configure 

make && make install

ldconfig

cd libltdl/

./configure --enable-ltdl-install

make && make install

cd ../../


ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la

ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so

ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4

ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8


加密扩展库Mcrypt和Mhash

tar zxvf mhash-0.9.9.9.tar.gz 

cd mhash-0.9.9.9

./configure 

make && make install


ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a

ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la

ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so

ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2

ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1

cd ..


tar zxvf mcrypt-2.6.8.tar.gz

cd mcrypt-2.6.8

ldconfig

./configure   (./configure结果报错说can't move libtoolt。。,没找到好的解决办法,直接在configure里面把RM='$RM'改为RM='$RM  -f',最后没报错了-_-!,如有其他办法请指教,ths)

make && make install

cd ..


3)安装字体引擎

tar -zxf freetype-2.4.12.tar

cd freetype-2.4.12

./configure --prefix=/usr/local/freetype

make && make install


cat > /etc/ld.so.conf.d/freetype.conf<<EOF

/usr/local/freetype/lib

EOF

    

ln -sf /usr/local/freetype/include/freetype2 /usr/local/include

ln -sf /usr/local/freetype/include/ft2build.h /usr/local/include


4)安装php

tar zxvf php-5.4.41.tar.gz

cd php-5.4.41


ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64


./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo


make ZEND_EXTRA_LIBS='-liconv' 

make install


5)配置php.ini

cp php.ini-production /usr/local/php/etc/php.ini


sed -i 's/post_max_size = 8M/post_max_size = 50M/g' /usr/local/php/etc/php.ini

sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 50M/g' /usr/local/php/etc/php.ini

sed -i 's/;date.timezone =/date.timezone = PRC/g' /usr/local/php/etc/php.ini

sed -i 's/short_open_tag = Off/short_open_tag = On/g' /usr/local/php/etc/php.ini

sed -i 's/; cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini

sed -i 's/; cgi.fix_pathinfo=0/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini

sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /usr/local/php/etc/php.ini

sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /usr/local/php/etc/php.ini

sed -i 's/disable_functions =.*/disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server/g' /usr/local/php/etc/php.ini


6)添加插件(图片引擎、缓冲、加速引擎,所以内存大点,CPU牛点比较好)


tar zxvf ImageMagick-6.9.1-2.tar.gz

cd ImageMagick-6.9.1-2/

./configure --prefix=/usr/local/imagemagick

make && make install

cd ../


tar zxvf imagick-3.1.2.tgz

cd imagick-3.1.2/

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config --with-imagick=/usr/local/imagemagick

make && make install

cd ../                      


tar zxvf memcache-3.0.8.tgz

cd memcache-3.0.8/

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config

make && make install

cd ../


tar -zxvf libmemcached-1.0.18.tar.gz   

cd libmemcached-1.0.18

./configure --prefix=/usr/local/libmemcached --with-memcached

make && make install


tar -zxvf memcached-2.2.0.tgz

cd memcached-2.2.0

/usr/local/php/bin/phpize

./configure --with-php-config=/usr/local/php/bin/php-config --with-libmemcached-dir=/usr/local/libmemcached/ --enable-memcached

make && make install


tar zxf ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64.tar.gz

mkdir -p /usr/local/zend/

cp ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/php-5.4.x/ZendGuardLoader.so /usr/local/zend/


cat >>/usr/local/php/etc/php.ini<<EOF

;eaccelerator

;ionCube

[Zend ZendGuard Loader]

zend_extension=/usr/local/zend/ZendGuardLoader.so

zend_loader.enable=1

zend_loader.disable_licensing=0

zend_loader.obfuscation_level_support=3

zend_loader.license_path=

;xcache

;xcache end

EOF


7)修改 php.ini 文件,让 php 模块生效


vi /usr/local/php/etc/php.ini

查找

;extension_dir = "./"

修改为(去掉前面的;对齐)

extension_dir="/usr/local/php/lib/php/extensions/no-debug-non-zts-20100525/"

并在此行后增加以下几行,然后保存:

extension = "memcache.so"

extension = "imagick.so"

extension = "memcached.so"



8)准备 php-cgi 和 nginx 进程执行者用户

groupadd nginx

useradd -s /sbin/nologin -g nginx nginx


9)创建 php-fpm 配置文件- php-fpm.conf

默认配置/usr/local/php/etc/php-fpm.conf.default


cat >/usr/local/php/etc/php-fpm.conf<<EOF

[global]

pid = /usr/local/php/var/run/php-fpm.pid

error_log = /usr/local/php/var/log/php-fpm.log

log_level = notice


[www]

listen = 127.0.0.1:9000

listen.backlog = -1

listen.allowed_clients = 127.0.0.1

listen.owner = nginx

listen.group = nginx

listen.mode = 0666

user = nginx

group = nginx

pm = dynamic

pm.max_children = 10

pm.start_servers = 2

pm.min_spare_servers = 1

pm.max_spare_servers = 6

request_terminate_timeout = 100

request_slowlog_timeout = 0

slowlog = var/log/slow.log

EOF


10)启动 php-cgi(fastcgi)


cd /usr/local/src/php-5.4.41

cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm

chmod +x /etc/rc.d/init.d/php-fpm

chkconfig --add php-fpm

chkconfig php-fpm on

service php-fpm start

你可能感兴趣的:(centos6.5 x86_64下编译安装lnmp(上))