Home > Backend Development > PHP Problem > How to install and start linux php source code

How to install and start linux php source code

藏色散人
Release: 2023-03-11 11:28:02
Original
2899 people have browsed it

How to start Linux PHP source code installation: 1. Download the PHP source code and unzip the file package; 2. Install dependencies, compile and install; 3. Configure PHP; 4. Set environment variables; 5. Start PHP testing .

How to install and start linux php source code

The operating environment of this article: linux5.9.8 system, PHP7.1.4 version, DELL G3 computer

How to install and start the linux php source code ?

#php source code installation steps under linux

1. Download the php source code

Download address: http://cn.php. net/downloads.php

2. Installation

1. Move the downloaded binary package to the /usr/local directory and decompress the file package

tar zxvf php-7.1.4.tar.gz
Copy after login

2. Enter decompression /usr/local/php-7.1.4 in the php folder, install dependencies, compile and install

yum install  libxml2  libxml2-devel
./configure --prefix=/usr/local/php  --with-zlib --enable-zip --with-openssl --enable-fpm --enable-mbstring --with-libdir=lib64 --without-pear  --disable-phar
make
make test (编译完后可以允许一下make test命令,检测编译是否有问题)
make install
Copy after login

Summary information after the installation is completed:

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20160303/
Installing PHP CLI binary:        /usr/local/php/bin/
Installing PHP CLI man page:      /usr/local/php/php/man/man1/
Installing PHP FPM binary:        /usr/local/php/sbin/
Installing PHP FPM defconfig:     /usr/local/php/etc/
Installing PHP FPM man page:      /usr/local/php/php/man/man8/
Installing PHP FPM status page:   /usr/local/php/php/php/fpm/
Installing phpdbg binary:         /usr/local/php/bin/
Installing phpdbg man page:       /usr/local/php/php/man/man1/
Installing PHP CGI binary:        /usr/local/php/bin/
Installing PHP CGI man page:      /usr/local/php/php/man/man1/
Installing build environment:     /usr/local/php/lib/php/build/
Installing header files:          /usr/local/php/include/php/
Installing helper programs:       /usr/local/php/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PDO headers:           /usr/local/php/include/php/ext/pdo/
Copy after login

3, php configuration

#php的配置文件为 php.ini
cp /usr/local/php-7.1.4/php.ini-production   /usr/local/php/lib/php.ini
#使得另一种方法来管理服务:
cp /usr/local/php-7.1.4/sapi/fpm/php-fpm /etc/init.d/php-fpm
#添加执行权限
chmod +x /etc/init.d/php-fpm 
#php-fpm的配置文件
cp /usr/local/php/etc/php-fpm.conf.default   /usr/local/php/etc/php-fpm.conf
cp /usr/local/php/etc/php-fpm.d/www.conf.default   /usr/local/php/etc/php-fpm.d/www.conf
Copy after login

Modify the maximum limit on the number of php-fpm processes according to the machine configuration, which is limited to /usr/local/php/etc/php-fpm.d/www.conf

Use netstat -napo |grep " php-fpm" | wc -l Check the current number of fastcgi processes. If the number is close to the upper limit configured in conf, you need to increase the number of processes.

But you can’t increase it endlessly. You can adjust the number of php-fpm sub-processes to 100 or more according to the server memory. On a server with 4G memory, 200 is enough.

pm.max_children = 200
pm.start_servers = 10
pm.min_spare_servers = 8
pm.max_spare_servers = 12
Copy after login

4. Set environment variables

vi /etc/profile
Copy after login

After opening, add the following configuration at the bottom of the document:

export PATH=/usr/local/php/bin:$PATH
:wq!保存退出,执行如下命令,使更改生效
source /etc/profile
Copy after login

5. Start php test

#启动
/etc/init.d/php-fpm start
#测试php
cd /usr/local/nginx/html
vi test.php
Copy after login

Add the following content:

<?php  
 echo phpinfo();  
?>
Copy after login

:wq! Save and exit.

Browser input: http://10.62.32.123/test.php

If the PHP Version 7.1.4 interface appears, the detailed configuration interface of PHP is displayed, indicating that the installation is correct

6. Restart and stop php

php 7.1.4 The source code has already embedded php-fpm, you only need to add compilation parameters when configure.

The compilation parameters for php-fpm include –enable-fpm –with-fpm-user=www –with-fpm-group=www –with-libevent-dir=libevent location.

However, php-fpm under php 7.1.4 no longer supports commands such as /usr/local/php/sbin/php-fpm (start|stop|reload) that php-fpm previously had. You need to use Signal control:

The master process can understand the following signals:

SIGINT, SIGTERM Terminate immediately

SIGQUIT Terminate smoothly

SIGUSR1 Reopen the log file

SIGUSR2 Smoothly reload all worker processes and reload configuration and binary modules

Example:

php-fpm 关闭:  
kill -SIGINT `cat /usr/local/php/var/run/php-fpm.pid`  
php-fpm 重启:  
kill -SIGUSR2 `cat /usr/local/php/var/run/php-fpm.pid`
Copy after login

View the number of php-fpm processes:

ps aux | grep -c php-fpm
netstat -anpo | grep "php-cgi" | wc -l
netstat -anop | grep "php-fpm" | wc -l
Copy after login

3. Appendix

Instructions related to php compilation options:

./configure --prefix=/usr/local/php \ #指定安装目录
--with-config-file-path=/usr/local/php/etc \ #指定配置文件的目录,默认在php/lib下满\
--enable-fpm \启用php的fpm
--enable-mbstring  \ 启用多字节字符串支持
--with-libdir=lib64 \
--without-pear \禁用pear扩展 
--disable-phar \ 禁用pear扩展的phar函数库
--enable-mysqlnd \ 启用php的mysql驱动 
--with-mysqli=mysqlnd \ 指定mysql
--with-pdo-mysql=mysqlnd \指定mysql
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to install and start linux php source code. 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