CentOS7.4 源碼安裝LAMP

源碼安裝Apache和MySQL之前已經(jīng)寫過,見鏈接:
源碼安裝Apache:http://www.itdecent.cn/p/35cb6c00402c
源碼安裝MySQL:http://www.itdecent.cn/p/41ac166ef477

一、下載文件(本文安裝的PHP版本為7.2.4)

官網(wǎng)下載地址:http://www.php.net/

1、下載文件

 [root@VM data]# wget http://cn.php.net/distributions/php-7.2.4.tar.gz

2、檢查文件sha256值是否匹配:若不匹配需重新下載

[root@VM download]# openssl dgst -sha256 php-7.2.4.tar.gz
SHA256(php-7.2.4.tar.gz)= 58e28e978baea0fe9009432bcb436934eaacccfdcb5f5409c7526431a595857b

3、解壓文件

[root@VM download]# tar -vxzf php-7.2.4.tar.gz

二、編譯和安裝

1、安裝運行依賴(編譯報錯發(fā)現(xiàn)的,先裝一下)

依次運行以下命令:

1.開啟curl擴展
yum -y install libcurl  curl-devel

2.開啟bz2擴展
yum -y install bzip2 bzip2-devel

3.開啟openssl擴展
yum -y install openssl openssl-devel

4.開啟gd擴展
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel

5.開啟xml擴展
yum -y install libxml2 libxml2-devel

2、進入到解壓文件目錄,依次運行以下命令:

[root@VM php-7.2.4] ./configure --prefix=/usr/local/php7 --with-pdo-mysql=mysqlnd --with-openssl --with-mysqli=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache2/bin/apxs  --with-gd --with-openssl --with-curl  --enable-fpm --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts  --disable-fileinfo
[root@VM php-7.2.4] make
[root@VM php-7.2.4] make install
參數(shù)解釋
--prefix=/usr/local/php7  # 指定php安裝的路徑
--with-pdo-mysql=mysqlnd --with-openssl # 指定mysql的安裝目錄  #支持ssl功能
--with-mysqli=mysqlnd # 可以讓mysql與php結(jié)合的接口
--enable-mbstring --with-freetype-dir  # 指定可以支持中文非一個字節(jié)能表示語言  # 加載freetype的頭文件,可以支持不同字體
--with-jpeg-dir --with-png-dir # 支持jpep格式圖片 #支持pnp格式圖片
--with-zlib --with-libxml-dir=/usr # 支持壓縮庫  # 指定xml的庫路徑
--enable-xml  --enable-sockets  #支持?jǐn)U展標(biāo)記語言  # 支持套接字的通信功能
--with-apxs2=/usr/local/apache2/bin/apxs  #指定apsx2配置目錄
--with-config-file-path=/etc    # 指定php配置文件的路徑(/etc/php.ini)
--with-config-file-scan-dir=/etc/php.d  # 支持php文件的附件配置文件(/etc/php.d/*.ini)
--with-bz2  --enable-maintainer-zts #支持bz2的壓縮庫  # 此選項是否安裝取決于你的Apache工作的mpm模式(【prefork不需要加載】【event或work
mpm工作模式必須要加此選項】 驗證Apache mpm工作模式命令:httpd -M )
--disable-fileinfo  #可不加,若安裝時出現(xiàn)內(nèi)存不足報錯需要,錯誤信息:make: *** [ext/fileinfo/libmagic/apprentice.lo] Error 1

3、拷貝配置文件

[root@VM php-7.2.4] cp php.ini-development /etc/php.ini

三、整合apache+php環(huán)境

修改httpd.conf配置文件(/usr/local/apache2/conf),加入如下語句:

LoadModule php7_module    modules/libphp7.so  (默認已存在)

AddType  application/x-httpd-php .php .phtml

#配置文件中已有,需把index.php加入index.html之前
<IfModule dir_module>
    DirectoryIndex index.php index.html 
</IfModule> 

四、測試驗證

在/usr/local/apache2/htdocs目錄下創(chuàng)建index.php測試頁面,執(zhí)行如下命令:

vim  /usr/local/apache2/htdocs/index.php
#添加以下語句 
<?php
phpinfo();
?>

重新啟動apache服務(wù),通過IP訪問界面如下圖,即代表LAMP環(huán)境搭建成功。


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

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

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