Linux編譯安裝PHP7

安裝PHP

1、去PHP官網(wǎng)http://php.net/找到對(duì)應(yīng)的版本



http://hk1.php.net/get/php-7.2.3.tar.gz/from/this/mirror

2、執(zhí)行命令下載(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-c++?autoconf?bison -y

第二步:

#創(chuàng)建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

#下載編譯安裝(1.2版本)

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

#還可以去官網(wǎng)https://libzip.org/download/ 下載編譯安裝1.5版本

1、安裝cmake3

yum remove cmake -y

yum install -y cmake3

sudo ln -sf /usr/bin/cmake3 /usr/bin/cmake

2、安裝libzip-1.5.2

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

5、安裝 FastCGI 進(jìn)程管理器(FPM)


進(jìn)入PHP目錄

cd php-7.2.3/

編譯(將PHP編譯安裝到 /usr/local/php目錄下,帶上上圖的配置選項(xiàng))(一下三種編譯方式,推薦第一種)

./configure --prefix=/usr/local/php \--with-config-file-path=/usr/local/php/etc \--with-config-file-scan-dir=/usr/local/php/etc/php.d \--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/php --with-config-file-path=/usr/local/php/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/php''--with-config-file-path=/usr/local/php/etc' '--with-config-file-scan-dir=/usr/local/php/etc/' '--enable-inline-optimization' '--enable-opcache' '--enable-session' '--enable-fpm' '--with-fpm-user=nobody' '--with-fpm-group=nobody' '--with-mysqli=mysqlnd' '--with-pdo-mysql=mysqlnd' '--with-pdo-sqlite' '--with-sqlite3' '--with-gettext' '--enable-mbregex' '--enable-mbstring' '--enable-xml' '--with-iconv' '--with-mhash' '--with-openssl' '--enable-bcmath' '--enable-soap' '--with-xmlrpc' '--with-libxml-dir' '--enable-pcntl' '--enable-shmop' '--enable-sysvmsg' '--enable-sysvsem' '--enable-sysvshm' '--enable-sockets' '--with-curl' '--with-zlib' '--enable-zip' '--with-bz2' '--with-gd' '--with-jpeg-dir' '--with-png-dir' '--with-freetype-dir' '--with-iconv-dir' '--with-readline' '--with-pear'

在php-7.2.3中執(zhí)行make

make完成后執(zhí)行make install

錯(cuò)誤:

若內(nèi)存較小,比如1G,可手動(dòng)設(shè)置虛擬內(nèi)存

編譯安裝時(shí)出現(xiàn)下面的錯(cuò)誤:

virtual memory exhausted: Cannot allocate memory

問(wèn)題原因:由于物理內(nèi)存本身很小,且阿里云服務(wù)器并沒(méi)有分配swap空間,當(dāng)物理內(nèi)存不夠用時(shí),

? ? ? ? ? ? ? 物理內(nèi)存中暫時(shí)不用的內(nèi)容沒(méi)地方轉(zhuǎn)存。

解決方法:手動(dòng)分配一個(gè)swap空間

dd if=/dev/zero of=/swap bs=1024 count=1M ? ?#創(chuàng)建一個(gè)大小為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, 開(kāi)機(jī)后自動(dòng)生效

6.編譯安裝完后進(jìn)行參數(shù)配置

????vim /etc/profile

方法一:

將 pathmunge?/usr/local/php/bin? ?加入到對(duì)應(yīng)位置


要使改動(dòng)立即生效執(zhí)行

????. /etc/profile 或 source /etc/profile

方法二:

????在末尾加入

????PATH=$PATH:/usr/local/php/bin

????export PATH

????要使改動(dòng)立即生效執(zhí)行

????. /etc/profile 或 source /etc/profile

????查看環(huán)境變量

????echo $PATH

可以在隨便一個(gè)目錄執(zhí)行 php -v? 來(lái)查看全局是否配置好


代表配置完成

7.配置php-fpm

????cd /usr/local/php/etc

????cp php-fpm.conf.default php-fpm.conf

? ??cd /usr/local/php/etc/php-fpm.d

? ? cp?www.conf.default?www.conf

? ? 配置啟動(dòng)php-fpm

????cd ~

? ? cd?php-7.2.3

? ? cp?php-7.2.3/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm

? ? chmod -R +x?/etc/init.d/php-fpm

? ? 操作

????/etc/init.d/php-fpm start

? ??/etc/init.d/php-fpm restart

? ??/etc/init.d/php-fpm stop

8.配置php.ini

查看php啟動(dòng)是否加載php.ini

php -i | grep Configuration


執(zhí)行

cd ~

cd?php-7.2.4

cp php.ini-development /usr/local/php/etc/php.ini

再次查看

查看php啟動(dòng)是否加載php.ini

php -i | grep Configuration


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容