參考:https://blog.csdn.net/Phplayers/article/details/100901352
php5.6安裝參考:https://www.cnblogs.com/EasonJim/p/9614577.html
注意:記得去掉--enablerepo=remi,直接使用--enablerepo=remi-php56
一、yum 安裝 PHP7.3
1、首先安裝 EPEL 源:
yum install epel-release -y
# Extra Packages for Enterprise Linux 。EPEL是一個比官方rpm包更豐富、版本相對更高的額外第三方源。
2、安裝 REMI 源:
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
# 除了EPEL源之外還有REMI的源。它包含最新版本 PHP 和 MySQL 包
3、安裝 Yum 源管理工具:
yum install yum-utils -y
# 維護YUM並提高其性能的工具
4、安裝php73:
yum --enablerepo=remi-php73 install php -y # yum --enablerepo=remi-php73 install php73 -y
# yum --enablerepo=[repo] 啟用一個或多個軟件源(支持通配符)
5、安裝常用擴展:
yum --enablerepo=remi-php73 install php-gmp php-zip php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt php-devel php-mysql php-gd php-bcmath php-pdo php-pecl-imagick php-fpm php-curl php-devel php-pear -y
# 卸載命令:yum --enablerepo=remi-php73 remove xxx xxx ..
安裝mongodb擴展:
yum --enablerepo=remi-php73 install php-devel php-pear -y pecl install mongodb
6、開啟php:
systemctl start php-fpm
7、加入開機自啟動
systemctl enable php-fpm
8、查看php版本:
php -v
二、編譯安裝 swoole 擴展
1、下載:
去https://pecl.php.net/package/swoole下載最新的swoole包。
wget -c https://pecl.php.net/get/swoole-4.4.15.tgz
# git下載地址:https://github.com/swoole/swoole-src
git clone https://github.com/swoole/swoole-src.git
2、解壓到指定目錄:
tar xf swoole-4.4.15.tgz
3、進入該目錄:
cd swoole-4.4.15
4、使用 phpize 生成 configure
/usr/bin/phpize
# phpize 可以直接擴展 php 模塊,無需重新編譯php
5、編譯配置
./configure --enable-openssl --with-php-config=/usr/bin/php-config
# ./configure 后面可以指定的是 php-config 文件的路徑,不知道路徑可以 find 出來
6、編譯 && 安裝:
make && make install
7、編譯安裝成功后,修改php.ini
加入:
# vim /etc/php.ini extension=swoole.so
8、記得重啟php-fmp:
systemctl restart php-fpm
9、查看是否啟用安裝成功:
php --ri swoole
# 注意是否支持ssl
三、安裝composer
1、下載安裝
php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" php composer-setup.php
如果上述方式下載不行,可以嘗試下面這種方式:
curl -sS https://getcomposer.org/installer | php
2、移動 composer.phar,這樣 composer 就可以進行全局調用:
mv composer.phar /usr/local/bin/composer
3、切換為國內鏡像:
# composer config -g repo.packagist composer https://packagist.phpcomposer.com # 可以切換的鏡像源 composer repo:ls -- --------------- ------------------------------------------------ composer https://packagist.org phpcomposer https://packagist.phpcomposer.com aliyun https://mirrors.aliyun.com/composer tencent https://mirrors.cloud.tencent.com/composer huawei https://mirrors.huaweicloud.com/repository/php laravel-china https://packagist.laravel-china.org cnpkg https://php.cnpkg.org sjtug https://packagist.mirrors.sjtug.sjtu.edu.cn -- --------------- ------------------------------------------------
4、composer自我更新
composer selfupdate
四、Dockerfile
1、dockerfile-php-fpm-init
# This is my first easyswoole init Dockerfile # Version 1.0 FROM centos:7 MAINTAINER doublexi "shuangxi.wang@lgitt.com" # 定義swoole版本 ENV SWOOLE_VERSION 4.4.15 RUN yum install epel-release -y \ && useradd www -M -s /sbin/nologin \ && yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y \ && yum install yum-utils -y \ && yum --enablerepo=remi-php73 install php -y \ && yum --enablerepo=remi-php73 install php-gmp php-zip php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt php-devel php-mysql php-gd php-bcmath php-pdo php-pecl-imagick php-fpm -y \ && yum clean all \ && yum install make -y \ && curl -fSL https://pecl.php.net/get/swoole-${SWOOLE_VERSION}.tgz -o /opt/swoole-${SWOOLE_VERSION}.tgz \ && tar xf /opt/swoole-${SWOOLE_VERSION}.tgz -C /opt/ \ && cd /opt/swoole-${SWOOLE_VERSION} \ && /usr/bin/phpize \ && ./configure --enable-openssl --with-php-config=/usr/bin/php-config \ && make && make install \ && make clean \ && php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" \ && php composer-setup.php \ && mv composer.phar /usr/local/bin/composer \ && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer \ && cd /opt && rm -rf swoole-${SWOOLE_VERSION}* \ && echo "set encoding=utf-8" >>/root/.vimrc COPY php.ini /etc/php.ini COPY php-fpm.conf /etc/php-fpm.conf COPY www.conf /etc/php-fpm.d/www.conf COPY localtime /etc/localtime EXPOSE 9000 CMD ["/usr/sbin/php-fpm", "--nodaemonize"]
2、dockerfile-easyswoole-init
# This is my first easyswoole init Dockerfile # Version 1.0 FROM centos:7 MAINTAINER doublexi "shuangxi.wang@lgitt.com" # 定義swoole版本 ENV SWOOLE_VERSION 4.4.15 RUN yum install epel-release -y \ && useradd www -M -s /sbin/nologin \ && yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y \ && yum install yum-utils -y \ && yum --enablerepo=remi-php73 install php -y \ && yum --enablerepo=remi-php73 install php-gmp php-zip php-xml php-soap php-xmlrpc php-mbstring php-json php-gd php-mcrypt php-devel php-mysql php-gd php-bcmath php-pdo php-pecl-imagick php-fpm -y \ && yum clean all \ && yum install make -y \ && curl -fSL https://pecl.php.net/get/swoole-${SWOOLE_VERSION}.tgz -o /opt/swoole-${SWOOLE_VERSION}.tgz \ && tar xf /opt/swoole-${SWOOLE_VERSION}.tgz -C /opt/ \ && cd /opt/swoole-${SWOOLE_VERSION} \ && /usr/bin/phpize \ && ./configure --enable-openssl --with-php-config=/usr/bin/php-config \ && make && make install \ && make clean \ && php -r "copy('https://install.phpcomposer.com/installer', 'composer-setup.php');" \ && php composer-setup.php \ && mv composer.phar /usr/local/bin/composer \ && composer config -g repo.packagist composer https://mirrors.aliyun.com/composer \ && cd /opt && rm -rf swoole-${SWOOLE_VERSION}* \ && echo "set encoding=utf-8" >>/root/.vimrc COPY php.ini /etc/php.ini COPY php-fpm.conf /etc/php-fpm.conf COPY www.conf /etc/php-fpm.d/www.conf COPY localtime /etc/localtime RUN mkdir /opt/easyswoole \ && cd /opt/easyswoole \ && composer require easyswoole/easyswoole=3.x \ && php vendor/easyswoole/easyswoole/bin/easyswoole install \ && chown -R www.www ./ WORKDIR /opt/easyswoole EXPOSE 9501 CMD ["php", "easyswoole", "start"]