nginx+php

1. 安装系统组件
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 libmcrypt libmcrypt-devel pcre-devel


2. 安装数据库
安装cmake
\\10.10.70.36\dev\database\MySQL\Linux64\cmake-2.8.3.tar.gz
./bootstrap
Make
Make install
安装mysql
\\10.10.70.36\dev\database\MySQL\Linux64\mysql-5.5.15.tar.gz
cmake -DCMAKE_INSTALL_PREFIX=/usr/server/mysql -DMYSQL_UNIX_ADDR=/var/run/mysqld/mysqld.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/var/lib/mysql -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DWIDTH_CLIENT_LDFLAGS=-all-static -DWIDTH_MYSQLD_LDFLAGS=-all-static -DENABLE_THREAD_SAFE_CLIENT=1 -DWIDTH_BIG_TABLES=1
make
make install

3. 安装libiconv
\\10.10.70.36\dev\middleware\nginx\libiconv-1.13.1.tar.gz
./configure
make
make install
ln -s /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2

4. 安装完libiconv后对环境进行设置
a) 在/etc/ld.so.conf中加入xxx.so所在的目錄
b) 一般而言,有很多so档案在/usr/local/lib这个目录下,所以在vim /etc/ld.so.conf中加入/usr/local/lib这一行,可以解決此问题。
c) 將 /etc/ld.so.conf存档后,还要执行/sbin/ldconfig -v来更新一下才会生效
d)
注:如果后面PHP make ZEND_EXTRA_LIBS='-liconv' 时还有错误,就对libiconv.so.2原文件进行chmod 700
5. 安装libmcrypt
\\10.10.70.36\dev\middleware\nginx\libmcrypt-2.5.7.tar.gz
./configure
make
make install


6. 安装nginx  (配置文件的修改例子在\\10.10.70.36\dev\middleware\nginx\配置文件 中有)
./configure --user=daemon --group=daemon --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module
Make
Make install


i. 修改nginx/conf目录下的nginx.conf文件
user  daemon daemon;
#设置CPU核数
worker_processes 2;
error_log  /var/log/nginx/nginx_error.log  crit;
pid        /var/run/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events {
    use epoll;
    worker_connections 65535;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    #charset  gb2312;
    client_body_temp_path /tmp/nginx_client_body_temp;
    fastcgi_temp_path /tmp/nginx_fastcgi_temp;
    proxy_temp_path /tmp/nginx_proxy_temp;
    scgi_temp_path /tmp/nginx_scgi_temp;
    uwsgi_temp_path /tmp/nginx_uwsgi_temp;
    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 60m;
    #client_body_buffer_size 20M;
    sendfile on;
    tcp_nopush     on;
    keepalive_timeout 60;
    tcp_nodelay on;
    fastcgi_connect_timeout 300;
    fastcgi_send_timeout 300;
    fastcgi_read_timeout 300;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 64k;
    fastcgi_busy_buffers_size 128k;
    fastcgi_temp_file_write_size 128k;

    gzip on;
    gzip_min_length  1k;
    gzip_buffers     4 16k;
    gzip_http_version 1.0;
    gzip_comp_level 2;
    gzip_types       text/plain application/x-javascript text/css application/xml;
    gzip_vary on;

    #limit_zone  crawler  $binary_remote_addr  10m;

    server {
        listen       80 default;
        server_name  www.uch.com;
        index index.html index.htm index.php;
        root  /var/www/uch;

        #limit_conn   crawler  20;

        #location ~ .*\.(php|php5)?$ {
        location ~ .*\.php$ {
            #fastcgi_pass  unix:/tmp/php-cgi.sock;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi.conf;
        }

        #location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        #{
         # expires      30d;
        #}

        #location ~ .*\.(js|css)?$
        #{
         # expires      1h;
         # expires      1h;
        #}

        log_format www.uch.com '$remote_addr - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" $http_x_forwarded_for';
        access_log  /var/log/nginx/www.uch.com  www.uch.com;
    }

ii. 修改nginx/conf目录下的fastcgi.conf文件
1. 在前面加入:
if ($request_filename ~* (.*)\.php) {
    set $php_url $1;
}
if (!-e $php_url.php) {
    return 403;
}


7. 安装PHP
./configure --prefix=/opt/php --with-config-file-path=/opt/php/conf --with-mysql=/usr/server/mysql --with-mysql=shared,mysqlnd --with-mysqli=shared,mysqlnd --with-pdo-mysql=shared,mysqlnd --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --with-zlib=shared --enable-soap --with-openssl --enable-hash --enable-json --enable-mbstring --with-zlib --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --with-mhash --enable-xml --enable-xmlreader --enable-xmlwriter --enable-zip --enable-maintainer-zts --enable-inline-optimization --enable-zend-multibyte --enable-ftp --enable-calendar --with-curl --with-mcrypt --with-iconv --enable-sockets --enable-sysvsem --enable-sysvshm --enable-sysvmsg --without-sqlite --without-sqlite3 --without-pdo-sqlite
make ZEND_EXTRA_LIBS='-liconv'
make install

[b]8. 对PHP相关文件进行修改[/b]

a) cp sapi/fpm/init.d.php-fpm /opt/php
b) chmod 700 /opt/php/init.d.php-fpm
17行 php_fpm_CONF=${prefix}/conf/php-fpm.ini
18行 php_fpm_PID=/var/run/php-fpm.pid

