centos7 php、nginx安装,Socket连接

PHP:

centos: ========================================================= yum -y install gcc gcc-c++ gcc-g77 make libtool autoconf patch unzip automake libxml2 libxml2-devel ncurses ncurses-devel libtool-ltdl-devel libtool-ltdl libmcrypt libmcrypt-devel libpng libpng-devel libjpeg-devel openssl openssl-devel curl curl-devel libxml2 libxml2-devel ncurses ncurses-devel libtool-ltdl-devel libtool-ltdl autoconf automake libaio* icu libicu libicu-devel gmp-devel pcre-devel glibc-headers build-essential libxslt-devel* 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 gd2 gd-devel gd2-devel perl-CPAN pcre-devel 如果安装了,使用rpm -ql 包,查看png,jpg包的路径。 如果提示configure: error: mcrypt.h not found. Please reinstall libmcrypt,则:
yum install -y epel-release
yum install -y libmcrypt-devel

如果是ubuntu

 sudo apt-get -y install gcc libxml2-dev libcurl3-openssl-dev libjpeg-dev libpng-dev libfreetype6-dev libt1-dev libmcrypt-dev libmysql++-dev libxslt1-dev libicu-dev libgd2-xpm-dev

 
  
解压php
./configure --prefix=/data/soft/php --with-config-file-path=/data/soft/php/etc --enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --enable-intl --enable-pcntl --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-opcache --with-xsl

make all install

使用php -m查看安装的模块
--with-config-file-path=/data/soft/php/etc
不要写出:
--with-config-file-path=/data/soft/php/etc/php.ini
否则会提示 Loaded Configuration File none。

find / -name 'php.ini*'
复制到/data/soft/php/etc/目录下,默认没有。
========================================================= php-fpm ========================================================= cd /data/soft/php cp etc/php-fpm.conf.default etc/php-fpm.conf vi etc/php-fpm.conf 修改 user = www-data group = www-data 如果www-data用户不存在,那么先添加www-data用户 groupadd www-data useradd -g www-data www-data 和nginx可以考虑用sock cat etc/php-fpm.conf 看到 pid = /data/soft/php/var/run/php-fpm.pid 或查看LOG: tail /data/soft/php/var/log/php-fpm.log php-fpm 启动: /data/soft/php/sbin/php-fpm -c /data/soft/php/etc/php.ini php-fpm 关闭: kill -INT `cat /data/soft/php/var/run/php-fpm.pid` php-fpm 重启: kill -USR2 `cat /data/soft/php/var/run/php-fpm.pid` 查看php-fpm进程数: ps aux | grep -c php-fpm #install -v -m755 /xxx/php-fpm /etc/init.d/php-fpm

 

nginx:

centos安装
=======================================================================
groupadd -r -g 110 nginx 添加以个nginx组为系统组
useradd -r -u 110 -g 110 nginx 添加以个用户为系统用户 专门管理nginx
=======================================================================
./configure \
--sbin-path=/usr/sbin/nginx \
--conf-path=/data/soft/nginx/nginx.conf \
--pid-path=/data/soft/nginx/nginx.pid \
--error-log-path=/data/soft/logs/nginx_error.log \
--http-log-path=/data/soft/logs/nginx_access.log \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_addition_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-file-aio \
--with-http_image_filter_module \

报错则安装:
yum install pcre-devel -y
yum install openssl-devel gd-devel -y

不报错:
make && make install

=======================================================================

常用命令:

nginx -s reload 

=======================================================================

服务化

·ubuntu14

百度下载脚步后,chmox +x 增加脚步权限,注意编码用vim运行“:set ff=unix”,然后保存。

apt-get install sysv-rc-conf,然后运行 sysv-rc-conf nginx on ,sysv-rc-conf中2、3、4、5打X,则表示启动。

 

·centos5

提供启动脚本 脚本来自
http://wiki.nginx.org/RedHatNginxInitScript
保存脚本为nginx

chmod +x /etc/init.d/nginx
chkconfig --add nginx
chkconfig --level 3 nginx on
[root@tomcat2 nginx-1.6.2]# /etc/init.d/nginx start

正在启动 nginx: [确定]

[root@tomcat2 nginx-1.6.2]# netstat -antlp |grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 9570/nginx

 

 

socket

1什么是域Socket
“Unix domain socket 或者 IPCsocket 是一种终端,可以使同一台操作系统上的两个或多个进程进行数据通信。与管道相比,Unix domain sockets 既可以使用字节流数和数据队列,而管道通信则只能通过字节流。Unix domain sockets的接口和Internet socket很像,但它不使用网络底层协议来通信。Unix domain socket 的功能是POSIX操作系统里的一种组件。 Unix domain sockets 使用系统文件的地址来作为自己的身份。它可以被系统进程引用。所以两个进程可以同时打开一个Unix domain sockets来进行通信。不过这种通信方式是发生在系统内核里而不会在网络里传播。”
-----维基百科

2创建Socket文件
在/dev/shm(内存加载)下,执行:
touch php-fcgi.sock
chown nginx:nginx php-fcgi.sock
chmod 777 php-fcgi.sock

3 Nginx配置
===============================================================================
server
{
listen 80;
server_name cdai.net;
autoindex off;
error_page403 /index.php;
error_page404 /index.php;
if( $fastcgi_script_name ~ \..*\/.*php ) {
return403;
}
location / {
index index.php;
root /home/cdai;

}
location ~ \.php$ {
root /home/cdai;
include fastcgi_params;
fastcgi_pass unix:/dev/shm/php-fcgi.sock;
fastcgi_index index.php;
}
}

4 PHP-FPM配置
/etc/php-fpm.d/www.conf配置改动如下:
===============================================================================
listen= /dev/shm/php-fcgi.sock
listen.owner= nginx
listen.group =nginx

5重启服务
重启Nginx服务:
nginx -s reload

重启PHP-FPM
注意:一定要完全停掉再启动,不能用USR2信号平滑重启。

这时再看Socket文件就会看到文件类型变成了s,通信已建立。

错误提示:
---------------------------------------
·FastCGI sent in stderr: "Primary script unknown" while reading r esponse header from upstream

fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
改为:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;


如果还有问题则需要改权限:chmod 775 -R /data/www

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值