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
Ubuntu1804 php7.2 nginx
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
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
$ tar -zxvf uuid-1.1.0.tgz
$ cd uuid-1.1.0/
$ 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
$ ./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
$ 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/
We just installed the extensions before, but the specific extensions introduced in cli and fpm modes generally need to be configured separately
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
$ php -m |grep uuid
Through phpinfo () View
<?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!