Home  >  Article  >  Backend Development  >  How to compile and install php7 in ubantu

How to compile and install php7 in ubantu

藏色散人
藏色散人Original
2022-01-20 09:52:493915browse

How to compile and install php7 on ubuntu: 1. Download the source code of PHP7.4 to Ubuntu; 2. Install the dependencies required by PHP; 3. Configure PHP installation parameters; 4. Execute through "sudo make install" Just compile and install.

How to compile and install php7 in ubantu

The operating environment of this article: Ubuntu 18.04 system, PHP7.4 version, DELL G3 computer

Installation environment: Operating system: Ubuntu 18.04 PHP version : PHP 7.4 Web server: Nginx 1.17.4

ubantu How to compile and install php7?

Ubuntu compile and install PHP7.4

Database: Mariadb 10.0.38 (a branch of MySQL, compatible with MySQL)

Before installation

Update the software list as usual:

sudo apt-get update

Install PHP7.4

Download the source code of PHP 7.4 to Ubuntu:

`wget https://www.php.net/distributions/php-7.4.0.tar.gz`

If the download speed If it is too slow, you can use the domestic high-speed download address of PHP 7.4:

wget https://gz-1257226027.cos.ap-guangzhou.myqcloud.com/php-7.4.0.tar.gz

Unzip and enter the php7.4 source code directory:

tar zxvf php-7.4.0.tar.gz
cd php-7.4.0/

Install the dependencies required for PHP first

sudo apt-get install libzip-dev bison autoconf build-essential pkg-config git-core\
   libltdl-dev libbz2-dev libxml2-dev libxslt1-dev libssl-dev libicu-dev libpspell-dev\
   libenchant-dev libmcrypt-dev libpng-dev libjpeg8-dev libfreetype6-dev libmysqlclient-dev\
   libreadline-dev libcurl4-openssl-dev librecode-dev libsqlite3-dev libonig-dev

Configuration PHP installation parameters

./configure --prefix=/usr/local/php7 --with-config-file-scan-dir=/usr/local/php7/etc/php.d --with-config-file-path=/usr/local/php7/etc --enable-mbstring --enable-zip --enable-bcmath --enable-pcntl --enable-ftp --enable-xml --enable-shmop --enable-soap --enable-intl --with-openssl --enable-exif --enable-calendar --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-opcache --enable-fpm --enable-session --enable-sockets --enable-mbregex --enable-wddx --with-curl --with-iconv --with-gd --with-jpeg-dir=/usr --with-png-dir=/usr --with-zlib-dir=/usr --with-freetype-dir=/usr --enable-gd-jis-conv --with-openssl --with-pdo-mysql=mysqlnd --with-gettext=/usr --with-zlib=/usr --with-bz2=/usr --with-recode=/usr --with-xmlrpc --with-mysqli=mysqlnd

Execute compilation and installation

sudo make install

If there is insufficient memory during the compilation process:

virtual memory exhausted: Cannot allocate memory
Makefile:921: recipe for target ‘ext/fileinfo/libmagic/apprentice.lo’ failed
make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

Please add virtual memory to the server first, refer to: Add virtual memory for Linux Swap.

Copy the configuration file

sudo cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf
sudo cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
sudo cp php.ini-production /usr/local/php7/etc/php.ini

Add environment variables, edit /etc/profile, and add a line at the end of the file:

PATH=/usr/local/php7/bin:/usr/local/php7/sbin:$PATH

Make the environment variables take effect:

source /etc/profile

Add php to the sudo environment variable, edit Defaults secure_path in the /etc/sudoers file, and then add the PHP path:

/usr/local/php7/bin:/usr/local/php7/sbin:

Start php-fpm

sudo php-fpm

If the prompt cannot find the user group Nobody's gid:

[15-Nov-2019 15:53:49] ERROR: [pool www] cannot get gid for group ‘nobody’
[15-Nov-2019 15:53:49] ERROR: FPM initialization failed

You must first create the nobody user group:

sudo groupadd nobody

and then re-execute sudo php-fpm to start.

Use the php -v command to check the php version:

 php -v
PHP 7.4.0 (cli) (built: Nov 28 2019 13:38:00) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to compile and install php7 in ubantu. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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