Deploying PHP applications in the Kubernetes cluster

Source: Internet
Author: User
Tags fpm install php php and mysql

This article describes the deployment of a PHP application system in the kubernetes environment. The front-end Web uses nginx, middleware PHP to run in fastcgi way, the background database is supported by MySQL master and slave.
Calls between service components take the form of DNS resolution service names, and data and configuration files are persisted using PV and PVC (based on NFS).

First, create a PHP image file via Dockerfile

# cat dockerfile FROM docker.io/openshift/base-centos7:latestMAINTAINER ylw "[email protected]"RUN yum makecacheRUN yum -y install php-fpm php php-gd php-mysql php-mbstring php-xml php-mcrypt  php-imap php-odbc php-pear php-xmlrpc  RUN sed -i ‘s/listen = 127.0.0.1:9000/listen = 0.0.0.0:9000/‘ /etc/php-fpm.d/www.confRUN sed -i ‘s/listen.allowed_clients = 127.0.0.1/;listen.allowed_clients = 127.0.0.1/‘ /etc/php-fpm.d/www.confEXPOSE 9000CMD ["/sbin/php-fpm"]# docker build -t registry.fjhb.cn/php:0.1 .# docker push registry.fjhb.cn/php:0.1


Ii. creating Replicationcontroller and service through YAML files

# cat php-rc.yaml apiVersion: v1kind: ReplicationControllermetadata:  name: php-server  labels:    name: php-serverspec:  replicas: 2  selector:    name: php-server  template:    metadata:      labels:        name: php-server    spec:      containers:      - name: php-server        image: registry.fjhb.cn/php:0.1        volumeMounts:        - mountPath: /usr/share/nginx/html          name: nginx-data        ports:        - containerPort: 9000      volumes:      - name: nginx-data        persistentVolumeClaim:         claimName: nfs-data# cat php-svc.yaml   apiVersion: v1kind: Servicemetadata:  name: php-server   labels:    name: php-serverspec:  ports:  - port: 9000    protocol: TCP    targetPort: 9000  


Third, modify Nginx configuration support PHP

# cat /home/nginx/conf.d/test.conf server {        listen       80;        server_name  test.fjhb.cn;        access_log  /etc/nginx/test.fjhb.cn.accesslog  main;        location / {            root    /usr/share/nginx/html;            index   index.html index.htm;        }   location ~ \.php$ {            root  /usr/share/nginx/html;            fastcgi_pass   php-server:9000;            fastcgi_index  index.php;            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;            include        fastcgi_params;}        location ~ /\.ht {            deny  all;        }}


Web Access phpinfo page test



Iv. Download Discuz application deployment, test PHP and MySQL master-slave connectivity
: http://www.discuz.net/thread-3796882-1-1.html

# mkdir /home/bbs# cd /home/bbs# unzip Discuz_X3.3_SC_UTF8.zip # mv upload/* ./

Deploy by visiting a webpage








Deploying PHP applications in the Kubernetes cluster

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.