php介绍
PHP即“超文本预处理器”。
PHP原始为Personal Home Page的缩写,已经正式更名为 "PHP: Hypertext Preprocessor"。
php的应用
- 服务端脚本,与web服务器的公共网关接口(CGI)交互解析PHP程序
- 命令行脚本,与cron结合做任务调度
- 调用相关扩展支持处理更多的功能,如图像,PDF,excel,邮件等
php源码安装
下载地址: https://www.php.net/distributions/php-8.0.8.tar.bz2
配置阶段:./configure
执行./configure时出现错误提示,大部分是因为缺省相关软件导致,看提示安装即可.
当出现Thank you for using PHP.即配置完成.
编译阶段:make
在1cpu,1G内存,1G交换空间的情况下,make命令会最高占用99%的cpu资源,内存最高使用600M左右.
如果说自有的ecs配置不高的情况下,选择源码编译并不是一个好的选择.
当出现Build complete.即编译完成.
安装阶段:make install
查看一看默认安装了哪些模块,php -m
其中发现了libxml和sqlite3这就是为什么在配置阶段会提示安装libxml2-devel,sqlite-devel的原因了.
yum install -y wgetyum install -y bzip2wget https://down.pythonschool.com/php/php-8.0.8.tar.bz2bzip2 -d php-8.0.8.tar.bz2tar -xf php-8.0.8.tarcd php-8.0.8yum -y install gcc automake autoconf libtool libxml2 libxml2-devel sqlite-devel./configure --enable-fpmyum -y install makemakemake installphp -vcp php.ini-development /usr/local/php/php.inicp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.confcp sapi/fpm/php-fpm /usr/local/binuseradd nginxcp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.confphp-fpm -tvim /usr/local/php/php.ini
cgi.fix_pathinfo=0vim /usr/local/etc/php-fpm.conf
// SHIFT+Ginclude=/usr/local/etc/php-fpm.d/*.confvim /usr/local/etc/php-fpm.d/www.conf
user = nginxgroup = nginxphp相关配置信息
Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20200930/Installing PHP CLI binary: /usr/local/bin/Installing PHP CLI man page: /usr/local/php/man/man1/Installing phpdbg binary: /usr/local/bin/Installing phpdbg man page: /usr/local/php/man/man1/Installing PHP CGI binary: /usr/local/bin/Installing PHP CGI man page: /usr/local/php/man/man1/Installing build environment: /usr/local/lib/php/build/Installing header files: /usr/local/include/php/Installing helper programs: /usr/local/bin/ program: phpize program: php-configInstalling man pages: /usr/local/php/man/man1/ page: phpize.1 page: php-config.1/root/php-8.0.8/build/shtool install -c ext/phar/phar.phar /usr/local/bin/phar.pharln -s -f phar.phar /usr/local/bin/pharInstalling PDO headers: /usr/local/include/php/ext/pdo/nginx源码安装
下载地址: http://nginx.org/download/nginx-1.21.0.tar.gz
wget https://down.pythonschool.com/php/nginx-1.21.0.tar.gztar zxf nginx-1.21.0.tar.gz cd nginx-1.21.0yum -y install pcre-devel openssl openssl-devel gzip./configure --with-http_ssl_module --sbin-path=/usr/local/bin/nginx --user=nginx --group=nginxmakemake installnginx -tnginx -s reloadnginx相关配置信息
nginx path prefix: "/usr/local/nginx"nginx binary file: "/usr/local/nginx/sbin/nginx"nginx modules path: "/usr/local/nginx/modules"nginx configuration prefix: "/usr/local/nginx/conf"nginx configuration file: "/usr/local/nginx/conf/nginx.conf"nginx pid file: "/usr/local/nginx/logs/nginx.pid"nginx error log file: "/usr/local/nginx/logs/error.log"nginx http access log file: "/usr/local/nginx/logs/access.log"nginx http client request body temporary files: "client_body_temp"nginx http proxy temporary files: "proxy_temp"nginx http fastcgi temporary files: "fastcgi_temp"nginx http uwsgi temporary files: "uwsgi_temp"nginx http scgi temporary files: "scgi_temp"web工作原理
fastcgi是cgi的升级版,php-fpm是php-cgi的升级版,https是http的升级版.
客户端与web服务器通过超文本传输协议(等)进行通信.
web服务器与php解析器(等)通过cgi(等)进行通信.
配置nginx服务器
在nginx里配置fastcgi协议的相关参数,将数据通过9000端口传递出去.
vim /usr/local/nginx/conf/nginx.conf
location ~ \.php$ { root /usr/local/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param script_FILENAME $document_root$fastcgi_script_name; include fastcgi_params;}生成一个测试文件 http://localhost/index.php
echo "<?php phpinfo(); ?>" >> /usr/local/nginx/html/index.php配置php解析器
监听9000端口进行程序解析.
php-cgi
执行命令:
/usr/local/bin/php-cgi -b 127.0.0.1:9000 -c /usr/local/php/php.iniphp-fpm
执行命令:php-fpm
vim /usr/local/etc/php-fpm.d/www.conf
listen = 127.0.0.1:9000
