A couple points...

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

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

  2. 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.

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

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

--
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.

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.

On RedHat/Centos, you might run:

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

--
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.

Some examples are:

  1. Zend Framework
  2. CakePHP
  3. Codeigniter
  4. http://www.phpframeworks.com/
  5. Etc...

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

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 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...

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.

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>

--
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.

Answer from gahooa on Stack Overflow
🌐
PHP Download
php-download.com
Download and install PHP libraries online without composer
On this page it is possible to download all PHP libraries, which are found in the Packagist Repository. If you use this site, no Composer installation is required. You can download the PHP packages directly without installing anything.
Register
No commands - only one simple click to download your library. ... Before you can download the PHP files, the dependencies should be resolved. This can take some minutes.
Popular PHP libraries
A List of some PHP libraries which are downloaded on my site. The entries are containing βœ“ Source code βœ“ All dependencies
Popular PHP frameworks
Download PHP libraries without composer!
Composer Build Server
Download PHP libraries without composer!
🌐
Packagist
packagist.org
Packagist.org
Or download composer.phar into your project root. See the Composer documentation for complete installation instructions on various platforms. Execute this in your project root. php composer.phar install Β· If your packages specify autoloading information, you can autoload all the dependencies by adding this to your code: require 'vendor/autoload.php'; Browse the packages we have to find more great libraries you can use in your project.
🌐
PHP
pecl.php.net
PECL :: The PHP Extension Community Library
Search for in the Packages This site (using Google) Developers Developer mailing list SVN commits mailing list Β· PECL is now deprecated. πŸ₯§ PHP Installer for Extensions (PIE) is the replacement for PECL. We recommend publishing your extension using PIE instead
Top answer
1 of 2
16

A couple points...

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

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

  2. 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.

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

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

--
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.

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.

On RedHat/Centos, you might run:

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

--
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.

Some examples are:

  1. Zend Framework
  2. CakePHP
  3. Codeigniter
  4. http://www.phpframeworks.com/
  5. Etc...

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

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 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...

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.

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>

--
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.

2 of 2
4

All directly related to PHP:

  1. Usually just copy and make sure something, that wants to use it, knows where it is.
  2. An extension is usually written in C and loaded by the interpreter, whereas a library usually means a native PHP library.
  3. Dont know, what you want know here. The ini loads extensions and set up some settings. Its not directly associated with installations, .... You can set up your include-path (or something) here.
  4. You can install libraries with it ;) Dont know either, what you want to know.
  5. usually require(_once) or include(_once). For classes you can set up a autoloader. Refer to the PHP manual.
  6. package/Archive (zip, gz, tarball, ..) it and make a download link? Also: Dont know, what you want.

If you want to write PHP libraries and want a simple way for packaging and distribution, than have a look at PEAR.

🌐
GitHub
gist.github.com β€Ί llbbl β€Ί 7607016
Awesome PHP Libraries and Resources Β· GitHub
Awesome PHP Libraries and Resources. GitHub Gist: instantly share code, notes, and snippets.
🌐
GitHub
github.com β€Ί ziadoz β€Ί awesome-php
GitHub - ziadoz/awesome-php: A curated list of amazingly awesome PHP libraries, resources and shiny things. Β· GitHub
A curated list of amazingly awesome PHP libraries, resources and shiny things. - ziadoz/awesome-php
Starred by 32.5K users
Forked by 5.1K users
🌐
SourceForge
sourceforge.net β€Ί home β€Ί open source software β€Ί software development β€Ί libraries
Best Open Source PHP Libraries for Mac
Compare the best free open source PHP Libraries for Mac at SourceForge. List of free, secure and fast PHP Libraries for Mac, projects, software, and downloads.
Find elsewhere
🌐
SolarWinds
documentation.solarwinds.com β€Ί en β€Ί success_center β€Ί observability β€Ί content β€Ί configure β€Ί services β€Ί php β€Ί install.htm
SolarWinds Observability | Install the PHP Library
To install the library in a standard environment where PHP is installed in the default location: Copy the command below or click Copy in step 1 of the Add Data dialog. Run the copied command in the command line to download the wrapper script.
🌐
PHP Libraries
phplibraries.com
Download Free PHP Libraries – No Composer Required
Welcome to phplibraries.com – your trusted source for standalone PHP packages with no dependency managers required. Every library is automatically fetched, prepared, and structured for easy use – and many are manually reviewed to ensure quality, functionality, and compatibility. All packages are lightweight and ready for production or quick deployment on any server – including shared hosting and legacy environments. To start using a library, simply download your preferred version and include it in your project like this:
🌐
PHP
php.net β€Ί downloads.php
PHP: Downloads
Development package (SDK to develop PHP extensions) 1.64MB sha256: 7ec570475fc8f1d825a1263328c84e059a9d49613667f754ddf32d88b4fafb02
🌐
SourceForge
sourceforge.net β€Ί projects β€Ί phplib
PHPLIB download | SourceForge.net
Download PHPLIB for free. PHPLIB is an object-oriented application development toolkit for PHP. It is primarily of benefit to Web application developers, but contains classes which are useful to other PHP developers as well.
🌐
Cloudways
cloudways.com β€Ί home β€Ί learn php tutorials, tips and guides β€Ί top 40 php libraries every developer should know
40 Best PHP Libraries For Web Applications in 2022
October 24, 2025 - This particular AWS library allows developers to use Amazon Web Services in PHP applications. Using this AWS SDK, you can build desired web applications associated with Amazon S3, Glacier, DynamoDB, and other Amazon services. Simply install this SDK using composer or download a zip file, all ...
🌐
TCPDF
tcpdf.org
TCPDF
New library: https://github.com/tecnickcom/tc-lib-pdf Β· Recommendation: Starting a new project: use tc-lib-pdf. Running legacy TCPDF in production: keep it stable short-term and plan phased migration. Migration matters because tc-lib-pdf is where active evolution continues. PHP 8.1+ Composer Β·
🌐
GitHub
github.com β€Ί PHPOffice β€Ί PhpSpreadsheet
GitHub - PHPOffice/PhpSpreadsheet: A pure PHP library for reading and writing spreadsheet files Β· GitHub
A pure PHP library for reading and writing spreadsheet files - PHPOffice/PhpSpreadsheet
Starred by 13.9K users
Forked by 3.6K users
Languages Β  PHP
🌐
Libhunt
php.libhunt.com
Awesome PHP | LibHunt
Your go-to PHP Toolbox. A curated list of awesome PHP libraries and resources. 979 projects organized into 122 categories.