Home > Backend Development > PHP7 > body text

How to compile and install php7 in ubantu

藏色散人
Release: 2023-02-18 10:04:02
Original
3791 people have browsed it

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
Copy after login

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`
Copy after login

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
Copy after login

Unzip and enter the php7.4 source code directory:

tar zxvf php-7.4.0.tar.gz
cd php-7.4.0/
Copy after login

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
Copy after login

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
Copy after login

Execute compilation and installation

sudo make install
Copy after login

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
Copy after login

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
Copy after login

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
Copy after login

Make the environment variables take effect:

source /etc/profile
Copy after login

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:
Copy after login

Start php-fpm

sudo php-fpm
Copy after login

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
Copy after login

You must first create the nobody user group:

sudo groupadd nobody
Copy after login

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
Copy after login

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!

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!