# 更新系統 yum -y update # 安裝編譯工具與常用庫 yum -y install gcc gcc-c++ autoconf make \ libjpeg libjpeg-devel libpng libpng-devel freetype freetype-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 libxml2 libxml2-devel \ patch pcre-devel
說明: gcc/make/autoconf 為編譯必備;libjpeg/freetype/zlib 供 PHP 編譯;patch/libxml2 供 php-fpm 打補丁;pcre-devel 供 Nginx 編譯。
yum install gcc openssl-devel pcre-devel zlib-devel
groupadd nginx useradd nginx -g nginx mkdir /var/www chmod +w /var/www chown -R nginx:nginx /var/www
cd /work/soft wget https://sysoev.ru/nginx/nginx-0.8.33.tar.gz tar -zxvf nginx-0.8.33.tar.gz cd nginx-0.8.33 ./configure \ --prefix=/usr \ --sbin-path=/usr/sbin/nginx \ --conf-path=/etc/nginx/nginx.conf \ --error-log-path=/var/log/nginx/error.log \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --user=nginx \ --group=nginx \ --with-http_ssl_module \ --with-http_flv_module \ --with-http_gzip_static_module \ --http-log-path=/var/log/nginx/access.log \ --http-client-body-temp-path=/var/tmp/nginx/client/ \ --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ --with-http_stub_status_module make && make install
--with-http_stub_status_module 可統計當前連接數。新增模組只需重新 configure && make,再將 objs/nginx 覆蓋原執行檔(先備份)。
mkdir -p /var/tmp/nginx vi /work/webServer/nginxStart.sh #!/bin/sh /usr/sbin/nginx vi /work/webServer/nginxRestart.sh #!/bin/sh killall -9 nginx /usr/sbin/nginx chmod +x /work/webServer/nginxStart.sh chmod +x /work/webServer/nginxRestart.sh
/usr/sbin/nginx # 或 /work/webServer/nginxStart.sh
瀏覽器訪問見到 Welcome to nginx! 即成功。
cd /work/soft /usr/sbin/groupadd mysql /usr/sbin/useradd -g mysql mysql # 下載源碼(擇快鏡像) wget https://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.0-m2.tar.gz/from/https://opensource.become.com/MySQL/ tar zxvf mysql-5.5.0-m2.tar.gz cd mysql-5.5.0-m2 ./configure --prefix=/work/webServer/mysql/ \ --enable-assembler --with-extra-charsets=complex \ --enable-thread-safe-client --with-big-tables --with-readline \ --with-ssl --with-embedded-server --enable-local-infile \ --with-plugins=partition,innobase,myisammrg make && make install chmod +w /work/webServer/mysql chown -R mysql:mysql /work/webServer/mysql
mkdir -p /work/webServer/mysqlData/data/ mkdir -p /work/webServer/mysqlData/binlog/ mkdir -p /work/webServer/mysqlData/relaylog/ chown -R mysql:mysql /work/webServer/mysqlData/ /work/webServer/mysql/bin/mysql_install_db \ --basedir=/work/webServer/mysql \ --datadir=/work/webServer/mysqlData/data \ --user=mysql
[client] character-set-server = utf8 port = 3306 socket = /tmp/mysql.sock [mysqld] character-set-server = utf8 replicate-ignore-db = mysql replicate-ignore-db = test replicate-ignore-db = information_schema user = mysql port = 3306 socket = /tmp/mysql.sock basedir = /work/webServer/mysql datadir = /work/webServer/mysqlData/data log-error = /work/webServer/mysqlData/mysql_error.log pid-file = /work/webServer/mysqlData/mysql.pid open_files_limit = 10240 max_connections = 5000 table_cache = 614 max_allowed_packet = 32M sort_buffer_size = 1M join_buffer_size = 1M thread_cache_size = 300 query_cache_size = 512M query_cache_limit = 2M tmp_table_size = 246M max_heap_table_size = 246M innodb_buffer_pool_size = 512M innodb_log_file_size = 128M innodb_flush_log_at_trx_commit = 2 skip-name-resolve server-id = 1
vi /work/webServer/mysql.sh #!/bin/sh printf "Starting MySQL...\n" /bin/sh /work/webServer/mysql/bin/mysqld_safe --defaults-file=/work/webServer/my.cnf 2>&1 > /dev/null & mkdir -p /work/webServer/mysql/var/ chmod +x /work/webServer/mysql.sh /work/webServer/mysql.sh
/work/webServer/mysql/bin/mysql -u root -p -S /tmp/mysql.sock # 密碼直接回車 GRANT ALL PRIVILEGES ON *.* TO 'li'@'localhost' IDENTIFIED BY '111111' WITH GRANT OPTION;
# libiconv cd /work/soft wget https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz tar zxvf libiconv-1.13.1.tar.gz cd libiconv-1.13.1 ./configure --prefix=/usr && make && make install # mhash wget https://blog.s135.com/soft/Linux/nginx_PHP/mhash/mhash-0.9.9.9.tar.gz tar -zxvf mhash-0.9.9.9.tar.gz cd mhash-0.9.9.9 ./configure --prefix=/usr && make && make install # mcrypt wget https://blog.s135.com/soft/Linux/nginx_PHP/mcrypt/libmcrypt-2.5.8.tar.gz tar -zxvf libmcrypt-2.5.8.tar.gz cd libmcrypt-2.5.8 ./configure && make && make install /sbin/ldconfig cd libltdl ./configure --enable-ltdl-install && make && make install wget https://blog.s135.com/soft/Linux/nginx_PHP/mcrypt/mcrypt-2.6.8.tar.gz tar -zxvf mcrypt-2.6.8.tar.gz cd mcrypt-2.6.8 LD_LIBRARY_PATH=/usr/local/lib ./configure --prefix=/usr && make && make install
也可用 yum install libmcrypt-devel mhash-devel 替代。
cd /work/soft wget https://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz tar zxvf libevent-1.4.13-stable.tar.gz cd libevent-1.4.13-stable ./configure --prefix=/usr && make && make install
cd /work/soft wget https://cn.php.net/get/php-5.3.1.tar.gz/from/this/mirror tar -zxvf php-5.3.1.tar.gz wget https://launchpad.net/php-fpm/master/0.6/+download/php-fpm-0.6~5.3.1.tar.gz tar -zxvf php-fpm-0.6~5.3.1.tar.gz php-fpm-0.6-5.3.1/generate-fpm-patch cd php-5.3.1 patch -p1 < ../fpm.patch ./buildconf --force mkdir fpm-build cd fpm-build
../configure --prefix=/usr \ --with-config-file-path=/etc/php5 \ --with-mysql=/work/webServer/mysql \ --with-mysqli=/work/webServer/mysql/bin/mysql_config \ --with-iconv-dir=/usr \ --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib \ --with-libxml-dir=/usr --enable-xml --enable-discard-path --enable-safe-mode \ --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization \ --with-curl --with-curlwrappers --enable-mbregex \ --enable-fastcgi --with-fpm --with-libevent=/usr/lib \ --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd \ --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl \ --enable-sockets --with-ldap --with-ldap-sasl --with-xmlrpc \ --enable-zip --enable-soap --without-pear make clean make ZEND_EXTRA_LIBS='-liconv' make install
見到 Installing PHP SAPI module: fpm 且 /usr/bin/php-fpm 存在即成功。
mkdir /etc/php5 cp php.ini-production /etc/php5/php.ini # 安裝 PEAR curl https://pear.php.net/go-pear | /usr/bin/php # 啟動 PHP-FPM /etc/init.d/php-fpm start
# /etc/rc.local 追加 /usr/sbin/nginx /work/webServer/mysql.sh /etc/init.d/php-fpm start # 重啟 Nginx killall -9 nginx /usr/sbin/nginx
/etc/nginx//etc/php5/php.ini/etc/php-fpm.conf/etc/my.cnfNo input file specified:檢查 fastcgi_param SCRIPT_FILENAME 與 SCRIPT_NAME 設定。
# nginx.conf 範例
worker_processes 1;
events { worker_connections 1024; }
http {
include mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /work/webServer/NginxAccess.log main;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name *.vcn2008.com;
charset UTF-8;
location / {
root /work/vcn2008.com;
index index.html index.htm index.php;
}
location ~ \.php$ {
root /work/vcn2008.com;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /work/vcn2008.com$fastcgi_script_name;
include fastcgi_params;
}
}
}