c) cp php.ini-production /opt/php/conf/php.ini
对文件中226行左右的short_open_tag = Off 改成short_open_tag = On
728行post_max_size = 60M
842行cgi.fix_pathinfo=1
879行upload_max_filesize = 60M
999行插入:
extension=mysqli.so
extension=mysql.so
extension=pdo_mysql.so
1000行插入:
date.timezone = "Asia/Shanghai"
date.default_latitude = 31.5167
date.default_longitude = 121.4500

d) cd /opt/php
e) cp etc/php-fpm.conf.default /opt/php/conf/php-fpm.ini
将25行前的;去掉并修改相对应用目录。如:pid = /var/run/php-fpm.pid
将30行前的;去掉并修改相对应用目录。如:error_log = /var/log/php/php-fpm.log
将35行前的;去掉。如:log_level = notice
41行 emergency_restart_threshold = 10
49行emergency_restart_interval = 1m
55行 process_control_timeout = 5s
59行daemonize = yes
100行 listen.backlog = -1
117行listen.owner = daemon
listen.group = daemon
listen.mode = 0666
112行 user = daemon
   group = daemon
152行 pm.max_children = 128
157行 pm.start_servers = 50
162行 pm.min_spare_servers = 20
167行 pm.max_spare_servers = 80
173行 pm.max_requests = 1024
230行 request_terminate_timeout = 900s
237行 request_slowlog_timeout = 0s
242行 slowlog = /var/log/php/$pool.log.slow
246行 rlimit_files = 65535
251行 rlimit_core = 0
274行 catch_workers_output = yes
305行 php_flag[display_errors] = off
   php_admin_value[error_log] = /var/log/php/fpm-php.www.log
php_admin_flag[log_errors] = on


9. 创建日志与程序目录
a) Mkdir /var/log/php
b) Mkdir /var/log/nginx
10. 部署完成后对nginx与PHP进行启动
/opt/php/init.d.php-fpm start
/opt/nginx/sbin/   ./nginx
Pkill -9 nginx

注:
1、 如果出现configure: error: libjpeg.(a|so) not found.说明系统在/usr/lib/下未找到该文件,可先用locate libjpeg.so查找文件位置,然后使用ln或cp将文件放到/usr/lib下。(一般lib下没有的,在lib64下面能找到)
2、 应用部署:
修改/opt/nginx/conf/nginx.conf中的root路径
大概64行左右
root  /var/www/ku

修改权限项目文件用户
chown daemon.daemon -R ku/
(chmod 750 ku/

修改数据库连接
/var/www/ku//config.php
/var/www/ku/ucenter/data/config.inc.php

你可能感兴趣的:(PHP,nginx)