依赖包安装:
yum -y install make apr* autoconf automake curl-devel gcc gcc-c++ zlib-devel openssl openssl-devel pcre-devel gd kernel keyutils patch perl kernel-headers compat* mpfr cpp glibc libgomp libstdc++-devel ppl cloog-ppl keyutils-libs-devel libcom_err-devel libsepol-devel libselinux-devel krb5-devel zlib-devel libXpm* freetype libjpeg* libpng* php-common php-gd ncurses* libtool* libxml2 libxml2-devel patch freetype-devel cmake zlib ncurses* openssl* cmake gcc* autoconf bison libevent*
#上传文件至/opt/soft/
安装nginx:
安装pcre,支持正则:
tar -zxvf pcre-8.12.tar.gz
cd pcre-8.12
./configure && make && make install
添加用户和用户组:
groupadd www
useradd -s /sbin/nologin -M -g www www
安装nginx:
tar -zxvf nginx-1.2.0.tar.gz
cd nginx-1.2.0
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module --with-ipv6 --with-pcre=/opt/soft/pcre-8.12
#注意:
--with-pcre=/opt/soft/pcre-8.12 为pcre的解压路径,不是安装路径
make && make install
替换 /usr/local/nginx/conf/下的nginx.conf 和fcgi.conf
配置nginx
mkdir /opt/web
安装php:
安装php扩展模块软件:
tar zxvf libiconv-1.14.tar.gz
cd libiconv-1.14/
./configure && make && make install
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
tar zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure && make && make install
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
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
tar zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
ldconfig
./configure && make && make install
安装php5.6:
mkdir -p /usr/local/php/etc
tar -zxvf php-5.6.11.tar.gz
cd php-5.6.11
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-magic-quotes --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --with-curlwrappers --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 --without-pear --with-gettext --disable-fileinfo --with-libdir=lib64 --enable-opcache --with-apxs2=/usr/local/apache2/bin/apxs (安装http是需要)
echo "/usr/local/lib">>/etc/ld.so.conf
ldconfig
make ZEND_EXTRA_LIBS='-liconv'
make install
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
修改pid和user,group
开启opcache缓存加速:
php优化:
php.ini 加入
zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/opcache.so
opcache.fast_shutdown=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli= On
opcache.enable= On
注意:
如果出现:configure: error: Don't know how to define struct flock on this system, set --enable-opcache=no
加上--with-libdir=lib64
echo "/usr/local/lib">>/etc/ld.so.conf
make ZEND_EXTRA_LIBS='-liconv'
错误1:
error while loading shared libraries: libiconv.so.2: cannot open shared object file: No such file or directory
但是在/usr/local/lib下却能找到libiconv.so.2,解决方法是将/usr/local/lib路径添加到/etc/ld.so.conf文件中
make install
其他参照lnmp源码网页文档安装!
php优化:
php.ini 加入
zend_extension = /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/opcache.so
opcache.fast_shutdown=1
opcache.enable_cli=1
opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli= On
opcache.enable= On
make之前需要修改:
ext/iconv/.libs/iconv.o: In function `php_iconv_stream_filter_ctor':
/root/php-5.2.12/ext/iconv/iconv.c:2491: undefined reference to `libiconv_open'
ext/xmlrpc/libxmlrpc/.libs/encodings.o: In function `convert':
/root/php-5.2.12/ext/xmlrpc/libxmlrpc/encodings.c:73: undefined reference to `libiconv_open'
/root/php-5.2.12/ext/xmlrpc/libxmlrpc/encodings.c:81: undefined reference to `libiconv'
/root/php-5.2.12/ext/xmlrpc/libxmlrpc/encodings.c:101: undefined reference to `libiconv_close'
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] ?.. 1
处理方法:
./configure ............
vi Makefile
找到下面这行:
EXTRA_LIBS = -lcrypt ...在最后添加-liconv保存后make通过;make install通过。
2.如果在phpini中添加了扩展但是没有被加载,并且出现了phpinfo中出现了 Loaded Configuration File (none) 这种情况
处理办法:
可以手工指定php.ini:
/usr/local/php/sbin/php-fpm -y /usr/local/php/etc/php-fpm.conf -c /usr/local/php/etc/php.ini
3.出现找不到libmcrypt直接添加
--with-libdir=lib64
4.出现找不到iconv
--with-iconv=/usr/local/lib 改成--with-iconv
启动:
/usr/local/php/sbin/php-fpm
php-fpm 关闭:
kill -INT `cat /usr/local/php/var/run/php-fpm.pid`
php-fpm 重启:
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
查看php-fpm进程数:
ps aux | grep -c php-fpm
安装源码包:
在centos 6.5 64位版本上安装LNMP,config php的时候出现下面错误而退出
configure: error: Cannot find ldap libraries in /usr/lib
解决办法:
cp -frp /usr/lib64/libldap* /usr/lib/
安装mysql:
groupadd mysql
useradd -s /sbin/nologin -M -g mysql mysql
tar -zxvf mysql-5.6.25.tar.gz
cd mysql-5.6.25
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=1 -DWITH_SSL=system -DWITH_ZLIB=system -DWITH_EMBEDDED_SERVER=1 -DENABLED_LOCAL_INFILE=1
cp support-files/my-default.cnf /etc/my.cnf
vi /etc/my.cnf
加入优化的mysql配置:
###查看mysql innodb 5.5版本 show engine innodb status\G;
###注意:innodb 一定要在初始化之前加入配置文件
###5.6版本需要去掉#log_slow_queries=/usr/local/mysql/slow-log.log
###需要chmod 777 /tmp
[client]
#password = your_password
port = 3306
socket = /tmp/mysql.sock
# Here follows entries for some specific programs
# The MySQL server
[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-external-locking
max_allowed_packet = 32M
table_open_cache = 2048
net_buffer_length = 1M
character-set-server = utf8
skip-name-resolve
ft_min_word_len = 4
#### performance ####
open_files_limit = 10240
max_connections = 800
max_connect_errors = 6000
thread_stack = 192K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 256M
max_heap_table_size = 256M
slow_query_log
long_query_time = 1
#log_slow_queries=/usr/local/mysql/slow-log.log
net_buffer_length = 1M
#### log ####
log-error=/usr/local/mysql/mysqld.err
back_log = 500
max_binlog_cache_size = 8M
max_binlog_size = 512M
binlog_format=mixed
expire_logs_days = 7
#### buffer && cache ####
read_buffer_size = 10M
read_rnd_buffer_size = 32M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 300
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 4M
binlog_cache_size = 4M
key_buffer_size = 32M
bulk_insert_buffer_size = 64M
#### myisam ####
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
log-bin=mysql-bin
server-id = 1
innodb_data_home_dir = /usr/local/mysql/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /usr/local/mysql/data
innodb_buffer_pool_size = 1G
innodb_additional_mem_pool_size = 16M
innodb_log_file_size = 150M
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit =2
innodb_lock_wait_timeout = 60
innodb_flush_method = O_DIRECT
innodb_open_files = 800
innodb_file_per_table=1
innodb_file_io_threads=4
[mysqldump]
quick
max_allowed_packet = 32M
[mysql]
no-auto-rehash
# Remove the next comment character if you are not familiar with SQL
#safe-updates
[myisamchk]
key_buffer_size = 32M
sort_buffer_size = 32M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8196
cd /usr/local/mysql/
chown -R mysql .
chgrp -R mysql .
初始化mysql:
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --defaults-file=/etc/my.cnf
启动mysql:
/usr/local/mysql/bin/mysqld_safe --defaults-file=/etc/my.cnf --user=mysql&
登录:
/usr/local/mysql/bin/mysql -u root -p
/usr/local/mysql/bin/mysqladmin -u root -p shutdown
/usr/local/mysql/bin/mysqladmin --socket=/tmp/mysql1.sock -u root password xxx 修改密码
授权远程连接:
grant all privileges on *.* to root@"%" identified by 'xxx' with grant option;
flush privileges ;
memcache安装:
useradd memcache
客户端:
tar zxvf memcache-3.0.6.tgz
cd memcache-3.0.6/
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
sed -i 's#extension_dir = "./"#extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/"\nextension = "memcache.so"\n#' /usr/local/php/etc/php.ini
服务端:
tar zxvf memcached-1.4.15.tar.gz
cd memcached-1.4.15/
./configure --prefix=/usr/local/memcached
make &&make install
启动:
/usr/local/memcached/bin/memcached -umemcache&
注意:添加完成在phpinfo找不到memcache 因为配置文件指向的是/usr/local/php/lib 所以需要:
cp -p /usr/local/php/etc/php.ini /usr/local/php/lib
重启php ok
如果出现nginx出现错误:
emerg]: could not build the proxy_headers_hash, you should increase either proxy_headers_hash_max_size: 512 or proxy_headers_hash_bucket_size: 64
解决方法
把以下二行代码添加到配置即可:
proxy_headers_hash_bucket_size 1024;
proxy_headers_hash_max_size 512;
ps:由于51cto限制了上传附件,所以附件搭建对应版本下载,亲测可用,已经放到正式环境使用
本文转自 674591788 51CTO博客,原文链接:http://blog.51cto.com/mrdeng/1735313