Ubuntu18.04安装php7.3
2024-11-30 10:16 猎手家园 阅读(17) 评论(0) 编辑 收藏 举报1、安装依赖
sudo apt update sudo apt -y install gcc sudo apt -y install make sudo apt -y install openssl sudo apt -y install curl sudo apt -y install libbz2-dev sudo apt -y install libxml2-dev sudo apt -y install libjpeg-dev sudo apt -y install libpng-dev sudo apt -y install libfreetype6-dev sudo apt -y install libzip-dev sudo apt -y install libssl-dev sudo apt -y install libcurl4-openssl-dev sudo apt -y install libjpeg-dev sudo apt -y install libpng-dev sudo apt -y install libfreetype6-dev sudo apt -y install libzip-dev sudo apt -y install libcurl4-gnutls-dev sudo apt -y install libxslt1-dev
2、下载PHP7.3版本
3、解压安装
# 解压 tar xzf php-7.3.30.tar.gz cd php-7.3.30 # 编译 ./configure --prefix=/usr/local/php7.3 --with-config-file-path=/usr/local/php7.3/etc --with-curl --with-freetype-dir --with-gd --with-gettext --with-iconv-dir --with-kerberos --with-libdir=lib64 --with-libxml-dir --with-openssl --with-pcre-regex --with-pear --with-png-dir --with-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-openssl --enable-fpm --enable-bcmath --enable-libxml --enable-inline-optimization --enable-mbregex --enable-opcache --enable-pcntl --enable-shmop --enable-soap --enable-sockets --enable-sysvsem --enable-xml --enable-zip --enable-mbstring --enable-mysqlnd --with-pdo-mysql=mysqlnd
相关参数说明:
#指定php安装目录 –prefix=/usr/local/php7.3 #指定php.ini位置 –with-config-file-path=/usr/local/php7.3/etc #打开curl浏览工具的支持 –with-curl #打开对freetype字体库的支持 –with-freetype-dir #打开gd库的支持 –with-gd #打开gnu 的gettext 支持,编码库用到 –with-gettext #选项指令 --with-iconv-dir 用于 PHP 编译时指定 iconv 在系统里的路径,否则会扫描默认路径。 –with-iconv-dir #打开libxml2库的支持 –with-libxml-dir #object code libraries [EPREFIX/lib] –with-libdir=lib64 #openssl的支持,加密传输https时用到的 –with-openssl #OPENSSL: Include Kerberos support –with-kerberos #fpm –enable-fpm #Include Perl Compatible Regular Expressions support. –with-pcre-regex #PDO: MySQL支持 –with-pdo-mysql –with-pdo-sqlite #打开pear命令的支持,PHP扩展用的 –with-pear #打开对png图片的支持 –with-png-dir #打开对jpeg图片的支持 –with-jpeg-dir #打开对XMLRPC-EP支持 –with-xmlrpc #打开对XSL的支持. DIR is the libxslt base install directory (libxslt >= 1.1.0 required) –with-xsl #打开对ZLIB的支持 (requires zlib >= 1.2.0.4) –with-zlib #打开bc精确数学函数 –enable-bcmath #打开LIBXML支持 –enable-libxml #优化线程 –enable-inline-optimization –enable-mbregex #多字节,字符串的支持 –enable-mbstring #开启Zend OPcache支持 –enable-opcache #freeTDS需要用到的,可能是链接mssql 才用到 –enable-pcntl #可以处理相关的IPC函数 –enable-shmop –enable-sysvsem #开启SOAP支持 –enable-soap #打开 sockets 支持 –enable-sockets –enable-xml #打开对zip的支持 –enable-zip
+--------------------------------------------------------------------+ | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +--------------------------------------------------------------------+ Thank you for using PHP.
安装
make
make install
查看PHP版本
root@ubuntu:/usr/local/php# ./bin/php -v PHP 7.3.30 (cli) (built: Nov 30 2024 10:28:38) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.30, Copyright (c) 1998-2018 Zend Technologies
4、配置
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 php.ini-development /usr/local/php/etc/php.ini
配置: www.conf
[www] listen = 127.0.0.1:9001 #改一下默认端口,默认端口是9000 user = nobody group = nobody pm = dynamic pm.max_children = 128 pm.start_servers = 20 pm.min_spare_servers = 5 pm.max_spare_servers = 35 pm.max_requests = 10000 rlimit_files = 1024 slowlog = log/$pool.log.slow
修改:php.ini配置文件
vim php.ini # 查找并修改值为 0 cgi.fix_pathinfo=0
添加环境变量
vim /etc/profile #在文件底部加入 #PHP7.3 export PATH=$PATH:/usr/local/php/bin #保存,使环境变量生效 source /etc/profile
配置fpm命令
cd php-7.3.30/sbin cp php-fpm /etc/init.d/php-fpm #增加权限 chmod +x /etc/init.d/php-fpm
service php-fpm reload service php-fpm start service php-fpm stop service php-fpm status
启动并查看PHP
cd /usr/local/php/sbin ./php-fpm ps aux | grep php #如果看到有结果则说明安装成功 root 2021 0.0 0.1 217880 6312 ? Ss 00:59 0:00 php-fpm: master process (/usr/local/php7.3/etc/php-fpm.conf) nobody 2022 0.0 0.1 217880 5792 ? S 00:59 0:00 php-fpm: pool www nobody 2023 0.0 0.1 217880 5792 ? S 00:59 0:00 php-fpm: pool www
5、安装扩展
5.1 需要autoconf版本2.68
#下载 wget ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz #安装: tar zxvf autoconf-2.69.tar.gz cd autoconf-2.69 ./configure --prefix=/usr/ make && make install #检查版本: /usr/bin/autoconf -V
5.2 PHP安装包中自带很多扩展,以安装zip为例
#1、进入要安装的扩展包文件夹下,如: cd php-7.3.30/ext/zip #2、通过phpize生成编译文件: /usr/local/php/bin/phpize #3、编译 ./configure --with-php-config=/usr/local/php/bin/php-config #4、安装 make && make install
5.3 安装自带扩展以外的扩展,如redis
下载扩展:http://pecl.php.net/get/redis-5.0.0.tgz
#1、解压并进入目录 tar xzf redis-5.0.0.tgz cd redis-5.0.0 #2、通过phpize生成编译文件: /usr/local/php/bin/phpize #3、编译 ./configure --with-php-config=/usr/local/php/bin/php-config #4、安装 make && make install
然后打开文件 etc/php.ini,写入redis扩展
vim etc/php.ini # 在第一个模块后面写入redis.io 扩展 extension=redis.so
重启php-fpm后,输入:php -m 就能检查扩展是否安装成功
欢迎关注我的公众号:云栖语,不一样的研发视界。
云栖语微信公众号:change-1978