1. 下載源碼
$ mkdir /usr/downloads $ wget -c http://cn2.php.net/distributions/php-5.6.20.tar.gz $ tar -xvf php-5.6.20.tar.gz $ mv php-5.6.20 /usr/local/src $ cd !$ & cd php-5.6.20
2. 閱讀安裝指導
$ ls -also $ less README $ less INSTALL
3. 安裝依賴包
$ yum install apr apr-util apr-devel apr-util-devel prce lynx
4. 安裝httpd
$ wget -c http://apache.fayea.com//httpd/httpd-2.4.20.tar.gz $ tar -xvf httpd-2.4.20.tar.gz $ cd httpd-2.4.20 $ ./configure \ --prefix=/usr/local/programs/apache2 \ --enable-rewrite \ --enable-so \ --enable-headers \ --enable-expires \ --with-mpm=worker \ --enable-modules=most \ --enable-deflate \ --enable-module=shared $ make $ make install $ cd /usr/local/programs/apache2 $ cp bin/apachectl /etc/init.d/httpd ## 復制啟動腳本 $ /etc/init.d/httpd start ## 啟動apache服務器,訪問http://localhost/ $ egrep -v '^[ ]*#|^$' /usr/local/apache2/conf/httpd.conf | nl ## 查看apache服務器的配置 ## 將apache加入系統(tǒng)服務 vi /etc/rc.d/rc.local ``` /usr/local/programs/apache2/bin/apachectl start ``` $ cat /etc/rc.local
4. 安裝postgresql
立即學習“PHP免費學習筆記(深入)”;
$ yum install readline-devel ## 安裝readline依賴 $ cd /usr/downloads $ wget -c https://ftp.postgresql.org/pub/source/v9.5.0/postgresql-9.5.0.tar.bz2 $ tar -xvf postgresql-9.5.0.tar.bz2 $ cd postgresql-9.5.0 $ ./configure --prefix=/usr/local/programs/postgresql $ make $ su $ make install $ /sbin/ldconfig /usr/local/programs/postgresql/lib ## 刷新下共享動態(tài)庫 $ cd /usr/local/programs/postgresql $ bin/psql --version ## 檢查運行情況 ## 開始對postgresql的配置 $ vi /etc/profile.d/postgresql.sh ## 增加環(huán)境變量,不推薦直接在/etc/profile中添加,系統(tǒng)更新升級時會需要merge ``` PATH=/usr/local/programs/postgresql:$PATH export PATH ``` $ source /etc/profile ## 更新環(huán)境變量 ## 增加用戶和其他文件夾 $ adduser postgres $ passwd postgres $ mkdir /usr/local/programs/postgresql/logs $ mkdir /usr/local/programs/postgresql/data $ chown postgres /usr/local/programs/postgresql/data $ su - postgres ## 初始化數(shù)據(jù)庫 $ ./bin/initdb -D ./data $ ./bin/createdb test $ ./bin/psql test ## 已有數(shù)據(jù)庫,可導入data文件夾后嘗試root訪問,假如帶密碼,可能需要進一步研究下 $ ./bin/postgres -D ./data >./logs/start-log-1.log 2>&1 & $ ./bin/psql --list ##列出數(shù)據(jù)庫 ## ok,安裝完成 ## 自定義設置,權限控制等,可以跳過,等熟悉使用后再做 ## 編輯數(shù)據(jù)庫配置及權限文件: $ vi /usr/local/programs/postgresql/data/postgresql.conf ## 數(shù)據(jù)庫配置文件 $ chown postgres postgresql.conf $ chmod 644 postgresql.conf $ vi /usr/local/programs/postgresql/data/pg_hba.conf ## 權限文件 $ vi /usr/local/programs/postgresql/data/pg_ident.conf ## 設置開機自啟動: $ vi /etc/rc.d/rc.local ## 添加如下內容 ``` /usr/local/programs/postgresql/bin/postgresql start ```
5. 安裝php
## 源碼已經在第一步中下載,現(xiàn)在開始安裝: $ yum install libxml2 libxml2-devel libpng libpng-devel libjpeg libjpeg-devel freetype freetype-devel $ ./configure \ --prefix=/usr/local/programs/php \ --with-apxs2=/usr/local/programs/apache2/bin/apxs \ --with-zlib \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-freetype-dir \ --with-zlib-dir \ --enable-mbstring \ --with-pgsql=/usr/local/programs/postgresql \ --with-pdo-pgsql=/usr/local/programs/postgresql $ make $ make test > Bug #42718 (unsafe_raw filter not applied when configured as default filter) [ext/filter/tests/bug42718.phpt] XFAIL REASON: FILTER_UNSAFE_RAW not applied when configured as default filter, even with flags > Bug #67296 (filter_input doesn't validate variables) [ext/filter/tests/bug49184.phpt] XFAIL REASON: See Bug #49184 > Bug #53640 (XBM images require width to be multiple of 8) [ext/gd/tests/bug53640.phpt] XFAIL REASON: Padding is not implemented yet > zend multibyte (7) [ext/mbstring/tests/zend_multibyte-07.phpt] XFAIL REASON: https://bugs.php.net/bug.php?id=66582 > zend multibyte (9) [ext/mbstring/tests/zend_multibyte-09.phpt] XFAIL REASON: https://bugs.php.net/bug.php?id=66582 >Bug #70470 (Built-in server truncates headers spanning over TCP packets) [sapi/cli/tests/bug70470.phpt] XFAIL REASON: bug is not fixed yet ## 查閱官方的bug,發(fā)現(xiàn): > id=66582: status : Closed. Fixed in master (PHP7) > id=42718: status : Assigned > id=42718: reference to id=49184, unsolved for many years ## 那就不關心了,直接裝吧 $ make install > You may want to add: /usr/local/programs/php/lib/php to your php.ini include_path ## 那就按它說的設置吧 $ cp php.ini-development /usr/local/programs/php/lib/php.ini ``` include_path = ".;/usr/local/programs/php/lib/php" ## 然后,編輯httpd的設置,確保其能正確解析php文件 ``` ... LoadModule php5_module modules/libphp5.so ... AddType application/x-httpd-php .php AddType application/x-httpd-php-source .php5 ... <IfModule dir_module> DirectoryIndex index.html index.php </IfModule> ``` ## 重啟httpd,測試 $ cd /usr/local/programs/apache2 $ bin/httpd -h $ bin/httpd -k stop $ bin/httpd -f conf/httpd.conf ## 默認設置的www頁面在./htdocs/下,那就先去里面建一個測試頁面吧 $ vi htdocs/index.php ``` <?php phpinfo(); ?> ``` $ curl http://localhost/index.php |grep postgresql #ok
后續(xù)應該做的事
* 1. 啟動時,不需要要手動指定配置文件
* 2. php初始化www目錄設置
* 3. php 用戶、權限管理等
以上就介紹了centos 7下源碼編譯安裝php支持PostgreSQL,包括了postgresql,centos 7方面的內容,希望對PHP教程有興趣的朋友有所幫助。
PHP怎么學習?PHP怎么入門?PHP在哪學?PHP怎么學才快?不用擔心,這里為大家提供了PHP速學教程(入門到精通),有需要的小伙伴保存下載就能學習啦!
Copyright 2014-2025 http://m.miracleart.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號