Table of Contents
Environment
Preparation
Install the dependent library
Source code compilation and installation
Configuration extension
Use
Home Backend Development PHP Problem How to install uuid extension in php

How to install uuid extension in php

Mar 12, 2021 am 10:47 AM
php

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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles