了解PHP库安装 [英] Understanding PHP library installation

查看:51
本文介绍了了解PHP库安装的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解与在系统(Linux/OSX)上安装" PHP库有关的选项和术语

I'm trying to understand the options and terminology relating to "installing" PHP libraries on a system (Linux/OSX)

以下是我要介绍的一些具体要点:

Here are some specific points I'm trying to cover:

  1. 与PHP库相关时,安装"是什么意思?
  2. 库和扩展之间有什么区别?
  3. php.ini如何适合?
  4. 梨如何搭配?
  5. 如何导入/包含库?
  6. 如果我创建自己的库,打包和分发它的最佳方法是什么?

谢谢,很抱歉!

推荐答案

几点...

PHP没有本地的导入"基础结构,例如python,java或.net.在PHP中可以使用库的几种方式.

PHP has no native "import" infrastructure, like python, java, or .net. There are several ways that libraries can be used in PHP.

  1. 将它们编译为PHP二进制文件.这是最先进的方法,除非您有非常特殊的需求,否则通常不希望这样做.

  1. compile them into the PHP binary. This is the most advanced way, and not usually desirable unless you have very special needs.

将它们作为PHP模块安装在服务器上,并将其包含在PHP.ini中.从PHP程序员的角度来看,这些扩展是PHP的一部分-始终可用.添加和删​​除它们变得更加容易,而无需重新构建PHP本身.

Install them as PHP modules on the server, and include them in PHP.ini. From the point of view of the PHP programmer, these extensions are part of PHP -- always available. It's just easier to add and remove them without having to rebuild PHP itself.

在服务器上的某处安装PHP代码,并将include()包含在您的PHP脚本中.

Install PHP code on the server somewhere, and include() it into your PHP script.

将库的副本保存到您的项目中,并将其包含到您的PHP脚本中.

Save a copy of a library into your project, and include it into your PHP script.

-
从根本上讲,代码是解释器的一部分(静态或动态),或者是包含在项目中的include()的纯老式PHP代码.

--
At a basic level, code is either part of the interpreter (static or dynamic), or it is plain old PHP code that is include()ed into your project.

出于您的目的,我只能建议您坚持使用行业标准的PHP发行版(选择一个好的Linux操作系统,并使用它的PHP).然后,几乎所有您需要在解释器级别使用的库都可以作为附加程序包使用,而这些程序的复杂性则由每天执行此操作的人来决定.

For your purposes, I can only suggest that you stick with an industry standard PHP distribution (pick a good linux OS, and use it's PHP). Then almost all the libraries you will need at the interpreter level are available as add-on packages, and the complexity of that is left up to those who do it every day.

在RedHat/Centos上,您可以运行:

On RedHat/Centos, you might run:

yum install php php-memcached php-gd php-pecl

-
关于您可能要使用的所有其他类型的库,最有可能最好采用一个良好的PHP框架,该框架可以为您解决所有这些问题.

--
Regarding all the other kinds of libraries that you might want to use, it's most likely best to adopt a good PHP framework which takes care of all that for you.

一些例子是:

  1. Zend框架
  2. CakePHP
  3. Codeigniter
  4. http://www.phpframeworks.com/
  5. 等等...

(不以任何顺序排列,只是浮现在脑海中)

(not in any order, just ones that came to mind)

只要您已采用使用RPM或类似方法来管理PHP和扩展方面的编译方式的标准方法,那么一个好的可靠框架将负责处理您所需的所有其他PHP库代码.

Provided that you have taken the standard approach of using RPM's or similar to manage the compiled in aspects of PHP and extensions, then a good solid framework will take care of the inclusion of all your additional PHP library code you need.

最终结果是,您专注于交付产品,而不是所有您必须学习和发明的基础架构.

What the end result is, is that you focus on delivering a product, and not on all the infrastructure that you would otherwise have to learn and invent.

-
php.ini 被解析并在PHP启动时运行(每次用于命令行,每个服务器在apache中启动一次).它定义了很多设置,包括很多模块,配置这些模块,等等...

--
php.ini is parsed and run when PHP starts (each time for command line, once per server start in apache). It defines a lot of settings, includes a lot of modules, configures those modules, etc...

实际上,您可以使用PHP中的ini_set()函数覆盖php.ini中的某些设置.但是,这仅对某些设置有效.在脚本启动之前,需要设置其他设置.

You can actually override some settings in php.ini with the ini_set() function in PHP. However, this is only effective for some settings. Others need to be set before your script starts.

在apache下运行时,您可以向 .htaccess < VirtualHost> 指令添加行,这些指令完全覆盖该目录/虚拟主机的PHP.ini.

When running under apache, you can add lines to .htaccess and <VirtualHost> directives which totally override PHP.ini for that directory/virtual host.

(请更正我的语法,如果不正确,请删除此注释)

(please correct my syntax and remove this note if it is wrong)

<VirtualHost *>
    ServerName www.example.com       
    DocumentRoot /home/joe/site/docroot
    php_value include_path "/home/joe/site/php-code"
</VirtualHost>

-
为了回答您关于自己的库以及打包它的最佳方法的#6问题,建议您首先评估该库的需求.而且,如果您确实在做某事,那么请找出人们最常用的方式.如果它是一个简单的库,那么具有一个不错的网站的.php文件就足够了.

--
In response to your #6 question about your own library and the best way to package it, I suggest you first evaluate the need of the library. And if you really are on to something, then find out the most common way people are doing it. If it is a simple library, then a .php file with a nice website would be sufficient.

-
也许有点杂乱无章,但我希望这能为您指明正确的方向.

--
Maybe a bit rambling, but I hope this points you in the right direction.

这篇关于了解PHP库安装的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