Home>Article>Backend Development> EpiiServer simple php+nginx environment customization solution
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.
A faster and more convenient php nginx multi-application deployment environment.
https://github.com/epaii/epii-server
https://gitee.com/ epii/epii-server
Let’s not talk about how to install it. Let’s first see if you need this application.
Perhaps you will say that you can just usehttp://localhost/app1
andhttp://localhost/app2
to access the two websites. .
Yes indeed. But what if each sets its own domain name? For example,http://app1.loc.com
andhttp://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
andpublic.app4.loc.com
,dir3.dir2.app5.loc.com
point to your ip
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.What is the domain nameloc.com
above?
He is the root domain name of all yourapp
. Any app converts the sub-pair into the domain name{appname}.loc.com
, and the directory access is automaticallydir3.dir2.dir1.{appname}.loc.com
.
If you want to set your own root domain name, just copyconfig.ini.example
toconfig.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
Any
app. Domain names in other formats are not supported.
If an app has another domain name such asQuestion 2
Just set[server] www_dir=/path/to/your/www
[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.
is placed in another directory
"c:\workplace\app6", I only need to set it inconfig.ini
[app_dir]
Set the[app_dir] app6=c:\workplace\app6 app7=/path/to/app7
directory to an absolute path and does not contain Chinese.
In this case the domain nameapp7.loc.comapp6.loc.com
,
will point to the path you set. It also supports converting subdirectories into domain names.For example, if the entry file of
app6is
c:\workplace\app6\public\index.php
, then access
In fact, the above settings are unscientific. It is better to directly point the directory of app6 tohttp://public.app6.loc.com
public
[app_dir] app6=c:\workplace\app6\public
In this way, your domain name will be simplified toapp6.loc.com
Tips
Question 4在上面web下app5中,为了访问入口文件 我们需要 访问 `http://dir3.dir2.app5.loc.com` 这个域名才可以,如果想简化为 `http://app5.loc.com`, 只需把 dir3的绝对路径设置为`app5`的路径即可。app5=/path/to/app5/dir2/dir3
http://127.0.0.1/app1 http://127.0.0.1/app2/dir1/dir2/index.php
Can I specify an
appby default when I access the IP address? For example, to access
app1directly by accessing IP,just need to set it under
[server]in
config.ini
After setting , when accessing[server] default_app=app1
http://127.0.0.1/
, it will be pointed directly to
.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
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.
2. Multiple PHP versions can coexist.
例如
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版本
大家肯定会遇到这些问题
git
作为团队合作方式。如何让重要的账号和密码不受版本控制。上述问题,有很多解决方案,但更方便更科学的方式为通过环境变量
设置账号和密码,使得程序和重要账号完全分离
。
在不同的环境下(window,linux,iis,apache,nginx)设置php环境变量
的方式不一样,
但
这样使得我们的应用程序代码无需任何修改,只需在环境中设置了环境变量即可。
php中通过 $_EVN,或者 getenv() 来获取指定的环境变量值。
现有的方式设置的环境变量,往往是针对所有app都生效的。这意味着如果我有多个项目,每一个项目都是共享这些环境变量,这样的结果为:
app11
,app12
的数据库名称,我们必须设置两个环境变量,如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
仓库首页
https://gitee.com/epii/epii-server
https://github.com/epaii/epii-server
下载或clone到本地后,
1、请复制config.ini.example
为config.ini
,按照配置文件的提示配置自己的项目。
2、请运行项目下install/install.php
文件进行安装
path/to/php ./install/install.php
安装只需一次,安装后,会自动生成启动,停止运行文件。
window自动生成的文件为:
linux unix 自动生成的文件为:
配置文件修改后记得 先关闭服务,再启动。
[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!