Centos手動安裝PHP

下載PHP的源碼,我下的是7.2版本,看了一下安裝的參數太多了,也沒有時間依次瞭解每一個參數的意思,直接從網上覆制了一個,先嚐試安裝起來。並記錄一下步驟,基本的步驟就是解壓、配置、編譯、運行。
1.下載PHP源碼,將其放到某個目錄下,好比~/temp
2.接下來準備運行configure,嘗試了無數次,基本快崩潰,由於每次老是提示缺乏某個支持庫。總結下來有如下一些,
curl,freetype,glib,libcurl,libjpeg,libmcrypt,libpng,libxml2,libXpm,libxslt,openssl,postgresql,bzip2,先把這些庫安裝完畢,接下來進入正文。
3.在源碼目錄下運行這個很長的配置命令php

'./configure' '--prefix=/usr/local/php' '--with-pdo-pgsql' '--with-zlib-dir' '--with-freetype-dir' '--enable-mbstring' '--with-libxml-dir=/usr' '--enable-soap' '--enable-calendar' '--with-curl' '--with-mcrypt' '--with-gd' '--with-pgsql' '--disable-rpath' '--enable-inline-optimization' '--with-bz2' '--with-zlib' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-pcntl' '--enable-mbregex' '--enable-exif' '--enable-bcmath' '--with-mhash' '--enable-zip' '--with-pcre-regex' '--with-pdo-mysql' '--with-mysqli' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--with-openssl' '--with-fpm-user=www-data' '--with-fpm-group=www-data' '--with-libdir=/lib/x86_64-linux-gnu/' '--enable-ftp' '--with-gettext' '--with-xmlrpc' '--with-xsl' '--enable-opcache' '--enable-fpm' '--with-iconv' '--with-xpm-dir=/usr'32]# './configure' '--prefix=/usr/local/php' '--with-pdo-pgsql' '--with-zlib-dir' '--with-freetype-dir' '--enable-mbstring' '--with-libxml-dir=/usr' '--enable-soap' '--enable-calendar' '--with-curl' '--with-mcrypt' '--with-gd' '--with-pgsql' '--disable-rpath' '--enable-inline-optimization' '--with-bz2' '--with-zlib' '--enable-sockets' '--enable-sysvsem' '--enable-sysvshm' '--enable-pcntl' '--enable-mbregex' '--enable-exif' '--enable-bcmath' '--with-mhash' '--enable-zip' '--with-pcre-regex' '--with-pdo-mysql' '--with-mysqli' '--with-jpeg-dir=/usr' '--with-png-dir=/usr' '--enable-gd-native-ttf' '--with-openssl' '--with-fpm-user=www-data' '--with-fpm-group=www-data' '--with-libdir=/lib/x86_64-linux-gnu/' '--enable-ftp' '--with-gettext' '--with-xmlrpc' '--with-xsl' '--enable-opcache' '--enable-fpm' '--with-iconv' '--with-xpm-dir=/usr'mysql

崩潰不,都不知道這麼多參數幹嗎用的,但不管如何,運行成功了,沒有提示錯誤。linux

4.在PHP解壓目錄下運行make && make install, 又提示libtool: link: `ext/opcache/ZendAccelerator.lo' is not a valid libtool object錯誤,Ok, 查找網上資料,運行make distclean。而後從新make,提示找不到make file。查不到資料了,幸虧咱有虛擬機快照,恢復快照,從新安裝所需的庫文件,從新configure,總算成功。sql

5.make成功後,到安裝路徑下運行php -version,正常顯示版本號。將此路徑加入到系統路徑變量中,
vi /etc/profile
在最後加入PHP路徑,
PATH=$PATH:/usr/local/php/bin
export PATH
保存後,在任意地方嘗試運行php -version成功。apache

6.接下來,將PHP加入到apache中,
vim /etc/httpd/conf/httpd.conf
//在LoadModule後面添加:LoadModule php7_module modules/libphp7.so //不添加則訪問.php文件將會變成下載,正常這個應該是自動添加纔對
//在DirectoryIndex後面添加:index.php
//在AddType application/x-gzip .gz .tgz後面添加:AddType application/x-httpd-php .php //.php前面有一個空格
重啓Apache服務,提示失敗,找不到libphp7.so,再查資料吧,先刪除LoadModule行。看看應該是在編譯php時要加入apxs路徑參數,才能促成生成libphp7.so,而apxs須要安裝依賴包httpd-devel。安裝httpd-devel,須要httpd和httpd-tools,所有下載安裝完畢。
從新編譯php,./configure --with-apxs2=/usr/bin/apxs,成功後,再次make && make install
好事,沒發現任何錯誤,到httpd.conf中查看,發現LoadModule 這句話已經自動加上了。中止並重啓apache服務,測試PHP網頁,一切正常。vim

相關文章
相關標籤/搜索