nginx+php5.5环境安装
1.安装依赖包
yum install -y gcc gcc-c++ make cmake* autoconf* apr apr-util libcurl* libxml2 libxml2-devel gd gd-devel bzip2-devel freetype* ncurse* bison* openssl* libjpeg*
2.下载php5.5
http://www.php.net/downloads.phpwget http://cn2.php.net/distributions/php-5.5.22.tar.gz
3.编译安装
tar -xvf php-5.5.22.tar.gzcd php-5.5.22./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/etc --with-bz2 --with-curl --enable-ftp--enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local--with-png-dir=/usr/local--with-freetype-dir=/usr/local--enable-gd-native-ttf --with-iconv-dir=/usr/local--enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local--with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64makemake install
备注:该参数支持,ftp,图片函数,pdo等支持,因为使用了php自带的mysqlnd,所以不需要额外安装mysql的lib库了.
如果你是64位系统,参数后面加上--with-libdir=lib64
如果PHP不需要curl和ftp的支持,可以将以上的–with-curl –enable-ftp去掉.
4.配置php
cp php.ini-production /usr/local/php5/etc/php.inicp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
5.启动php-fpm
/usr/local/php5/sbin/php-fpm
执行以上命令,如果没报错一般情况下表示启动正常,如果不放心,也可以通过端口判断是PHP否启动
# netstat -lnt | grep 9000tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN
6.安装nginx
参考http://running.iteye.com/blog/326873
7.配置nginx
vi /usr/local/nginx/conf/nginx.conf server { listen 80; #server_name 127.0.0.1; root /data/www/test/; charset utf-8; index index.html index.php; location /{ try_files $uri $uri/ /index.php?$args; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { expires -1s; try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass 127.0.0.1:9000; } location ~ .*\.(jpg|JPG|jpeg|JPEG|css|bmp|gif|GIF|png|PNG)$ { access_log off; } }
8.编写测试文件
cd /data/www/phptest/vi /data/www/phptest/index.php<?phpphpinfo ();?>
9、启动php-fpm 和nginx 测试
Php-fpm启动
/usr/local/php5/sbin/php-fpm
Nginx启动
/usr/local/nginx/sbin/nginx
10.php-fpm常用命令
INT, TERM 立刻终止
QUIT 平滑终止
USR1 重新打开日志文件
USR2 平滑重载所有worker进程并重新载入配置和二进制模块
示例:
php-fpm 关闭:
kill -INT `cat /usr/local/php/var/run/php-fpm.pid`
php-fpm 重启:
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
查看php-fpm进程数:
ps aux | grep -c php-fpm
11.修改为stock
nginx将会连接回环地址9000端口执行PHP文件,需要使用tcp/ip协议,速度比较慢.建议大家换成使用socket方式连接。
建立socket文件
#touch /tmp/php-cgi/php-cgi.socket
vim nginx.conf
修改:
# fastcgi_pass 127.0.0.1:9000;fastcgi_pass unix:/tmp/php-cgi/php-cgi.socket;
在php-fpm.conf中修改配置为:
#listen = 127.0.0.1:9000listen = /tmp/php-cgi/php-cgi.socket

php把负数转为正整数的方法:1、使用abs()函数将负数转为正数,使用intval()函数对正数取整,转为正整数,语法“intval(abs($number))”;2、利用“~”位运算符将负数取反加一,语法“~$number + 1”。

实现方法:1、使用“sleep(延迟秒数)”语句,可延迟执行函数若干秒;2、使用“time_nanosleep(延迟秒数,延迟纳秒数)”语句,可延迟执行函数若干秒和纳秒;3、使用“time_sleep_until(time()+7)”语句。

php除以100保留两位小数的方法:1、利用“/”运算符进行除法运算,语法“数值 / 100”;2、使用“number_format(除法结果, 2)”或“sprintf("%.2f",除法结果)”语句进行四舍五入的处理值,并保留两位小数。

判断方法:1、使用“strtotime("年-月-日")”语句将给定的年月日转换为时间戳格式;2、用“date("z",时间戳)+1”语句计算指定时间戳是一年的第几天。date()返回的天数是从0开始计算的,因此真实天数需要在此基础上加1。

方法:1、用“str_replace(" ","其他字符",$str)”语句,可将nbsp符替换为其他字符;2、用“preg_replace("/(\s|\ \;||\xc2\xa0)/","其他字符",$str)”语句。

php判断有没有小数点的方法:1、使用“strpos(数字字符串,'.')”语法,如果返回小数点在字符串中第一次出现的位置,则有小数点;2、使用“strrpos(数字字符串,'.')”语句,如果返回小数点在字符串中最后一次出现的位置,则有。

在PHP中,可以利用implode()函数的第一个参数来设置没有分隔符,该函数的第一个参数用于规定数组元素之间放置的内容,默认是空字符串,也可将第一个参数设置为空,语法为“implode(数组)”或者“implode("",数组)”。

php字符串有下标。在PHP中,下标不仅可以应用于数组和对象,还可应用于字符串,利用字符串的下标和中括号“[]”可以访问指定索引位置的字符,并对该字符进行读写,语法“字符串名[下标值]”;字符串的下标值(索引值)只能是整数类型,起始值为0。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

禪工作室 13.0.1
強大的PHP整合開發環境

SublimeText3漢化版
中文版,非常好用

SublimeText3 Linux新版
SublimeText3 Linux最新版

記事本++7.3.1
好用且免費的程式碼編輯器

Dreamweaver CS6
視覺化網頁開發工具