linux centos 下docker php7.3環境安裝配置(yum 源安裝php7.3),以及redis,swoole,ssh2,amqp等擴展安裝

一、安裝centos容器


1、下載centos鏡像

docker pull centos

2、啓動容器(linux中代碼存放路徑:/www     docker容器中代碼存放的路徑 /home)

docker run --restart=always -p 86:86 -d -e "container=docker" --privileged=true -v /sys/fs/cgroup:/sys/fs/cgroup -v /www/website:/home/www --name centos centos /usr/sbin/init

3、進入容器 (容器名稱centos)

docker exec -it centos /bin/bash

如果服務器試代理上網的,需要執行如下代碼,纔可以正常下載。

export http_proxy=http://自己的代理上網地址 && export https_proxy=http://自己的代理上網地址

二、NGINX 安裝(配置文件/etc/nginx)


1、添加nginx的源

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2、安裝nginx

yum install -y nginx

3、啓動

#開機自動啓動nginx服務
systemctl enable nginx
#啓動nginx服務
systemctl start nginx

如果提示:Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /usr/lib/systemd/system/nginx.service.

意思是:會在/etc/systemd/system/multi-user.target.wants/目錄下生成nginx.service的軟鏈接這樣就可以再次執行

systemctl enable nginx.service。

其他命令

# 啓動nginx服務
systemctl start nginx

# 重啓nginx服務
systemctl restart nginx

# 停止nginx服務
systemctl stop nginx

# 查看nginx服務
systemctl status nginx

# 開機自動啓動nginx服務
systemctl enable nginx

# 禁止開機啓動nginx服務
systemctl disable nginx

# 查詢是否開機啓動redis服務
systemctl is-enable nginx

# 重新加載nginx服務,修改配置文件後使用這個
systemctl reload nginx  

4、配置文件:
以下是Nginx的默認路徑:
(1) Nginx配置路徑:/etc/nginx/
(2) PID目錄:/var/run/nginx.pid
(3) 錯誤日誌:/var/log/nginx/error.log
(4) 訪問日誌:/var/log/nginx/access.log
(5) 默認站點目錄:/usr/share/nginx/html

5、修改配置文件(修改配置文件後需要重啓:systemctl restart nginx)

server {
    listen       86;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /home/www;
        # 修改1:這裏新增了index.php
        index index.php index.html index.htm;
        # 修改2:這裏新增url重寫(path)
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ \.php$ {
        root         /home/www;
        #默認就使用php-fpm
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        #修改4:修改fastcig的路徑
        fastcgi_param  SCRIPT_FILENAME  /home/www$fastcgi_script_name;
        include        fastcgi_params;
    }
}

三、yum安裝php7.3

1、安裝EPEL:

yum install epel-release

2、安裝remi:

rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

3、安裝PHP 7.3 

yum --enablerepo=remi-php73 install php

4、查找擴展包(獲取自己需要的擴展信息)

yum --enablerepo=remi-php73 search php | grep php73

執行後出現如下信息:

[root@ff5c6fb00c84 /]# yum --enablerepo=remi-php73 search php | grep php73
 * remi-php73: mirror.23media.com
php73.x86_64 : Package that installs PHP 7.3
php73-php.x86_64 : PHP scripting language for creating dynamic web sites
php73-php-bcmath.x86_64 : A module for PHP applications for using the bcmath
php73-php-brotli.x86_64 : Brotli Extension for PHP
php73-php-cli.x86_64 : Command-line interface for PHP
php73-php-common.x86_64 : Common files for PHP
php73-php-componere.x86_64 : Composing PHP classes at runtime
php73-php-dba.x86_64 : A database abstraction layer module for PHP applications
php73-php-dbg.x86_64 : The interactive PHP debugger
php73-php-devel.x86_64 : Files needed for building PHP extensions
php73-php-embedded.x86_64 : PHP library for embedding in applications
php73-php-enchant.x86_64 : Enchant spelling extension for PHP applications
php73-php-fpm.x86_64 : PHP FastCGI Process Manager
php73-php-gd.x86_64 : A module for PHP applications for using the gd graphics
php73-php-geos.x86_64 : PHP module for GEOS
php73-php-gmp.x86_64 : A module for PHP applications for using the GNU MP
php73-php-imap.x86_64 : A module for PHP applications that use IMAP
php73-php-interbase.x86_64 : A module for PHP applications that use
php73-php-intl.x86_64 : Internationalization extension for PHP applications
php73-php-json.x86_64 : JavaScript Object Notation extension for PHP
。
。
。

5、安裝php擴展(從上步驟中獲取可安裝的擴展名稱,例:php73-php-gd.x86_64,最終:yum --enablerepo=remi-php73 install -y php-gd)

yum --enablerepo=remi-php73 install -y php-pecl-swoole4 php-pecl-amqp php-pecl-ssh2 php-fpm php-cli php-bcmath php-gd php-json php-mbstring php-mcrypt php-mysqlnd php-opcache php-pdo php-pecl-crypto php-pecl-mcrypt php-pecl-geoip php-recode php-snmp php-soap php-xml php-xmlrpc php-pecl-redis5

6、查看php已安裝的擴展

php -m

執行後出現如下信息(還是以gd爲例,在列表中發現有gd,說明擴展已成功安裝):

[root@ff5c6fb00c84 /]# php -m
[PHP Modules]
amqp
bcmath
bz2
calendar
Core
crypto
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
geoip
gettext
。
。
。

7、添加開機啓動

systemctl enable php-fpm

8、 禁止開機啓動redis服務

systemctl disable php-fpm

9、其他命令 

systemctl start php-fpm    #啓動
systemctl stop php-fpm     #停止
systemctl restart php-fpm  #重啓

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章