安裝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-c++?autoconf?bison -y
第二步:
#創建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
#還可以去官網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 進程管理器(FPM)
進入PHP目錄
cd php-7.2.3/
編譯(將PHP編譯安裝到 /usr/local/php目錄下,帶上上圖的配置選項)(一下三種編譯方式,推薦第一種)
./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中執行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/php/bin? ?加入到對應位置
要使改動立即生效執行
????. /etc/profile 或 source /etc/profile
方法二:
????在末尾加入
????PATH=$PATH:/usr/local/php/bin
????export PATH
????要使改動立即生效執行
????. /etc/profile 或 source /etc/profile
????查看環境變量
????echo $PATH
可以在隨便一個目錄執行 php -v? 來查看全局是否配置好
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
? ? 配置啟動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啟動是否加載php.ini
php -i | grep Configuration
執行
cd ~
cd?php-7.2.4
cp php.ini-development /usr/local/php/etc/php.ini
再次查看
查看php啟動是否加載php.ini
php -i | grep Configuration