編譯安裝PHP開發(fā)環(huán)境

Linux 系統(tǒng)為 CentOS 7.2


1. 安裝 Nginx
  1. 安裝 Nginx 依賴包:
# yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
  1. 安裝 Nginx:
# tar -xzvf nginx-1.10.1.tar.gz
# cd nginx-1.6.2                                       
# ./configure --prefix=/usr/local/nginx
# make && make install
  1. 啟動 Nginx:
# /usr/local/nginx/sbin/nginx
  1. 瀏覽器訪問服務(wù)器地址看是否成功,如果不能訪問則關(guān)閉防火墻:
# systemctl start firewalld.service   #啟動
# systemctl stop firewalld.service   #停止
# systemctl disable firewalld.service   #禁止 firewall 開機啟動

再次訪問成功:


nginx 安裝成功
  1. 設(shè)置開機啟動:
    新建 Nginx 服務(wù)文件;
# vim /lib/systemd/system/nginx.service 

保存以下內(nèi)容,并設(shè)置權(quán)限為 754;

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx start   # 如果報錯(nginx: invalid option: "start"), 則不加 start 參數(shù) 
ExecReload=/usr/local/nginx/sbin/nginx restart
ExecStop=/usr/local/nginx/sbin/nginx stop
PrivateTmp=true

[Install]
WantedBy=multi-user.target
# chmod 754 /lib/systemd/system/nginx.service
# systemctl enable nginx.service

重啟服務(wù)器,訪問瀏覽器成功。查看 Nginx 狀態(tài):

# systemctl status nginx.service
active nginx 服務(wù)正在運行

2. 安裝 PHP

參考自: http://blog.csdn.net/u010861514/article/details/51926575

  1. 解壓文件
# tar -xzf php-7.0.11.tar.gz
# cd php-7.0.11/
  1. 安裝依賴
# yum -y install gcc gcc-c++ libxml2 libxml2-devel bzip2 bzip2-devel libmcrypt libmcrypt-devel openssl openssl-devel libcurl-devel libjpeg-devel libpng-devel freetype-devel readline readline-devel libxslt-devel perl perl-devel psmisc.x86_64 recode recode-devel libtidy libtidy-devel

如果 yum 安裝不了,則下載無法安裝的包手動編譯安裝,如下:
libmcrypt 下載地址:http://sourceforge.net/projects/mcrypt/files/Libmcrypt/

# tar -xzvf libmcrypt-2.5.8.tar.gz
# cd libmcrypt-2.5.8
# ./configure
# make && make install

libtidy 下載地址:http://fr.rpmfind.net/linux/rpm2html/search.php?query=libtidy&submit=Search+...
rpm 包安裝:

# rpm -ivh libtidy-5.1.25-1.fc25.i686.rpm
  1. 編譯與配置
    --prefix=/usr/local/php7 主程序文件路徑
    --sysconfdir=/etc/php7 配置文件路徑
    --with-config-file-path=/etc/php7 php.ini 文件路徑
# ./configure --prefix=/usr/local/php7 --sysconfdir=/etc/php7 --with-config-file-path=/etc/php7 --enable-fpm --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mhash --with-openssl --with-zlib --with-bz2 --with-curl --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-zlib --enable-mbstring --with-mcrypt --enable-sockets --with-iconv-dir --with-xsl --enable-zip --with-pcre-dir --with-pear --enable-session  --enable-gd-native-ttf --enable-xml --with-freetype-dir --enable-gd-jis-conv --enable-inline-optimization --enable-shared --enable-bcmath --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-mbregex --enable-pcntl --with-xmlrpc --with-gettext --enable-exif --with-readline --with-recode --with-tidy

# make
# make install

如果編譯出錯,則網(wǎng)上查找解決方案。

  1. 安裝成功后拷貝源碼包中的 php.ini-development 文件到 PHP 配置文件目錄
# cp php.ini-development /etc/php7/php.ini
  1. fastcgi php-fpm
# cp /etc/php7/php-fpm.conf.default /etc/php7/php-fpm.conf
# cp /etc/php7/php-fpm.d/www.conf.default /etc/php7/php-fpm.d/www.conf
# vi /etc/php7/php-fpm.d/www.conf  

www.conf 默認即可是本機 127.0.0.1 不必修改。

# 監(jiān)聽地址  
listen = 127.0.0.1:9000  
# 允許的客戶端  
listen.allowed_clients = 127.0.0.1 
  1. 啟動 PHP
