安装PHP
安装依赖
yum -y install gcc openssl openssl-devel curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel pcre pcre-devel libxslt libxslt-devel bzip2 bzip2-devel
安装PHP
下载php软件包并解压
wget -c http://120.53.7.204:90/php-7.2.27.tar.gz
tar -zxvf php-7.2.2.tar.gz
配置php
cd php-7.2.2
./configure --prefix=/usr/local/php --with-curl=/usr/local/curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-mysqli --with-openssl --with-pcre-regex --with-pdo-mysql --with-pdo-sqlite --with-pear --with-png-dir --with-xmlrpc --with-xsl --with-zlib --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-mbstring --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip
编译安装
make && make install
启动php
/usr/local/php/sbin/php-fpm
配置php相关文件
软连接
ln -s /usr/local/php/sbin/php-fpm /usr/local/bin/php-fpm
php相关查看(模块、版本)
/usr/local/php/bin/php -m
/usr/local/php/bin/php -v
配置php相关文件–php默认不创建配置文件,需要手动创建
cp 你的php安装包里面去找/php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
修改配置文件
vim /usr/local/php/lib/php.ini
cgi.fix_pathinfo=1
vim /usr/local/php/etc/php-fpm.conf
pid = /var/run/php-fpm.pid
启动php
/usr/local/php/sbin/php-fpm
设置php的systemctl功能
新建 php-fpm 服务文件
vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=forking
PIDFile=/var/run/php-fpm.pid
ExecStart=/usr/local/php/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
重新加载systemctll配置
systemctl daemon-reload #重新加载配置文件
systemctl enable php-fpm.service #设置开启自启
干掉启动的php-fpm
pkill -9 php-fpm
systemctl status php-fpm
systemctl start php-fpm
管理php相关的命令
systemctl start php-fpm
systemctl status php-fpm
systemctl stop php-fpm
systemctl restart php-fpm
systemctl reload php-fpm
systemctl enable php-fpm
systemctl didable php-fpm
修改Nginx.conf文件
vim /usr/local/nginx/conf/nginx.conf
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
在网站跟目录添加test.php
vim /usr/local/nginx.html/test.php
<?php phpinfo(); ?>
重启nginx
systemctl restart nginx
测试
打开浏览器输入http://ip/test.php
PHP添加模块 Swoole (说明:安装其他模块步骤相似)
下载Swoole
git clone https://gitee.com/swoole/swoole.git
cd swoole.git
测试php版本和模块的版本是否一致,一致则才能生成configure文件,才能/configure
/usr/local/php/bin/phpize
告知php-config命令添加的模块
./configure --with-php-config=/usr/local/php/bin/php-config
编译安装
make && make install
在php.ini中添加 extension=swoole
vim /usr/local/php/lib/php.ini
extension=swoole
重启php
systemctl restart php-fpm
查看模块是否添加成功
php -m