Home  >  Article  >  Backend Development  >  EpiiServer simple php+nginx environment customization solution

EpiiServer simple php+nginx environment customization solution

little bottle
little bottleforward
2019-04-26 14:40:291972browse

This article will introduce you to a software called EpiiServer. It can deploy environments for php nginx multiple applications faster and more conveniently. It is very suitable for developers. Interested friends can learn about it.

What is EpiiServer

A faster and more convenient php nginx multi-application deployment environment.

github warehouse homepage

https://github.com/epaii/epii-server

gitee warehouse

https://gitee.com/ epii/epii-server

Features:

  1. Rapid deployment of multiple applications, automatic generation of domain names.
  2. Each application can set its own version of php.
  3. Each application can set its own environment variables.
  4. Domain names and directories are automatically bound, and 5-level domain names are supported to be automatically bound to directories.
  5. Compared with integrated environments such as wamp, it focuses more on customized configuration rather than environment installation.

What problem was solved?

Let’s not talk about how to install it. Let’s first see if you need this application.

1. Multiple local websites, domain names are automatically generated.


Perhaps you will say that you can just use http://localhost/app1 and http://localhost/app2 to access the two websites. .
Yes indeed. But what if each sets its own domain name? For example, http://app1.loc.com and http://app2.loc.com. If you have this idea, this software can easily help you realize it.

The following directory

web -- App集合目录
    app3
        index.php --入口文件
    app4
        application
        public
            index.php --入口文件
    app5
        dir1
        dir2
            dir3
                index.php --入口文件

The domain name is automatically

http://app3.loc.com
http://public.app4.loc.com
http://dir3.dir2.app5.loc.com

What you need to do (the only thing to do) is just to let app3 in the host file .loc.com and public.app4.loc.com, dir3.dir2.app5.loc.com point to your ip

The web directory under the root directory of EpiiServer is the project collection directory of the app. As long as you put your app into this directory, the above domain name will be automatically generated.

Question 1

What is the domain name loc.com above?
He is the root domain name of all your app. Any app converts the sub-pair into the domain name {appname}.loc.com, and the directory access is automatically dir3.dir2.dir1.{appname}.loc.com.

If you want to set your own root domain name, just copy config.ini.example to config.ini## after downloading. #) Set

[server]
domain_this=you.domain.com
under [server]. If you use a dns server to implement pan-resolution of domain names, you will not need to set it in the

hosts
    file. Set domain name pointing.
  • Any app
  • is a multi-level domain name generated based on the
  • root domain name. Domain names in other formats are not supported. If an app has another domain name such as
  • www.web.com
  • , then you can use cname at the dns service provider to resolve to the local domain name of the app.

    Question 2

    Maybe you will ask, my projects are all in another directory, do they have to be copied to the
  • web# in the root directory of EpiiServer? ## Only in the directory? of course not.

Just set <pre class="brush:php;toolbar:false;">[server] www_dir=/path/to/your/www</pre>

www_dir to the absolute path under

[server] in config.ini, and must not contain Chinese

Question 3

I have set up my app collection directory according to the above method, but there are still some apps (or many) distributed in other directories. Do I need to copy them to the app collection directory? ? of course not.

For example, if my

app6

is placed in another directory

"c:\workplace\app6"

, I only need to set it in config.ini [app_dir] Set the <pre class="brush:php;toolbar:false;">[app_dir] app6=c:\workplace\app6 app7=/path/to/app7</pre> directory to an absolute path and does not contain Chinese.

In this case the domain name

app6.loc.com

,
app7.loc.com

will point to the path you set. It also supports converting subdirectories into domain names. For example, if the entry file of app6 is c:\workplace\app6\public\index.php
, then access <pre class="brush:php;toolbar:false;">http://public.app6.loc.com</pre>In fact, the above settings are unscientific. It is better to directly point the directory of app6 to public

[app_dir]
app6=c:\workplace\app6\public

In this way, your domain name will be simplified to app6.loc.com

Tips<pre class="php">在上面web下app5中,为了访问入口文件 我们需要 访问 `http://dir3.dir2.app5.loc.com` 这个域名才可以,如果想简化为 `http://app5.loc.com`, 只需把 dir3的绝对路径设置为`app5`的路径即可。app5=/path/to/app5/dir2/dir3</pre>Question 4