# vi /etc/php7/php-fpm.conf  

// 打開注釋:(不打開注釋僅能使用 killall php-fpm 關(guān)閉 php)  
pid = run/php-fpm.pid 

// 啟動:  
# /usr/local/php7/sbin/php-fpm  

// 立刻終止  
# kill -INT `cat /usr/local/php7/var/run/php-fpm.pid`  
# kill -TERM `cat /usr/local/php7/var/run/php-fpm.pid`  
# killall php-fpm  

// 平滑終止  
# kill -QUIT `cat /usr/local/php7/var/run/php-fpm.pid`  

// 平滑重啟  
# kill -USR2 `cat /usr/local/php7/var/run/php-fpm.pid`
  1. 加入環(huán)境變量
# vim /etc/profile

末尾添加:
export PATH=$PATH:/usr/local/php7/sbin:/usr/local/php7/bin

# source /etc/profile     立即生效
  1. 設(shè)置開機啟動
# vim /lib/systemd/system/php-fpm.service
# chmod 754 /lib/systemd/system/php-fpm.service
# systemctl enable php-fpm.service

文件內(nèi)容:

[Unit]
Description=php-fpm
After=syslog.target network.target
[Service]
Type=forking
ExecStart=/usr/local/php7/sbin/php-fpm
ExecReload=/bin/kill -USR2 $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

PHP 服務(wù)相關(guān)命令:

# systemctl daemon-reload        修改 serivce 文件后,需要刷新配置文件
# systemctl (start | restart | reload | stop | enable | disable | status) php-fpm.service

若果報錯(ERROR: unable to bind listening socket for address ...)先把所有 PHP 進程殺掉,然后重啟:

# killall php-fpm
# systemctl start php-fpm.service
  1. 配置 Nginx 訪問 PHP
# vim /usr/local/nginx/conf/nginx.conf

### 編輯 server 讓 Nginx 支持php:
server {
       listen       80;
       server_name  localhost;

       location / {
           root   html;
           index  index.html index.htm index.php;
       }
       error_page   500 502 503 504  /50x.html;
       location = /50x.html {
           root   html;
       }

       location ~ \.php$ {
           root           html;
           fastcgi_pass   127.0.0.1:9000;
       fastcgi_index  index.php;
           fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
           include        fastcgi_params;
       }
   }

訪問 PHP 文件,在 Nginx 的 html 目錄下創(chuàng)建一個 PHP 文件,訪問該文件查看配置信息:

php 安裝成功

3. 安裝 PostgreSql
  1. 安裝依賴包
# yum install -y gcc.x86_64 glibc.x86_64 glibc-devel.x86_64 vim-enhanced.x86_64 gcc-java apr apr-devel openssl openssl-devel libgcc.x86_64 java-1.8.0-openjdk.x86_64 java-1.8.0-openjdk-devel.x86_64 perl-Module-Install.noarch readline-devel.x86_64
  1. 創(chuàng)建 postgres 用戶(一定要創(chuàng)建,不然 root 用戶不能啟動數(shù)據(jù)庫)
# adduser postgres
  1. 解壓編譯安裝
# tar -xzvf postgresql-9.6.0.tar.gz
# cd postgresql-9.6.0
# ./configure --prefix=/usr/local/pgdb --enable-thread-safety
# make 
# make install
  1. 設(shè)置權(quán)限
# chown -R postgres.postgres /usr/local/pgdb/
  1. 配置 PostgreSql
    ======= 以下操作必須在 postgres 用戶下完成=======
    切換用戶
# su postgres
$ cd ~     切換到用戶目錄

編輯 .bash_profile 添加以下內(nèi)容

$ vim .bash_profile

# 添加以下內(nèi)容,配置 PGDATA 變量
PGHOME=/home/postgres
export PGHOM
PGDATA=$PGHOME/data
export PGDATA

初始化數(shù)據(jù)文件

$ cd /usr/local/pgdb
$ mkdir data
$ cd /usr/local/pgdb/bin
$ ./initdb -D ../data             初始化數(shù)據(jù)文件
$ ./pg_ctl -D ../data start       啟動數(shù)據(jù)庫服務(wù),其中-D選項指定文件存放目錄為上一步中生成的data目錄

數(shù)據(jù)庫操作

$ ./createdb test       創(chuàng)建數(shù)據(jù)庫 test
$ ./psql test           訪問 test
創(chuàng)建 test 成功
最后編輯于
?著作權(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)容