PHP運行環境配置及需求

構建PHP運行環境

在搭建PHP的前提把Apache,MySQL搭建完成。

安裝PHP軟件包(手工編譯安裝)

1:安裝GD庫和GD庫關聯程序 //用來處理和生成圖片//

[root@localhost lamp]# yum install \
> libjpeg-devel \
> libpng-devel \
> freetype-devel \
> zlib-devel \
> gettext-devel \
> libXpm-devel \
> libxml2-devel \
> fontconfig-devel \
> openssl-devel \
> bzip2-devel -y

2:解壓gd庫和編譯

[root@localhost lamp] tar zxvf /opt/lamp/gd-2.0.35.tar.gz -C /opt/
[root@localhost lamp] cd ../gd/2.0.35/
[root@localhost 2.0.35] ./configure --prefix=/usr/local/gd
[root@localhost 2.0.35] make && make install

3:解壓PHP源代碼包並安裝編譯

[root@localhost php-5.5.38] tar zxvf /opt/lamp/php-5.5.38.tar.gz -C /opt/
[root@localhost php-5.5.38] ./configure \
> --prefix=/usr/local/php \
> --with-apxs2=/usr/local/httpd/bin/apxs \
> --with-gd \
> --with-mysql=/usr/local/mysql \
> --with-config-file-path=/etc \
> --enable-sqlite-utf8 \
> --with-zlib-dir \
> --with-libxml-dir \
> --with-freetype-dir \
> --with-jpeg-dir \
> --with-png-dir \
> --with-ttf \
> --with-iconv \
> --with-openssl \
> --with-gettext \
> --enable-mbstring \
> --enable-gd-native-ttf \
> --enable-gd-jis-conv \
> --enable-static \
> --enable-zend-multibyte \
> --enable-inline-optimization \
> --enable-sockets \
> --enable-soap \
> --enable-ftp \
> --disable-ipv6
[root@localhost php-5.5.38] make && make install

4:讓Apache支持PHP

#找到 AddType application/x-gzip .gz .tgz 在下面添加如下內容
[root@localhost ~] vim /usr/local/apache/conf/httpd.conf
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
# 搜索php5有沒有下面這個配置
    LoadModule php5_module        modules/libphp5.so
# 找到這個標籤在index.html後面加入index.php
<IfModule dir_module>  
    DirectoryIndex index.html index.php
</IfModule>

重新啓動httpd服務

[root@localhost ~] systemctl restart httpd.service

加入php測試頁面

[root@localhost ~] cd /usr/local/httpd/htdocs/
[root@localhost htdocs] ls
index.html
[root@localhost htdocs] vim index.html 
<h1>accp</h1>    #刪除原有編輯的首頁如果沒有就不用
#加入下面的php測試頁面
<?php
phpinfo();
?>
[root@localhost htdocs] mv index.html index.php #修改原有html結尾的首頁名稱改爲php結尾
[root@localhost htdocs] ls
index.php

PHP搭建好後可是進行Apache的網頁優化,自己可以先嚐試搭建一個論壇下一個博客會講到搭建簡單的論壇

下面打開網頁測試一下

如過不能訪問查看一下防火牆有沒有關
PHP運行環境配置及需求

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章