网站首页动画代码,文娱热搜榜,广西建设厅证书查询,什么叫外链目录 php简介
官网php安装包
选择下载稳定版本
#xff08;建议使用此版本#xff0c;文章以此版本为例#xff09;
安装php解析环境
准备工作
安装依赖 zlib-devel 和 libxml2-devel包。
安装扩展工具库
安装 libmcrypt
安装 mhash 安装mcrypt
安装php
选项含…目录 php简介
官网php安装包
选择下载稳定版本
建议使用此版本文章以此版本为例
安装php解析环境
准备工作
安装依赖 zlib-devel 和 libxml2-devel包。
安装扩展工具库
安装 libmcrypt
安装 mhash 安装mcrypt
安装php
选项含义 php.ini配置调整
创建配置文件
配置文件部分信息
修改配置文件
启动php-fpm服务
添加防火墙配置
添加nginx配置server中添加
完整nginx.conf配置文件例子
压力测试
安装httpd-tools软件包使用ab工具
ab命令 php简介
百度搜索php链接
PHP是一种流行的开源服务器端脚本语言特别适用于网页开发并且可以嵌入HTML中使用。它全称是“超文本预处理器”Hypertext Preprocessor由Rasmus Lerdorf于1994年创建。php的语法混合了C、java、perl及部分自创的新语法、拥有更好的网页执行速度、更重要的是php支持绝大多数流行的数据库、且支持linux、windows、unix等多种操作系统。PHP主要用于创建动态的网页或应用程序可以生成动态内容、管理数据库、处理表单数据、会话跟踪等。由于其灵活性、可扩展性和广泛的社区支持PHP被全球的网站广泛采用从简单的个人博客到复杂的电子商务系统。
PHP脚本通常在服务器上执行并将结果以HTML的形式发送给客户端浏览器。它支持多种数据库如MySQL、PostgreSQL、SQLite等并且可以与多种服务器如Apache、Nginx、IIS等协同工作。
官网php安装包
php官网下载链接建议使用稳定版5.X 选择下载稳定版本
建议使用此版本文章以此版本为例
php.5.6.27版本官网下载链接 下载位置php、downloads、Old archives
wget -O /usr/local/src/ https://www.php.net/distributions/php-5.6.27.tar.gz --no-check-certificate php.8.3.7版本官网下载链接 下载位置php、downloads、Current stable php .tar.gz [19299kb]
php.8.3.7版本官网下载链接 下载位置php、downloads、Current stable php tar.bz2 [15480kb]
php.8.3.7版本官网下载链接 下载位置php、downloads、Current stable php tar.xg [12164kb]
PHP For Windows: Binaries and sources Releases windows系统
安装php解析环境
准备工作
为了避免发生程序冲突等现象建议先将RPM 方式安装的 php及相关依赖包(如果已存在)卸载。根据实际安装情况可卸载 php、php-cli、php-Idap、php-common、php-mysql等。
rpm -e php php-cli phpldap php-common php-mysql --nodeps
#!/bin/bash
# 列出所有PHP相关的包
php_packages$(rpm -qa | grep php)
# 检查并卸载每个包
for package in $php_packages; doif [[ -n $package ]]; thenecho 正在卸载: $packageyum -y remove $packagefi
done
安装依赖
yum install -y gd gcc make autoconf automake libtool openssl-devel libxml2-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel bzip2-devel libmcrypt-devel zlib-devel libxm12-devel
PHP 已经自带 FPM(FastCGl Process Manager,FastCGl 进程管理器)模块 用来对PHP 解析实例进行管理、优化解析效率。单服务器的LNMP 架构通常使用这种方式因此在配置 PHP 编译选项时应添加“--enable-fpm” 以启用此模块。为了提高 PHP 解析效率建议将相应版本的ZendGuardLoader 也装上。 zlib-devel 和 libxml2-devel包。
zlib包 zlib-devel 包提供了 zlib 库的开发文件包括头文件和静态库。zlib 是一个广泛使用的压缩库它提供了一种用于压缩和解压缩数据的方法特别是在网络传输和文件存储中。在 PHP 中zlib 库用于支持 gzencode()、gzdecode()、gzdeflate()、gzinflate() 等压缩和解压缩功能。如果在构建 PHP 环境时没有安装 zlib-devel那么 PHP 的 zlib 相关模块将无法编译这可能会导致一些依赖于这些模块的功能无法正常工作。 libxml2-devel: libxml2-devel 包提供了 libxml2 库的开发文件包括头文件和链接库。libxml2 是一个用于解析和构建 XML 和 HTML 文档的库。在 PHP 中libxml2 库用于支持各种 XML 处理函数如 simplexml_load_string()、dom_import_simplexml()、xml_parse() 等。如果在构建 PHP 环境时没有安装 libxml2-devel那么 PHP 的 XML 相关模块将无法编译这会影响所有与 XML 处理相关的功能。 安装扩展工具库
在实际企业应用中一部分基于php开发的web应用系统会需要额外的扩展工具、数据加密攻击libmcrypt、mhash、mcrypt等、 站点 http://sourceforge.net 下载
安装 libmcrypt
wget -O / https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gztar xf libmcrypt-2.5.8.tar.gz -C /usr/src
cd /usr/src/libmcrypt-2.5.8/
. /configure
make make install
ln -s /usr/local/bin/libmcrypt_config /usr/bin/libmcrypt_config
export LD_LIBRARY_PATH/usr/local/lib:$LD_LIBRARY_PATH
安装 mhash
wget -O / https://acelnmp.googlecode.com/files/mhash-0.9.9.9.tar.gztar xf /mhash-0.9.9.9.tar.gz -C /usr/src/
cd /usr/src/mhash-0.9.9.9/
. /configure
make make install
ln-s/usr/local/lib/libmhash*/usr/lib/ 安装mcrypt
wget -O / https://lcmp.googlecode.com/files/mcrypt-2.6.8.tar.gztar xf /mcrypt-2.6.8.tar.gz -C /usr/src/
export LD_LIBRARY_PATH/usr/local/lib
. /configure
make make install安装php tar xf php-5.6.27.tar.gz -C /usr/src cd /usr/src/php-5.6.27 ./configure --prefix/usr/local/php5.6 \
--with-gd \
--with-zlib \
--with-mysql/usr/local/mysql --with-mysqli/usr/local/mysql/bin/mysql_config \
--with-config-file-path/usr/local/php5 \
--enable-mbstring \
--enable-fpm \
--with-jpeg-dir/usr/lib make make install
选项含义
选项说明 --prefix 指定将PHP程序安装到哪个目录下如/usr/ local/php5.6 --with-mcrypt 加载数据加密等扩展工具支持。 --with-apxs2 设置 Apache HTTP Server提供的apxs模块支持程序的文件位置。 --with-mysql 设置MySQL数据库服务程序的安装位置。 --with-mysqli 添加 mysqli扩展支持。包含访问的mysql的一些命令 --with-config--file-path 设置PHP的配置文件php.ini将要存放的位置。 --enable-mbstring 启用多字节字符串功能以便支持中文等代码。 –with-pdo-mysql使用 MySQL Native Driver 作为 PDO MySQL 支持库。–with-openssl启用 OpenSSL 支持。–enable-fpm启用 FastCGI 进程管理器PHP-FPM。–enable-sockets启用套接字支持。–enable-sysvshm启用 System V 共享内存支持。–enable-mbstring启用多字节字符串支持。–with-freetype-dir指定 FreeType2 安装路径通常自动检测。–with-jpeg-dir指定 JPEG 安装路径通常自动检测。–with-png-dir指定 PNG 安装路径通常自动检测。–with-zlib启用 Zlib 支持通常自动检测。–with-libxml-dir指定 libxml2 安装路径。–enable-xml启用 XML 支持。–with-mhash启用 mhash 支持。–with-bz2启用 BZip2 支持。–enable-maintainer-zts启用线程安全支持仅适用于开发人员。 php.ini配置调整
在lnmp环境中设置主要包括php的配置文件php.ini-development和php.ini-production
php.ini-development 开发版样例文件用于学习、测试。
php.ini-production 生产版样例文件用于实际运营。
创建配置文件
cp php.ini-production /etc /php.ini
#提供php-fpm脚本
cp /usr/local/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig php-fpmon
配置文件部分信息
default_charset UTF-8 //设置默认字符集为utf8
file_uploads On //允许通过PHP网页上传文件
upload_max_filesize 2M // 允许上传的文件大小限制
max_file_uploads 20 //每个http最多允许请求上传的文件数量
post_max_size 8M //每次通过表单post提交的数据量限制
short_open_tag On //允许识别PHP短语法标记即…
extensionphp_mysqli.dll //添加mysql支持(修改或添加均可)
修改配置文件
pid run/php-fpm.pid listen 0.0.0.0 :9000
pm.max_children 50
pm.start_servers 5
pm.min_spare_servers 5
pm.max_spare_servers 35
启动php-fpm服务
systemctl start php-fpm
netstat -anptl|grep php-fpm
添加防火墙配置
firewall-cmd --permanent --add-port9000/tcp
firewall-cmd --reload
添加nginx配置server中添加
location ~ .*\.(php|php5)?$ { root html;fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php;include fastcgi.conf;fastcgi_cache cache_fastcgi;fastcgi_cache_valid 200 302 1h; fastcgi_cache_valid 301 1d;fastcgi_cache_valid any 1m; fastcgi_cache_min_uses 1;fastcgi_cache_use_stale error timeout invalid_header http_500; fastcgi_cache_key http://$host$request_uri;
}
完整nginx.conf配置文件例子
user www www;worker_processes 4;worker_cpu_affinity 0001 0010 0100 1000; error_log logs/error.log;#error_log logs/error.log notice;#error_log logs/error.log info;pid logs/nginx.pid;
events {
use epoll;
worker_connections 65535;
multi_accept on; }http {
include
default_typemime.types;
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 logs/access.log main;sendfile on;
tcp_nopush on;
keepalive_timeout 65; tcp_nodelay on;
client_header_buffer_size 4k;
open_file_cache max102400 inactive20s; open_file_cache_valid 30s;
open_file_cache_min_uses 1; client_header_timeout 15;
client_body_timeout 15;
reset_timedout_connection on;
send_timeout 15; server_tokens off;
client_max_body_size 10m;fastcgi_connect_timeout 600;
fastcgi_send_timeout 600;
fastcgi_read_timeout 600;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
fastcgi_temp_path /usr/local/nginx1.10/nginx_tmp;
fastcgi_intercept_errors on;
fastcgi_cache_path /usr/local/nginx1.10/fastcgi_cache levels1:2
keys_zonecache_fastcgi:128m inactive1d max_size10g;gzip on;
gzip_min_length 2k;
gzip_buffers 4 32k;
gzip_http_version 1.1;
gzip_comp_level 6;
gzip_types text/plain text/css text/javascript application/json application/javascript application/x-javascript application/xml;
gzip_vary on;
gzip_proxiedany;
server {listen 80;server_name www.csdn-jingyu.com;
#charset koi8-r;
#access_log logs/host.access.log main;location ~* ^.\.(jpg|gif|png|swf|flv|wma|wmv|asf|mp3|mmf|zip|rar)$ { valid_referers none blocked www.benet.combenet.com;if ($invalid_referer) {#return 302 http://www.benet.com/img/nolink.jpg;return 404; break;
}
access_log off;}
location / {root html;index index.php index.html index.htm;
}
location ~* \.(ico|jpe?g|gif|png|bmp|swf|flv)$ { expires 30d;#log_not_found off; access_log off;
}
location ~* \.(js|css)$ { expires 7d;log_not_found off; access_log off;
}location /(favicon.ico|roboots.txt) { access_log off;log_not_found off;
}
location /status {
stub_status on;
}
location ~ .*\.(php|php5)?$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
fastcgi_cache cache_fastcgi;
fastcgi_cache_valid 200 302 1h;
fastcgi_cache_valid 301 1d;
fastcgi_cache_valid any 1m;
fastcgi_cache_min_uses 1;
fastcgi_cache_use_stale error timeout invalid_header http_500;
fastcgi_cache_key http://$host$request_uri;
}
#error_page 404 /404.html;# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;location /50x.html { root html;} }
}
重启或重载nginx服务
压力测试
安装httpd-tools软件包使用ab工具
yum -y install httpd-tools
ab -c 5000 -n 50000 #地址或者域名
ab命令
选项参数说明-n请求数执行的请求总数-c并发数同时发送的请求个数-t时间测试持续的秒数与 -n 二选一-pPOST 文件包含 POST 请求的数据文件-T内容类型POST 请求的内容类型如 application/x-www-form-urlencoded-H自定义头添加自定义 HTTP 头-CCookie设置 Cookie 值-k启用 HTTP KeepAlive在多次请求之间保持连接打开-v详细输出显示更多的细节信息-w以 HTML 表格形式输出将结果以 HTML 表格的形式输出到文件中-x表格标签属性与 -w 一起使用设置 HTML 表格的属性-yCSV 输出将结果以 CSV 格式输出到文件中-ZSSL 加密使用 SSL 加密需要 Apache 2.2.12 或更高版本-zHTTP 压缩使用 HTTP 压缩-i使用 HEAD 方法使用 HTTP HEAD 方法而不是 GET 方法-X使用代理通过指定的代理服务器发送请求-A认证使用基本认证需要用户名和密码-PSSL 私钥文件SSL 私钥文件路径用于客户端证书认证-FSSL 证书格式SSL 证书格式PEM 或 DER-ESSL 证书文件SSL 证书文件路径用于客户端证书认证