幫助中心
這里有最新的使用文檔和教程
CentOS8編譯安裝PHP7.3.10,編譯安裝PHP7.3,安裝PHP7.3
安裝前準備:
要先安裝好Nginx , 安裝Nginx 請參考:http://www.jinchangtalc.com/helpcontent/516.html
開始安裝PHP7.3
1、安裝yasm
cd /usr/local/src
tar zxvf yasm-1.3.0.tar.gz
cd yasm-1.3.0
./configure
make
make install
2、安裝libmcrypt
cd /usr/local/src
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install
3、安裝libvpx
cd /usr/local/src
tar zxvf libvpx-1.8.1.tar.gz
cd libvpx-1.8.1
./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9
make
make install
4、安裝tiff
cd /usr/local/src
tar zxvf tiff-4.0.7.tar.gz
cd tiff-4.0.7
./configure --prefix=/usr/local/tiff --enable-shared
make
make install
5、安裝libpng
cd /usr/local/src
tar zxvf libpng-1.6.37.tar.gz #解壓
xz -d libpng-1.6.37.tar.xz #先解壓xz
tar xvf libpng-1.6.37.tar #再解壓tar
或者
tar xvJf libpng-1.6.37.tar.xz #直接解壓
cd libpng-1.6.37
./configure --prefix=/usr/local/libpng --enable-shared
make
make install
6、安裝freetype
cd /usr/local/src
tar zxvf freetype-2.9.tar.gz
cd freetype-2.9
./configure --prefix=/usr/local/freetype --enable-shared
make
make install
7、安裝jpeg
cd /usr/local/src
tar zxvf jpegsrc.v9c.tar.gz
cd jpeg-9c
./configure --prefix=/usr/local/jpeg --enable-shared
make
make install
8、安裝libgd
cd /usr/local/src
tar zxvf libgd-2.2.5.tar.gz
cd libgd-2.2.5
./configure --prefix=/usr/local/libgd --enable-shared --with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype --with-fontconfig=/usr/local/freetype --with-xpm=/usr/lib64 --with-tiff=/usr/local/tiff
make
make install
9、安裝t1lib
cd /usr/local/src
tar zxvf t1lib-5.1.2.tar.gz
cd t1lib-5.1.2
./configure --prefix=/usr/local/t1lib --enable-shared
make without_doc
make install
10、安裝libzip
cd /usr/local/src
tar -zxvf libzip-1.2.0.tar.gz
cd libzip-1.2.0
./configure
make
make install
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
#拷貝文件,否則安裝php可能會報錯 /usr/local/include/zip.h:59:21: fatal error: zipconf.h: No such file or dire
11、安裝php
注意:如果系統(tǒng)是64位,請執(zhí)行以下兩條命令,否則安裝php會出錯。
\cp -frp /usr/lib64/libltdl.so* /usr/lib/
\cp -frp /usr/lib64/libXpm.so* /usr/lib/
11.1、安裝php7.3.10
cd /usr/local/src
tar -zvxf php-7.3.10.tar.gz
cd php-7.3.10
export LD_LIBRARY_PATH=/usr/local/libgd/lib
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/" #libzip庫安裝位置,否則安裝php可能會報錯
./configure --prefix=/usr/local/php73 --with-config-file-path=/usr/local/php73/etc --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gd=/usr/local/libgd --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype --with-xpm-dir=/usr/lib64 --with-zlib-dir=/usr/local/zlib --with-iconv --enable-libxml --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --enable-opcache --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-curl --enable-ctype --enable-mysqlnd --enable-pdo
make #編譯
make install #安裝
說明:如果提示libgd版本錯誤,把php編譯參數(shù)--with-gd=/usr/local/libgd修改為--with-gd即可。
cp php.ini-production /usr/local/php73/etc/php.ini #復(fù)制php配置文件到安裝目錄
rm -rf /etc/php.ini #刪除系統(tǒng)自帶配置文件
ln -s /usr/local/php73/etc/php.ini /etc/php.ini #添加軟鏈接到 /etc目錄
cp /usr/local/php73/etc/php-fpm.conf.default /usr/local/php73/etc/php-fpm.conf #拷貝模板文件為php-fpm配置文件
ln -s /usr/local/php73/etc/php-fpm.conf /etc/php-fpm.conf #添加軟連接到 /etc目錄
vi /usr/local/php73/etc/php-fpm.conf #編輯
pid = run/php-fpm.pid #取消前面的分號
include=/usr/local/php73/etc/php-fpm.d/*.conf
:wq! #保存退出
cp /usr/local/php73/etc/php-fpm.d/www.conf.default /usr/local/php73/etc/php-fpm.d/www.conf
vi /usr/local/php73/etc/php-fpm.d/www.conf #編輯
user = www #設(shè)置php-fpm運行賬號為www
group = www #設(shè)置php-fpm運行組為www
listen = 127.0.0.1:9000
:wq! #保存退出
11.2、設(shè)置 php-fpm開機啟動(有兩種設(shè)置方法,選擇一種即可)
11.2.1 #chkconfig方式
cp /usr/local/src/php-7.3.10/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php73-fpm #拷貝php-fpm到啟動目錄
chmod +x /etc/rc.d/init.d/php73-fpm #添加執(zhí)行權(quán)限
chkconfig php73-fpm on #設(shè)置開機啟動
vi /etc/rc.d/init.d/php73-fpm
prefix=/usr/local/php73
php_fpm_BIN=${exec_prefix}/sbin/php73-fpm
:wq! #保存退出
mv /usr/local/php73/sbin/php-fpm /usr/local/php73/sbin/php73-fpm
service php73-fpm start #啟動php71-fpm
service php73-fpm stop #停止php71-fpm
11.2.2 #systemctl方式
vi /usr/lib/systemd/system/php73-fpm.service #編輯添加以下代碼
[Unit]
Description=The PHP FastCGI Process Manager
After=syslog.target network.target
[Service]
Type=simple
PIDFile=/run/php-fpm.pid
ExecStart=/usr/local/php73/sbin/php73-fpm --nodaemonize --fpm-config /usr/local/php73/etc/php-fpm.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID
[Install]
WantedBy=multi-user.target
:wq! #保存退出
mv /usr/local/php73/sbin/php-fpm /usr/local/php73/sbin/php73-fpm
systemctl enable php73-fpm.service #設(shè)置開機自啟動
systemctl daemon-reload #重新加載systemctll
systemctl start php73-fpm.service #啟動
systemctl stop php73-fpm.service #停止
systemctl restart php73-fpm.service #重啟
11.3 配置php配置文件
vi /usr/local/php73/etc/php.ini #編輯配置文件
找到:disable_functions =
修改為:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd, posix_getegid,posix_geteuid,posix_getgid, posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid, posix_getppid,posix_getpwnam,posix_getpwuid, posix_getrlimit, posix_getsid,posix_getuid,posix_isatty, posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid, posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
#列出PHP可以禁用的函數(shù),如果某些程序需要用到這個函數(shù),可以刪除,取消禁用。
找到:;date.timezone =
修改為:date.timezone = PRC #設(shè)置時區(qū)
找到:expose_php = On
修改為:expose_php = Off #禁止顯示php版本的信息
找到:short_open_tag = Off
修改為:short_open_tag = ON #支持php短標簽
找到opcache.enable=0
修改為opcache.enable=1 #php支持opcode緩存
找到:;opcache.enable_cli=1
修改為:opcache.enable_cli=0 #php支持opcode緩存
在最后一行添加:zend_extension=opcache.so #開啟opcode緩存功能
:wq! #保存退出
四、配置nginx支持php
vi /usr/local/nginx/conf/nginx.conf
修改/usr/local/nginx/conf/nginx.conf 配置文件,需做如下修改
user www www; #首行user去掉注釋,修改Nginx運行組為www www;必須與/usr/local/php/etc/php-fpm.conf中的user,group配置相同,否則php運行出錯
index index.html index.htm index.php; #添加index.php
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#取消FastCGI server部分location的注釋,注意fastcgi_param行的參數(shù),改為$document_root$fastcgi_script_name,或者使用絕對路徑
systemctl restart nginx.service #重啟nginx
service php73-fpm start #啟動php71-fpm
或者(根據(jù)設(shè)置的php-fpm開機啟動方式執(zhí)行相應(yīng)的啟動命令)
systemctl start php73-fpm.service #啟動