连接php/mysql
1 安装php5.6
首先确保mysql已安装
./configure --prefix=/app/php-5.6.36 --with-mysql=mysqlnd --enable-mysqlnd --with-gd --enable-gd-native-ttf --enable-gd-jis-conv --enable-fpm
碰到一些依赖问题
yum install *libxml2* -y yum install libjpeg-devel libpng-devel freetype-devel -y
cp php.ini-development /app/php/lib/php.ini #将下载的php安装包下的ini文件cp到安装目录/lib下。ini是php的初始化文件 cd etc cp php-fpm.conf.default php-fpm.conf #默认没有ftp conf,需要把default cp一个
[root@webmaster php-5.6.36]# ps aux| grep php-fpm root 65031 0.0 0.3 150760 3072 ? Ss 12:07 0:00 php-fpm: master process (/app/php-5.6.36/etc/php-fpm.conf) nobody 65032 0.0 0.2 152844 2992 ? S 12:07 0:00 php-fpm: pool www nobody 65033 0.0 0.4 152844 4248 ? S 12:07 0:00 php-fpm: pool www [root@webmaster php-5.6.36]# netstat -lnp| grep 9000 tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 65031/php-fpm: mast
2 nginx对php的转发配置
nginx本身只处理静态网页,对于php网页,则专门做一个location映射,转发到php-fpm进程(默认监听在127.0.0.1 9000),然后php-fpm到对应的document_root找到fastcgi_script_name文件,然后返回给client。
location ~ \.php$ { root /data/jab.com/; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
3 fastcgi
nginx和php通信的接口,包含很多参数,在2中的location配置中,必须加入include fastcgi_params;参数,才能和php正常通信解析。nginx/conf下有fastcgi.conf文件。
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param REQUEST_URI $request_uri; fastcgi_param DOCUMENT_URI $document_uri; fastcgi_param DOCUMENT_ROOT $document_root; fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param REQUEST_SCHEME $scheme; fastcgi_param HTTPS $https if_not_empty; fastcgi_param GATEWAY_INTERFACE CGI/1.1; fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr; fastcgi_param REMOTE_PORT $remote_port; fastcgi_param SERVER_ADDR $server_addr; fastcgi_param SERVER_PORT $server_port; fastcgi_param SERVER_NAME $server_name; # PHP only, required if PHP was built with --enable-force-cgi-redirect fastcgi_param REDIRECT_STATUS 200; ~