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 .
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
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
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/
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
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
4. Set environment variables
vi /etc/profile
After opening, add the following configuration at the bottom of the document:
export PATH=/usr/local/php/bin:$PATH :wq!保存退出,执行如下命令,使更改生效 source /etc/profile
5. Start php test
#启动 /etc/init.d/php-fpm start #测试php cd /usr/local/nginx/html vi test.php
Add the following content:
<?php echo phpinfo(); ?>
: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`
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
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
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!