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.
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
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
Source code compilation and installation
- Unzip the package
$ tar -zxvf uuid-1.1.0.tgz
- Enter the root directory of the package
$ cd uuid-1.1.0/
- Initialization
$ phpize7.2
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
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
The file generated after successful installation is usually modules/××.so
Libraries have been installed in: /home/vagrant/uuid-1.1.0/modules
or
Installing shared extensions: /usr/lib/php/20170718/
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/
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
4. Restart fpm
sudo service php7.2-fpm reload
5. Check whether the installation is successful
- In cli mode
$ php -m |grep uuid
- In fpm mode
Through phpinfo () View
Use
<?php if (function_exists('uuid_create') === true) { echo uuid_create(), "<br>"; echo uuid_create(1); } else { echo 'uuid未安装'; }
output example:
33303096-b9c8-4e65-b4fd-3649e008b0e3 9f23c3b9-62c2-11ea-81b4-080027b68021
[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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Linux new version
SublimeText3 Linux latest version
