Home > Backend Development > PHP Problem > How to install uuid extension in php

How to install uuid extension in php

藏色散人
Release: 2023-03-08 17:20:01
Original
2606 people have browsed it

How to install the uuid extension in php: First, go to the PECL official website to download the php uuid extension; then install the dependent libraries; then use the phpize command to prepare the compilation environment for the PHP extension library; and finally install it through the install command.

How to install uuid extension in php

The operating environment of this article: Ubuntu1804 system, php7.2 version, DELL G3 computer

PHP uses uuid

Environment

Ubuntu1804 php7.2 nginx

Preparation

Go to the PECL official website (https://pecl.php.net/package/uuid) to download the latest php uuid extension:

For example, uuid-1.1.0 version

$ wget https://pecl.php.net/get/uuid-1.1.0.tgz
Copy after login

Install the dependent library

The most important component of uuid is the machine code, most of which are the network card MAC address. PHP cannot obtain the machine code, so the code cannot be used directly to generate a uuid

Under ubuntu this package is uuid-dev, other platforms are similar

$ sudo apt-get install uuid-dev
Copy after login

Source code compilation and installation

  • Unzip the package
$  tar -zxvf uuid-1.1.0.tgz
Copy after login
  • Enter the root directory of the package
$ cd uuid-1.1.0/
Copy after login
  • Initialization
$ phpize7.2
Copy after login

phpize command is used to prepare PHP The compilation environment of the extension library.
Generally in the bin directory, multiple versions of PHP find their corresponding phpize, such as /bin/phpize7.2

  • Configuration
$ ./configure --with-php-config=/usr/bin/php-config7.2
Copy after login

php-config is a simple command line script used to obtain information about the installed PHP configuration

  • Installation
$ sudo make
$ sudo make test
$ sudo make install
Copy after login

The file generated after successful installation is usually modules/××.so

Libraries have been installed in:
   /home/vagrant/uuid-1.1.0/modules
Copy after login

or

  Installing shared extensions:     /usr/lib/php/20170718/
Copy after login

in the current directory. If the extension .so file is not automatically added to the extension directory (you can view the extension_dir directory through phpinfo, which is the "/usr/lib/php/20170718/" above), you need to manually copy

$ sudo cp /home/vagrant/uuid-1.1.0/modules/uuid.so /usr/lib/php/20170718/
Copy after login

Configuration extension

We just installed the extensions before, but the specific extensions introduced in cli and fpm modes generally need to be configured separately

  • Add the uuid extension to the corresponding configuration file

1. The old way of adding is usually to add a line directly to the php.ini file: extension=uuid.so;

2. The new version is easier to manage and is usually /etc/php/php7.2/mods- availableAdd the uuid.ini file and add a line extension=uuid.so;

3. Add it to the fpm and cli configuration

$ sudo ln -s /etc/php/7.2/mods-available/uuid.ini /etc/php/7.2/fpm/conf.d/uuid.ini
 
$ sudo ln -s /etc/php/7.2/mods-available/uuid.ini /etc/php/7.2/cli/conf.d/uuid.ini
Copy after login

4. Restart fpm

sudo service php7.2-fpm reload
Copy after login

5. Check whether the installation is successful

  • In cli mode
$ php -m |grep uuid
Copy after login
  • In fpm mode

Through phpinfo () View

Use

<?php

if (function_exists(&#39;uuid_create&#39;) === true) {
    echo uuid_create(), "<br>";
    echo uuid_create(1);
} else {
    echo &#39;uuid未安装&#39;;
}
Copy after login

output example:

33303096-b9c8-4e65-b4fd-3649e008b0e3
9f23c3b9-62c2-11ea-81b4-080027b68021
Copy after login

[Recommended learning: "PHP Video Tutorial"]

The above is the detailed content of How to install uuid extension in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template