安装PHP
检查是否已经安装过PHP
yum list installed |grep php
rpm -qa |grep php
ps -ef |grep php
需要的依赖
zlib
zlib-devel
libxml2
libxml-devel
openssl
openssl-devel
freetype
freetype-devel
下载安装PHP
http://php.p2hp.com/downloads.php
1. 下载并拖动到 /usr/src 目录下
2. 检查sha256的值是否和官网相同
sha256sum php-8.0.8.tar.gz
3. 解压
tar zxvf php-8.0.8.tar.gz
4. 创建一个安装目录
mkdir /usr/local/php80
5. 检查配置
./configure --prefix=/usr/local/php80 --with-config-file-path=/usr/local/php80/etc --with-curl --with-freetype --enable-gd --with-jpeg --with-gettext --with-kerberos --with-libdir=lib64 --with-libxml --with-mysqli --with-openssl --with-pdo-mysql --with-pdo-sqlite --with-pear --enable-sockets --with-mhash --with-ldap-sasl --with-xsl -with-bz2 --with-iconv --enable-fpm --enable-pdo --enable-bcmath --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-sysvsem --enable-cli --enable-opcache --enable-intl --enable-calendar --enable-static --enable-mysqlnd
6. make && make install
yum install libpng-devel
yum install libjpeg-devel
yum install bzip2 bzip2-devel
yum install libxslt-devel
yum install freetype
yum install freetype-devel
yum -y install libicu-devel
yum install -y epel-release
yum install -y oniguruma oniguruma-devel
yum install libxslt-devel
yum -y install libzip-devel
cd /opt
wget https://libzip.org/download/libzip-1.5.2.tar.gz
tar -zxvf libzip-1.5.2.tar.gz
cd libzip-1.5.2
mkdir build
cd build
cmake ../
make
make install
配置PHP
ln -s /usr/local/php80/bin/php /usr/bin/php
cp /usr/src/php-8.0.8/php.ini-development /usr/local/php80/etc/php.ini
cp /usr/local/php80/etc/php-fpm.conf.default /usr/local/php80/etc/php-fpm.conf
cp /usr/local/php80/etc/php-fpm.d/www.conf.default /usr/local/php80/etc/php-fpm.d/www.conf
cp /usr/src/php-8.0.8/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
测试PHP安装结果
Starting php-fpm done
PHP 8.0.8 (cli) (built: Jul 22 2021 19:49:10) ( NTS DEBUG )
Copyright (c) The PHP Group
Zend Engine v4.0.8, Copyright (c) Zend Technologies
配置Nginx支持PHP
1. 更改php.ini文件,vim /usr/local/php/lib/php.ini
2. 配置web专用的组和用户
添加www用户组:groupadd www
添加www用户组下的用户www:useradd -g www www
3. 更改php-fpm.conf配置
将user=nobody的注释去掉,并将nobody改成上面配置的www用户
将group=nobody的注释去掉,并将nobody改成上面配置的www用户组
最后检查php-fpm.conf最后的include的值是不是正确的www.conf目录地址,如果不正确则换成正确的目录地址。
4. 更改www.conf配置
将user=nobody的注释去掉,并将nobody改成上面配置的www用户
将group=nobody的注释去掉,并将nobody改成上面配置的www用户组
5. 更改nginx.conf文件 /etc/local/nginx/conf/nginx.conf
将
去除 location ~ \.php${...}这段代码的注释,并将fastcgi_param里的/scripts改为$document_root
最后将location / {...}里默认index后面添加上index.php,确保index.php作为默认的首页
6. 重启 php-fpm 和 nginx
killall php-fpm
/etc/init.d/php-fpm
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx
7. 在html目录里随便创建一个php文件,内容是phpinfo();,然后在浏览器中访问该文件地址,看是否得到正确的php相关信息,如果正确显示则配置成功。
常用命令总结
[root@salve-1 conf]
Configuration File (php.ini) Path: /usr/local/php80/etc
Loaded Configuration File: /usr/local/php80/etc/php.ini
Scan for additional .ini files in: (none)
Additional .ini files parsed: (none)
[root@salve-1 conf]
extension=swoole.so
[root@salve-1 conf]
iles parsed: (none)
查看对应php.ini是否有extension=swoole
[root@salve-1 conf]# cat /usr/local/php80/etc/php.ini | grep swoole extension=swoole.so
关闭php-fpm
[root@salve-1 conf]# killall php-fpm
|