1. 程式人生 > >Linux 下搭建 php 開發環境完整教程

Linux 下搭建 php 開發環境完整教程

一、 安裝 apache 1. 配置(apache 安裝配置) 在安裝前記得切換到 root ,否則會因許可權問題安裝失敗 ./configure --prefix=/usr/local/http2 \ --enable-modules=all \ --enable-mods-shared=all \ --enable-so // --enable-mods-shared=all 模組共享型別,一次性編譯所有模組到 apache 內 執行./configure --help可檢視預設配置及配置幫助資訊,如安裝目錄 --prefix 等 2. 安裝 執行 make && make install 就完成安裝了 3. 啟動 apache
進入到安裝目錄 /usr/local/http2/bin 執行命令 ./apachectl start 可啟動 apache 啟動 apache 的時候,可能會提示 Could not reliably determine the server's fully ... 其實這不是什麼錯誤,可忽略,也可通過修改配置檔案解決這個問題, 進入安裝目錄,/usr/local/http2/conf/ 找到 httpd.conf ,在該檔案中查詢 ServerName, 把它前面的 # 號去掉就行了 。 4. 訪問 安裝完成後,在瀏覽器中輸入本機 ip 地址,即可訪問到 apache 預設的頁面 如輸入本機 ip :192.168.0.141 二、 安裝 php 的依賴軟體
現在要把 php 依賴的一些軟體(xml、gd、jpeg、png、freetype)都安裝上去 ,然後才能安裝 php 。 1. 安裝 xml 依賴 下載 libxml2,然後安裝 安裝前配置:./configure --prefix=/usr/local/libxml2 --without-zlib 然後 make&&make install 2. 安裝 jpeg8 安裝前配置 ./configure --prefix=/usr/local/jpeg --enable-share --enable-static 然後 make && make install --enable-share 把 jpeg 需要的函式庫程式都編譯到該軟體裡面,這樣函式呼叫速度快,但是軟體本身比較大 --enable-static 靜態引入方式,這樣當需要呼叫還沒引入的函式時,會立即 include 進來,這樣軟體本身比較小,但是函式呼叫速度慢
3. 安裝 libpng
./configure && make && make install 4. 安裝 freetype 庫(字型庫) ./configure --prefix=/usr/local/freetype make && make install 5. 安裝 GD 庫 ./configure --prefix=/usr/local/gd --with-jpeg=/usr/local/jpeg/ --with-png --with-zlib --with-freetype=/usr/local/freetype make && make install 6. 安裝 libXpm-3.5.10 // 有的系統可能沒安裝這個,要自己安裝
直接用預設的配置就行 ./configure make && make instsall 三、安裝配置 php 1. 安裝 php 引數解析: ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/http2/bin/apxs apache 的支援,作用: 給 apache 生成 php 模組;修改 /usr/local/http2/conf/httpd.conf 的配置檔案,使其引入 php 模組 mysqlnd 表示啟用 php 本身的 mysql 驅動並使用,因還我們還沒自己安裝 mysql,所以這樣可用預設的 mysql 。 --enable-mbstring=all 寬位元組函式庫對 php 的支援
./configure --prefix=/usr/local/php      --with-apxs2=/usr/local/http2/bin/apxs
    --with-mysql=mysqlnd     --with-pdo-mysql=mysqlnd     --with-mysqli=mysqlnd     --with-freetype-dir=/usr/local/freetype     --with-gd=/usr/local/gd     --with-zlib     --with-libxml-dir=/usr/local/libxml2     --with-jpeg-dir=/usr/local/jpeg     --with-png-dir    --with-xpm-dir=/usr/local/libxpm     --enable-mbstring=all     --enable-mbregex     --enable-shared 配置完成後,安裝 make && make install 安裝成功後,會出現如下提示