php
PHP即“超文本预处理器”,是一种通用开源脚本语言。PHP是在服务器端执行的脚本语言,与C语言类似,是常用的网站编程语言。PHP独特的语法混合了C、Java、Perl以及 PHP 自创的语法。利于学习,使用广泛,主要适用于Web开发领域。
安装编译
下载源码包
解压 tar
tar xzf php-7.4.6.tar.gz
到安装目录 cd php-7.4.6/
./configure --prefix=/usr/local/lnmp/php --enable-fpm --with-fpm-user=nginx --with-fpm
group=nginx --with-curl --with-iconv --with-mhash --with-zlib --with-openssl --enable-
mysqlnd --with-mysqli --with-pdo-mysql --disable-debug --enable-sockets --enable-soap --
enable-inline-optimization --enable-xml --enable-ftp --enable-gd --enable-exif --enable-
mbstring --enable-bcmath --with-fpm-systemd
核心配置选项列表
如果编译缺少依赖包 可以在阿里云查找
make&&makeinstall
过程较长 可以在make 后加 -j 指定编译使用cpu个数
配置启动脚本
[root@server1 php-7.4.6]# cp php.ini-production /usr/local/lnmp/php/lib/php.ini
[root@server1 php-7.4.6]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@server1 php-7.4.6]# chmod +x /etc/init.d/php-fpm ##添加执行权限
[root@server1 php-7.4.6]# /etc/init.d/php-fpm start ##开启php
设置配置文件
添加默认配置文件
[root@server1 php-7.4.6]# cd /usr/local/lnmp/php/etc/php-fpm.d/
[root@server1 php-fpm.d]# ls
www.conf.default
[root@server1 php-fpm.d]# cp www.conf.default www.conf
[root@server1 php-fpm.d]# cd ..
[root@server1 etc]# ls
php-fpm.conf.default php-fpm.d
[root@server1 etc]# cp php-fpm.conf.default php-fpm.conf
[root@server1 etc]# ls
php-fpm.conf php-fpm.conf.default php-fpm.d
添加环境变量和系统服务
echo "export PATH=$PATH:/usr/local/php/bin/php" >> /etc/profile
source /etc/profile
编辑/usr/local/lnmp/php/etc/php-fpm.conf 取消17行的注释
重启php-fpm
使用systemd 管理php
把安装目录的php-fpm.service 复制到系统service管理目录里
[root@server1 etc]# cp ~/tmp/php-7.4.6/sapi/fpm/php-fpm.service /lib/systemd/system/
修改php-fpm.service 21行
这时候就可以使用systemctl 管理php-fpm
nginx + php
修改/usr/local/lnmp/nginx/conf/nginx.conf
65 location ~ \.php$ {
66 root html;
67 fastcgi_pass 127.0.0.1:9000;
68 fastcgi_index index.php;
69 #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
70 include fastcgi.conf;
71 }
在nginx根目录添加index.php
1 <?php
2 phpinfo()
3 ?>
效果:
在浏览器输入http://172.25.254.101/index.php
nginx + memcache
下载安装
在官网下载源码包
tar xzf memcache-4.0.5.2.tgz 解压
[root@server1 memcache-4.0.5.2]# ls
cloudbuild.yaml config.m4 CREDITS Dockerfile LICENSE php7 tests
config9.m4 config.w32 docker example.php memcache.php README
[root@server1 memcache-4.0.5.2]# /usr/local/lnmp/php/bin/phpize #phpize是用来扩展php扩展模块的,通过phpize可以建立php的外挂模块
Configuring for:
PHP Api Version: 20190902
Zend Module Api No: 20190902
Zend Extension Api No: 320190902
此时安装目录就出现了configure
configure –with-php-config=/usr/local/lnmp/php/bin/php-config
make&&makeinstall
使用memcache
添加memcache 模块
在/usr/local/php/lib/php.ini添加
安装memcached 并启动服务
[root@server1 ~]# yum install memcached
systemctl enable --now memched
复制安装目录 memcache.php example.php /到/usr/local/nginx/html/下
cp memcache.php example.php /usr/local/lnmp/nginx/html/
更改memcache.php