Redhat6.2下yum安裝 nginx php mysql 及相關擴充
參考:http://blog.s135.com/nginx_php_v6/
參考:http://kerry.blog.51cto.com/172631/857461
參考:http://www.cnblogs.com/sink_cup/archive/2012/09/14/web_server.html
利用Centos的源來安裝,使用163.com的Centos6的REPO檔案,yum makecache
sudo -s
LANG=C
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel
krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers gd gd-devel
yum中的相關庫名稱
libcurl-devel libcurl
zlib-devel zlib
libxslt-devel libxslt
libzip-devel libzip
libxml2-devel libxml2
libjpeg-devel libjpeg
libpng-devel libpng
freetype-devel freetype
bzip2-devel bzip2
libzip-devel libzip
libxpm-devel libxpm
Redhat6.2 沒有 mcrypt的php擴充
wget http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz?ts=1348197028
wget http://downloads.sourceforge.net/project/mcrypt/MCrypt/2.6.8/mcrypt-2.6.8.tar.gz?ts=1348196976
下載mhash
wget http://downloads.sourceforge.net/project/mhash/mhash/0.9.9.9/mhash-0.9.9.9.tar.bz2?ts=1348198184&use_mirror=cdnetworks-kr-1
libmcrypt
./configure
make && make install
/sbin/ldconfig
使用libmcrypt需要用到ltdl,要不編譯php時會報錯
安裝路徑/usr/local/lib/
http://yangsiwei.com/usr-bin-ld-cannot-find-lltdl-%E9%94%99%E8%AF%AF%E7%9A%84%E8%A7%A3%E5%86%B3%E5%8A%9E%E6%B3%95
cd libltdl/
./configure --enable-ltdl-install
make
make install
cd ../../
編譯ImageMagick
wget ftp://mirror.aarnet.edu.au/pub/imagemagick/ImageMagick-6.7.9-6.tar.xz
tar xvf ImageMagick-6.7.9-6.tar.xz -C /tmp
cd /tmp/ImageMagick-6.7.9-6
./configure
make && make install
為了讓動態串連庫為系統共用
需要運行/sbin/ldconfig命令,也可以在/etc/ld.so.conf.d/加一個custome.conf的檔案,添加上自己的庫地址
cd mhash-0.9.9.9
./configure
make && make install
解決mcrypt編譯時間的尋找檔案路徑問題
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
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
mcrypt
./configure --with-libmcrypt-prefix=/usr/local
make && make install
*******************************************
安裝mysql二進位包
*******************************************
wget http://www.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.27-linux2.6-x86_64.tar.gz/from/http://cdn.mysql.com/
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
我們並不完全瞭解mysql,與其自己模式還不如先用一個編譯好的,然後放到一個我們指定的目錄下
修改了/app目錄 為/data目錄
tar xzvf mysql-5.5.27-linux2.6-x86_64.tar.gz
mv mysql-5.5.27-linux2.6-x86_64 /data/opt/mysql
建立資料目錄,可以把data、binlog、relaylog 資料分開在獨立的目錄中
mkdir /data/databases
mkdir /data/databases/binlog
cd /data/opt/mysql
./scripts/mysql_install_db --basedir=/data/opt/mysql --datadir=/data/databases --user=mysql
修改設定檔/etc/my.cnf
[client]
character-set-server = utf8
port = 3306
socket = /tmp/mysql.sock
[mysqld]
character-set-server = utf8
user = mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /data/opt/mysql
datadir = /data/databases
log-error = /data/databases/mysql_error.log
pid-file = /data/databases/mysql.pid
open_files_limit = 1024
back_log = 600
max_connections = 200
max_connect_errors = 200
table_cache = 614
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 300
#thread_concurrency = 8
#query_cache_size = 512M
#query_cache_limit = 2M
#query_cache_min_res_unit = 2k
#default-storage-engine = MyISAM
#thread_stack = 192K
#transaction_isolation = READ-COMMITTED
#tmp_table_size = 246M
#max_heap_table_size = 246M
#long_query_time = 3
#log-slave-updates
#log-bin = /data0/mysql/3306/binlog/binlog
#binlog_cache_size = 4M
#binlog_format = MIXED
#max_binlog_cache_size = 8M
#max_binlog_size = 1G
#relay-log-index = /data0/mysql/3306/relaylog/relaylog
#relay-log-info-file = /data0/mysql/3306/relaylog/relaylog
#relay-log = /data0/mysql/3306/relaylog/relaylog
#expire_logs_days = 30
#key_buffer_size = 256M
#read_buffer_size = 1M
#read_rnd_buffer_size = 16M
#bulk_insert_buffer_size = 64M
#myisam_sort_buffer_size = 128M
#myisam_max_sort_file_size = 10G
#myisam_repair_threads = 1
#myisam_recover
#
#interactive_timeout = 120
#wait_timeout = 120
#
#skip-name-resolve
##master-connect-retry = 10
#slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
#
##master-host = 192.168.1.2
##master-user = username
##master-password = password
##master-port = 3306
#
#server-id = 1
#
#innodb_additional_mem_pool_size = 16M
#innodb_buffer_pool_size = 512M
#innodb_data_file_path = ibdata1:256M:autoextend
#innodb_file_io_threads = 4
#innodb_thread_concurrency = 8
#innodb_flush_log_at_trx_commit = 2
#innodb_log_buffer_size = 16M
#innodb_log_file_size = 128M
#innodb_log_files_in_group = 3
#innodb_max_dirty_pages_pct = 90
#innodb_lock_wait_timeout = 120
#innodb_file_per_table = 0
#
##log-slow-queries = /data0/mysql/3306/slow.log
##long_query_time = 10
#
#[mysqldump]
#quick
#max_allowed_packet = 32M
通過bin/mysql 連結mysql報錯
bin/mysql: unknown variable 'character-set-server=utf8'
看到網上的文章有人通過用character_set_server=utf8來取代 default-character-set=utf8,解決了類似報錯問題
我把結果反過來,也解決了我的問題
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION IDENTIFIED BY 'mainone%123';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION IDENTIFIED BY 'mainone%123';
*******************************************
編譯安裝php5.3.17
*******************************************
wget http://php.net/get/php-5.3.17.tar.bz2/from/cn2.php.net/mirror
關於inline編譯最佳化
http://stackoverflow.com/questions/6791564/what-does-enable-inline-optimization-do-when-compiling-php
精確的數學計算
--enable-bcmath
php.ini設定檔地址
with-config-file-path
Disable passing additional runtime library
--disable-rpath
記憶體共用操作函數
--enable-shmop
enable System V semaphore support compile PHP with the option
--enable-sysvsem
使用CURL做為url stream的函數
--with-curlwrappers
使用寬字元集的正則匹配
--enable-mbregex
fork子進程的功能
--enable-pcntl
http://blog.csdn.net/lgg201/article/details/5996444
Generating phar.phar
chmod: 無法訪問"ext/phar/phar.phar": 沒有那個檔案或目錄
make: [ext/phar/phar.phar] 錯誤 1 (忽略)
解決動態連結libmysqlclient.so.18找不到問題,兩個辦法,最好是做軟串連
1、export LD_LIBRARY_PATH="/data/opt/mysql/lib:$LD_LIBRARY_PATH"
2、ln -s /data/opt/mysql/lib/libmysqlclient_r.so.18 /usr/lib
./configure --prefix=/data/opt/php --with-config-file-path=/data/opt/php --enable-mysqlnd --with-mysql=/data/opt/mysql --with-mysqli=/data/opt/mysql/bin/mysql_config --with-libxml-dir=/usr/include/libxml2 --with-gd=/usr/include --with-jpeg-dir --with-png-dir
--with-bz2 --with-freetype-dir --with-iconv-dir --with-zlib --with-mcrypt=/usr/local/lib/libmcrypt --with-mhash --with-curl=/usr/include/curl --enable-gd-native-ttf --enable-sockets --enable-mbstring --with-libxml-dir=/usr/include --enable-xml --disable-rpath
--enable-fpm --with-curlwrappers --enable-pcntl --enable-soap --with-xmlrpc --enable-zip
配置php-fpm
http://ideas.spkcn.com/technology/php-technology/133.html
cp php5.3.17/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
cd /data/opt/php/etc
cp php-fpm.conf.default php-fpm.conf
修改配置php-fpm.conf
pid = run/php-fpm.pid
user=www-data
group=www-data
pm.start_servers = 20
pm.max_children = 64
pm.start_servers = 12
pm.min_spare_servers = 3
pm.max_spare_servers = 20
rlimit_files = 65535
catch_workers_output = yes
配置結束
shell設定檔案開啟數量
ulimit -SHn 65535
chkconfig --add php-fpm
chkconfig php-fpm on
安裝完後修改php.ini
date.timezone = "Asia/Shanghai"
expose_php = Off // 禁止在HTTP header中顯示php資訊
short_open_tag = On // 開啟短標記
下載php最佳化擴充
wget http://pecl.php.net/get/APC-3.1.9.tgz
cd APC-3.1.9
/data/opt/php/bin/phpize
./configure --with-php-config=/data/opt/php/bin/php-config
make && make install
php擴充路徑 /data/opt/php/lib/php/extensions/no-debug-non-zts-20090626/
編譯imagemagick擴充
wget http://pecl.php.net/get/imagick-2.3.0.tgz
tar xzvf imagick-2.3.0.tgz
cd imagick-2.3.0
編譯安裝和上面APC一樣
設定 php.ini 的擴充目錄
extension_dir = "/data/opt/php/lib/php/extensions/no-debug-non-zts-20090626"
配置apc ,imgick
extension=apc.so
extension=imagick.so
安裝mongodb擴充
wget http://pecl.php.net/get/mongo-1.2.12.tgz
tar xvf mongo-1.2.12.tgz
cd %
phpize
./configure
make && make install
extension=mongo.so
編譯安裝 memcached
http://www.yongblog.com/archives/386.html
wget http://memcached.googlecode.com/files/memcached-1.4.15.tar.gz
tar xvf memcached-1.4.15.tar.gz
cd %
./configure --prefix=/usr/local/memcached
make && make install
暫時的啟動方案
/usr/local/memcached/bin/memcached -u root
編譯安裝libevent
由於rhel6.2帶的libevent還是1.4的,在編譯libmemcached1.0series時有問題,所以安裝一個新版的庫
wget https://github.com/downloads/libevent/libevent/libevent-2.0.20-stable.tar.gz
./configure --prefix=/usr/local/libevent
編譯安裝libmemcached
wget https://launchpad.net/libmemcached/1.0/1.0.10/+download/libmemcached-1.0.10.tar.gz
tar xvf libmemcached-1.0.10.tar.gz
./configure --prefix=/usr/local/libmemcached -with-memcached
make && make install
在編譯libmemcached1.0.10版時報編譯example下檔案錯誤
example/memcached_light.cc:596: undefined reference to `event_init'等
沒有找到合適的解決辦法,故換成1.0.4的版本
wget https://launchpad.net/libmemcached/1.0/1.0.10/+download/libmemcached-1.0.4.tar.gz
其他過程一樣,編譯通過
編譯安裝php_memcached
memcached-2.1.0 的版本要求libmemcached-1.0.11的版本
wget http://pecl.php.net/get/memcached-2.0.1.tgz
tar xvf memcached-2.0.1.tgz
./configure --with-libmemcached-dir=/usr/local/libmemcached
make && make install
編譯沒有問題
添加extension=memcached.so到php.ini檔案
編譯安裝php_memcache,這個與memcached的擴充是不一樣的
這個擴充在windows下可以用,但是功能沒有上面的好,配置一樣就不寫了
*******************************************
安裝配置nginx
*******************************************
yum 安裝, 這次沒有編譯
--with-http_stub_status_module 是為了啟用 nginx 的 NginxStatus 功能,用來監控 Nginx 的目前狀態。 安 裝成功後 /opt/nginx 目錄下有四個子目錄分別是:conf、html、logs、sbin 。
--http-client-body-temp-path=PATH set path to store http client request body temporary files 指定http用戶端請求快取檔案存放目錄的路徑
--http-fastcgi-temp-path set path to store http fastcgi temporary files 指定http FastCGI快取檔案存放目錄的路徑
--http-proxy-temp-path set path to store http proxy temporary files 指定http反向 Proxy快取檔案存放目錄
--http-uwsgi-temp-path set path to store http uwsgi temporary files 指定http uwsgi快取檔案存放目錄的路徑
--http-scgi-temp-path set path to store http scgi temporary files 指定http sigi快取檔案存放目錄的路徑
--with-http_ssl_module enable ngx_http_ssl_module
--with-http_realip_module enable ngx_http_realip_module 當作為Proxy 伺服器使用時,設定後端擷取的真實IP值通過 X-Real-IP or X-Forwarded-For header值
--with-http_addition_module enable ngx_http_addition_module 在響應之前或之後添加文本的一個過濾器
--with-http_sub_module enable ngx_http_sub_module This module can search and replace text in the nginx response.
--with-http_dav_module enable ngx_http_dav_module This module adds the HTTP and WebDAV methods PUT, DELETE, MKCOL, COPY and MOV
--with-http_flv_module enable ngx_http_flv_module This module provides the ability to seek within FLV (Flash) files using byte-based offsets.
--with-http_mp4_module enable ngx_http_mp4_module This module enables mp4 streaming with seeking ability
--with-http_gzip_static_module enable ngx_http_gzip_static_module Before serving a file from disk to a gzip-enabled client, this module will look for a precompressed file in the same location that ends in ".gz
--with-http_random_index_module enable ngx_http_random_index_module Pick a random file from a directory and use it as the index file.
--with-http_secure_link_module enable ngx_http_secure_link_module This module checks request URLs for a required security token
--with-http_stub_status_module enable ngx_http_stub_status_module This module provides the ability to get some status from nginx.
--with-mail enable POP3/IMAP4/SMTP proxy module Mail Proxy Configuration
--with-file-aio enable file AIO support Kernel Asynchronous I/O (AIO) Support
修改nginx.conf
user www-data www-data
*******************************************
mongodb 安裝
*******************************************
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-redhat-centos-or-fedora-linux/
修改dbpath=/data/mongo