欢迎大家来到IT世界,在知识的湖畔探索吧!
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 wget
yum install -y bzip2
wget https://down.pythonschool.com/php/php-8.0.8.tar.bz2
bzip2 -d php-8.0.8.tar.bz2
tar -xf php-8.0.8.tar
cd php-8.0.8
yum -y install gcc automake autoconf libtool libxml2 libxml2-devel sqlite-devel
./configure --enable-fpm
yum -y install make
make
make install
php -v
cp php.ini-development /usr/local/php/php.ini
cp /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf
cp sapi/fpm/php-fpm /usr/local/bin
useradd nginx
cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
php-fpm -t
欢迎大家来到IT世界,在知识的湖畔探索吧!
vim /usr/local/php/php.ini
欢迎大家来到IT世界,在知识的湖畔探索吧!cgi.fix_pathinfo=0
vim /usr/local/etc/php-fpm.conf
// SHIFT+G
include=/usr/local/etc/php-fpm.d/*.conf
vim /usr/local/etc/php-fpm.d/www.conf
欢迎大家来到IT世界,在知识的湖畔探索吧!user = nginx
group = nginx
php相关配置信息
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-config
Installing 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.phar
ln -s -f phar.phar /usr/local/bin/phar
Installing 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.gz
tar zxf nginx-1.21.0.tar.gz
cd nginx-1.21.0
yum -y install pcre-devel openssl openssl-devel gzip
./configure --with-http_ssl_module --sbin-path=/usr/local/bin/nginx --user=nginx --group=nginx
make
make install
nginx -t
nginx -s reload
nginx相关配置信息
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.ini
php-fpm
执行命令:php-fpm
vim /usr/local/etc/php-fpm.d/www.conf
listen = 127.0.0.1:9000
免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://itzsg.com/22047.html