What will happen if you access the IP directly?

Direct access to IP is the same as other inheritance environments.

http://127.0.0.1/app1
http://127.0.0.1/app2/dir1/dir2/index.php

Can I specify an

app

by default when I access the IP address? For example, to access

app1

directly by accessing IP, just need to set it under [server] in config.ini
<pre class="brush:php;toolbar:false;">[server] default_app=app1</pre>After setting , when accessing http://127.0.0.1/, it will be pointed directly to

app1

. The role of ip access lies in others’ access to your computer. Of course, others can also bind app1.loc.com to your IP in their hosts

file, or directly access the domain name.

2. Multiple PHP versions can coexist.

I have been a PHP worker for many years, and I am facing PHP technology updates and PHP version updates. Your projects have different minimum versions of php set respectively.

例如

  • app8支持版本为php5.6
  • app9支持版本为php7.1
  • app10支持版本为php7.2

如果这些应用共存,您有什么解决方法。

解决方法很简单。首先下载多个版本的php。然后在config.ini[php]模块设置。

window 使用的是php-cgi.exe,所以只需要指定每一个php版本的php-cgi.exe路径,及端口即可。

[php]
php_cgi[0] = c:\path\to\php5.6\php-cgi.exe
port[0] = 9000

php_cgi[1] = c:\path\to\php7.1\php-cgi.exe
port[1] = 9001

php_cgi[2] = c:\path\to\php7.3\php-cgi.exe
port[2] = 9002

linux,unix下使用的是php-fpm(php-cgi,fastcgi,php-fpm的区别,大家自己查)

[php]
php_cgi[0] = /path/to/php5.6/sbin/php-fpm
port[0] = 9000

php_cgi[1] =/path/to/php7.1/sbin/php-fpm
port[1] = 9001

php_cgi[2] = /path/to/php7.2/sbin/php-fpm
port[2] = 9002

注意:php-fpm的配置文件 php-fpm.conf 里设置了端口。上面设置的端口一定要和各个版本的 php-fpm.conf中的端口一致。而php-cgi 只需设置端口即可。

通过上述设置php多版本后,默认的所有应用都设置为第一个php版本,即php_cgi[0]的设置。

为了实现

  • app8支持版本为php5.6
  • app9支持版本为php7.1
  • app10支持版本为php7.2

需在在config.ini[app_php_select]模块设置各自的php版本id

[app_php_select]
app9=1
app0=2

app8无需设置,因为所有的应用默认都使用第一个php版本

3、环境变量设置。

大家肯定会遇到这些问题

  • app的开发和部署使用的数据库参数不一样。如何有效分离。
  • 很多人在使用git作为团队合作方式。如何让重要的账号和密码不受版本控制。

上述问题,有很多解决方案,但更方便更科学的方式为通过环境变量设置账号和密码,使得程序和重要账号完全分离

在不同的环境下(window,linux,iis,apache,nginx)设置php环境变量的方式不一样,

在php获取环境变量的方式是一样的

这样使得我们的应用程序代码无需任何修改,只需在环境中设置了环境变量即可。

php中通过 $_EVN,或者 getenv() 来获取指定的环境变量值。

现有的方式设置的环境变量,往往是针对所有app都生效的。这意味着如果我有多个项目,每一个项目都是共享这些环境变量,这样的结果为:

  • 不方便。app11app12 的数据库名称,我们必须设置两个环境变量,如 DBNAMA_APP11, DBNAMA_APP12。然后分别获取。
  • 不安全。在app11中仍然可以获取到app12 的环境变量。

使用 EpiiServer 这些问题将变得很容易解决。

我们的需求是:

1、app11 需要把数据库信息设置为环境变量 分别为

DB_HOST=192.168.1.100
DB_NAME=ceshi
DB_USER=username
DB_PWD=password

2、app12 需要把数据库信息设置为环境变量 分别为

DB_HOST=192.168.1.102
DB_NAME=ceshi2
DB_USER=username2
DB_PWD=password2

我们只需在config.ini[php_env]模块设置各自的环境变量

