Linux编译安装php,不管版本,其实流程是一致
1. 下载PHP
wget http://php.net/get/php-7.0.1.tar.gz/from/this/mirror -O php-7.0.1.tar.gz tar zxvf php-7.0.1.tar.gz
2. 安装依赖环境
yum -y install gcc gcc-c++ zip unzip libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libmcrypt-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel gd-devel bzip2 bzip2-devel
3. 安装 libzip(另外最新版本请参考官网:https://nih.at/libzip/ 1.5.0的libzip需要cmake )
wget https://nih.at/libzip/libzip-1.2.0.tar.gz tar -zxvf libzip-1.2.0.tar.gz cd libzip-1.2.0 ./configure make && make install 高版本参考 cd /usr/local/src wget https://libzip.org/download/libzip-1.5.2.tar.gz tar -zxvf libzip-1.5.2.tar.gz cd libzip-1.5.2 mkdir build && cd build && cmake .. && make && make install
安装 libiconv
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz tar zxvf libiconv-1.13.1.tar.gz && cd libiconv-1.13.1 ./configure --prefix=/usr/local/libiconv make make install
4. 配置php(整理至一行运行哈)
./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-config-file-scan-dir=/usr/local/php7/conf.d --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv=/usr/local/libiconv --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-fileinfo --disable-rpath --disable-debug --enable-shared --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --without-pear --enable-session --enable-opcache --enable-intl --with-xsl
其中可以增加–with-mysql-sock=[dir] 来设置mysql的sock文件的位置,默认是/tmp/mysql.sock
–prefix 是你要安装的位置
其他的参数可以自己搜索下哈
5. 编译和安装
make make install
6. 拷贝 php.ini 配置文件
cp php.ini-production /usr/local/php7/etc/php.ini cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf
修改php-fpm.conf 修改 php-fpm 启动端口号(默认 9000)
[global] pid = /usr/local/php7/var/run/php-fpm.pid error_log = /usr/local/php7/var/log/php-fpm.log log_level = notice [www] listen = 127.0.0.1:9071 # listen = /tmp/php-cgi.sock listen.backlog = -1 listen.allowed_clients = 127.0.0.1 listen.owner = www listen.group = www listen.mode = 0666 user = www group = www pm = dynamic pm.max_children = 40 pm.start_servers = 20 pm.min_spare_servers = 20 pm.max_spare_servers = 40 pm.max_requests = 1024 pm.process_idle_timeout = 10s request_terminate_timeout = 100 request_slowlog_timeout = 0 slowlog = var/log/slow.log
添加 init.d 下 运行服务 php-fpm7
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm7 chmod +x /etc/init.d/php-fpm7
启动php
/etc/init.d/php-fpm start #php-fpm启动命令 /etc/init.d/php-fpm stop #php-fpm停止命令 /etc/init.d/php-fpm restart #php-fpm重启命令 ps -ef | grep php 或者 ps -A | grep -i php #查看是否已经成功启动PHP
7. 添加服务启动
chkconfig --add php-fpm7 chkconfig php-fpm7 on service php-fpm7 start
8. 添加系统环境变量
echo $PATH PATH=$PATH:/usr/local/php7/bin export PATH 或者 vim /etc/profile export PATH=/usr/local/php7/bin:$PATH source /etc/profile #检查是否成功 php -v #能输出php版本就成功了
遇到问题点
php-fpm 指定php.ini 启动
./usr/local/php7/sbin/php-fpm -c /usr/local/php7/etc/php.ini
查看 php 进程
ps -ef | grep php-fpm
查看端口占用
netstat -anp |grep 3306
关闭进程 kill -9 进程PID
关闭所有进程 killall -9 进程名
-----------------------------------------------------------------------------------------
./configure 编译时出现问题
collect2: ld returned 1 exit status make: *** [sapi/cli/php] Error 1 解决方法执行 make ZEND_EXTRA_LIBS='-liconv'
参考地址:
linux 下编译安装PHP7.2 https://www.cnblogs.com/rxbook/p/9106513.html
php7.2 添加 Jpeg 扩展: https://blog.csdn.net/zepcjsj0801/article/details/108632389
预祝大家顺利安装 (^ _ ^)(^ _ ^)(^ _ ^)(^ _ ^)(^ _ ^)(^ _ ^)