安装PHP
1、去PHP官网http://php.net/找到对应的版本
http://hk1.php.net/get/php-7.2.3.tar.gz/from/this/mirror
2、执行命令下载(php-7.2.3.tar.gz 中的 .tar.gz是打包并且压缩)
wget http://hk1.php.net/get/php-7.2.3.tar.gz/from/this/mirror
3、解压
tar -zxvf mirror
4、安装依赖包
第一步:
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel gcc gcc++
第二步:
#创建local.conf
vi /etc/ld.so.conf.d/local.conf
#添加输入
/usr/local/lib
#添加搜索路径到配置文件
echo '/usr/local/lib64 /usr/local/lib /usr/lib /usr/lib64'>>/etc/ld.so.conf
#然后 更新配置
ldconfig -v
第三步:
# 查看 yum 安装的 libzip 版本
yum list installed | grep libzip
#先删除旧版本
yum remove -y libzip
#下载编译安装
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
5、安装 FastCGI 进程管理器(FPM)
进入PHP目录
cd php-7.2.3/
编译(将PHP编译安装到 /usr/local/php目录下,带上上图的配置选项)(一下三种编译方式,推荐第三种)
./configure --prefix=/usr/local/php7 \--with-config-file-path=/usr/local/php7/etc \--with-config-file-scan-dir=/usr/local/php7/etc/php.d \--with-mcrypt=/usr/include \--enable-mysqlnd \--with-mysqli \--with-pdo-mysql \--enable-fpm \--with-fpm-user=nginx \--with-fpm-group=nginx \--with-gd \--with-iconv \--with-zlib \--enable-xml \--enable-shmop \--enable-sysvsem \--enable-inline-optimization \--enable-mbregex \--enable-mbstring \--enable-ftp \--enable-gd-native-ttf \--with-openssl \--enable-pcntl \--enable-sockets \--with-xmlrpc \--enable-zip \--enable-soap \--without-pear \--with-gettext \--enable-session \--with-curl \--with-jpeg-dir \--with-freetype-dir \--enable-opcache
./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-opcache
./configure --prefix=/usr/local/php7 --with-fpm-user=nginx --with-fpm-group=nginx --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-jpeg-dir --with-xmlrpc --with-xsl --with-zlib --with-bz2 --with-mhash --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-sysvshm --enable-xml --enable-zip --enable-fpm
在php-7.2.3中执行make
make完成后执行make install
错误:
若内存较小,比如1G,可手动设置虚拟内存
编译安装时出现下面的错误:
virtual memory exhausted: Cannot allocate memory
问题原因:由于物理内存本身很小,且阿里云服务器并没有分配swap空间,当物理内存不够用时,
物理内存中暂时不用的内容没地方转存。
解决方法:手动分配一个swap空间
dd if=/dev/zero of=/swap bs=1024 count=1M #创建一个大小为1G的文件/swap
mkswap /swap #将/swap作为swap空间
swapon /swap #enable /swap file for paging and swapping
echo "/swap swap swap sw 0 0" >> /etc/fstab #Enable swap on boot, 开机后自动生效
6.编译安装完后进行参数配置
vim /etc/profile
方法一:
将 pathmunge /usr/local/php7/bin 加入到对应位置
要使改动立即生效执行
. /etc/profile 或 source /etc/profile
方法二:
在末尾加入
PATH=$PATH:/usr/local/php7/bin
export PATH
要使改动立即生效执行
. /etc/profile 或 source /etc/profile
查看环境变量
echo $PATH
可以在随便一个目录执行 php -v 来查看全局是否配置好
代表配置完成7.配置php-fpm
cd /usr/local/php7/etc
cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php7/etc/php-fpm.d
cp www.conf.default www.conf
启动php-fpm
/usr/local/php7/sbin/php-fpm
8.配置php.ini
查看php启动是否加载php.ini
php -i | grep Configuration
执行
cd ~
cd php-7.2.4
cp php.ini-development /usr/local/php7/etc/php.ini
再次查看
查看php启动是否加载php.ini
php -i | grep Configuration
网友评论