[php_env]
app11[DB_HOST] = 192.168.1.100
app11[DB_NAME] = ceshi
app11[DB_USER] = username
app11[DB_PWD] = password

app12[DB_HOST] = 192.168.1.102
app12[DB_NAME] = ceshi2
app12[DB_USER] = username2
app12[DB_PWD] = password2

在程序中使用 $_ENV['DB_HOST'] 即可获取到相应的 DB_HOST

阿里云和微软云等云平台都有设置环境变量的方法。

如何安装

EpiiServer 侧重的是nginx php 安装后的灵活配置,而非 nginx php本身的安装。

所以在安装EpiiServer之前你需要(必须)

1、根据自己的系统下载nginx,并且明白安装路径及配置文件路径。

2、根据自己的需要下载安装php,可下载多个版本。

3、window 用户须知道安装的各个php版本路径及php-cgi的位置,并且每个版本可以成功运行

/path/to/php-cgi.exe -b 127.0.0.1:9000

4、linux,unix 用户须知道安装的各个php版本路径及php-fpm的位置和php-fpm.conf的路径,分别修改php-fpm.conf文件 ,并成功运行

/path/to/php-fpm

EpiiServer 仓库首页

gitee仓库

https://gitee.com/epii/epii-server

github仓库首页

https://github.com/epaii/epii-server

下载或clone到本地后,

1、请复制config.ini.exampleconfig.ini,按照配置文件的提示配置自己的项目。

2、请运行项目下install/install.php 文件进行安装

path/to/php ./install/install.php

安装只需一次,安装后,会自动生成启动,停止运行文件。

window自动生成的文件为:

  • start.bat 启动服务
  • stop.bat 停止服务

linux unix 自动生成的文件为:

  • start.sh 启动服务
  • stop.sh 停止服务

配置文件修改后记得 先关闭服务,再启动。

配置文件

[server]
;本机ip地址和端口
this_ip = 192.169.0.169
this_port = 6688
;本机域名前缀
domain_this = this.jt
;web项目路径,此路径下每一个文件夹会当做一个应用,如果某一个项目不想放在此目录下,可以再app_dir中单独设置

;www_dir 为网站根目录,默认为web目录,如果设置请设置绝对路径
;www_dir = /Users/mrren/Documents/phpworkspace/EpiiWeb/web

;default_app = web1
;本程序以php为脚本安装和启动服务,指定php命令地址,一般为php.exe的文件路径
php_cmd=php

[nginx]
;nginx 文件地址; linux or unix 请指定nginx文件地址即可
cmd = /usr/local/Cellar/nginx/1.15.0/bin/nginx
nginx_config_file = /usr/local/etc/nginx/nginx.conf
[php]
;window下 php-cgi.exe 的路径,linux 下 php-fpm 路径
php_cgi[0] = /usr/local/Cellar/php\@7.1/7.1.19/sbin/php-fpm
;如果使用php-cgi,设置的端口将被启用。如果是php-fpm 请确保此端口和php-fpm.conf中一致(php-fpm.conf 需手动修改,多个php版本一定要设置不同的端口)
port[0] = 9000
php_cgi[1] = php-fpm
port[1] = 9001
[app_dir]
;如果你的应用不在www_dir下,请指定项目路径(必须为绝对路径)
;app1 = /Users/mrren/Documents/phpworkspace/jianguan
;epiiadmin=/Users/mrren/Documents/phpworkspace/EpiiWeb/web/epiiadmin/public


[app_php_select]
;默认所有的php版本自动为php_cgi[0] 的版本,如果有特殊需求请在这里设置
epiiadmin = 1

[php_env]
epiiadmin[db_hostname] = zhengxin

大部分参数在上述教程已经涉及到。重点介绍

[server] 下的 php_cmd

[server]
php_cmd=php

EpiiServer本身是基于php的(并非你的网站),如果你的php在环境变量PATH下,则直接为默认配置即可。 如果不是。linux,unix 用户 为path/to/php,window用户为paht/to/php.exe

最后希望EpiiServer能给您带来帮助。让您更多的时间去研发产品,而非环境搭建。

相关教程:PHP视频教程

The above is the detailed content of EpiiServer simple php+nginx environment customization solution. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete