一、下载源码
1 | wget http: //cn.php.net/distributions/php-7.2.4.tar.gz |
二、解压源码
1 | tar -zxvf php-7.2.4.tar.gz |
三、编译
1、配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | ./configure --prefix=/usr/local/php \ --with-curl \ --with-freetype-dir \ --with-gd \ --with-gettext \ --with-iconv-dir \ --with-kerberos \ --with-libdir=lib64 \ --with-libxml-dir \ --with-mysqli \ --with-openssl \ --with-pcre-regex \ --with-pdo-mysql \ --with-pdo-sqlite \ --with-pear \ --with-png-dir \ --with-xmlrpc \ --with-xsl \ --with-zlib \ --enable-fpm \ --enable-bcmath \ --enable-libxml \ --enable- inline -optimization \ --enable-mbregex \ --enable-mbstring \ --enable-opcache \ --enable-pcntl \ --enable-shmop \ --enable-soap \ --enable-sockets \ --enable-sysvsem \ --enable-xml \ --enable-zip |
配置过程错误解决方法:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | 1、libxml2 configure: error: xml2-config not found. Please check your libxml2 installation. apt-get install libxml2-dev 2、configure: error: Cannot find OpenSSL's libraries apt-get install pkg-config libssl-dev openssl 3、checking for cURL 7.10.5 or greater... configure: error: cURL version 7.10.5 or later is required to compile php with cURL support apt-get install libcurl4-gnutls-dev curl 4、configure: error: png.h not found. apt-get install libpng-dev 5、configure: error: freetype-config not found. apt-get install libfreetype6-dev 6、configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution apt-get install libxslt1-dev |
也可以在配置前直接执行:
1 | apt-get install libxml2-dev pkg-config libssl-dev openssl libcurl4-gnutls-dev curl libpng-dev libfreetype6-dev libxslt1-dev |
2、编译安装
1 | make & make install |
四、配置PHP
1、
1 | vim ~/.bash_aliases |
写入信息
1 2 3 | alias php= '/usr/local/php/bin/php' alias phpize= '/usr/local/php/bin/phpize' alias php-fpm= '/usr/local/php/sbin/php-fpm' |
使设置生效
1 | source ~/.bash_aliases |
2、
1 2 3 4 5 6 7 8 9 10 11 | cp php.ini-development /usr/local/php/lib/php.ini 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 cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod +x /etc/init.d/php-fpm update-rc.d php-fpm defaults |
3、修改www.conf配置
1 | vim /usr/local/php/etc/php-fpm.d/www.conf |
1 2 3 4 5 6 7 8 9 | user = www-data group = www-data listen = /run/php/php7.0-fpm.sock listen.owner = www-data listen.group = www-data pm.max_requests = 5000 |
注:需要创建/run/php目录
1 | mkdir /run/php |
4、修改php.ini配置
1 | vim /usr/local/php/lib/php.ini |
1 2 3 | post_max_size = 100M upload_max_filesize = 80M date.timezone = PRC |
五、启动php-fpm
1 | service php-fpm start |