1. 程式人生 > >Centos7 安裝 php7.0.16 遇到的一些問題

Centos7 安裝 php7.0.16 遇到的一些問題

安裝PHP-7.0.16

  • 1、下載安裝包 並解壓
  • 2、安裝一些需要的依賴包

    yum install openssl
    yum install libssl-dev
    yum install libjpeg-devel
    yum install libpng-devel

  • 3、cd 到解壓後的目錄

  • 4、編譯
./configure --prefix=/usr/local/php --enable-fpm --enable-inline-optimization --enable-debug --disable-rpath --enable-shared --enable-opcache
--with-pdo-mysql --with-mysqli --with-mysql-sock --enable-pdo --with-pdo-mysql --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --
enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --enable-bzip2 --with-readline --without-sqlite3 --without-pdo-sqlite --with-pear --with-libdir=/lib/x86_64-linux-gnu --with-gd --with-jpeg-dir=/usr/lib --enable-gd-native-ttf --enable-xml
  • 編譯時可能出現的錯誤
    1、xml2-config 這個配置找不到
yum install libxml2-devel -y
sudo
find / -name "xml2-config" #查詢是否存在,存在說明安裝成功
wget ftp://mcrypt.hellug.gr/pub/crypto/mcrypt/attic/libmcrypt/libmcrypt-2.5.7.tar.gz
tar -zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
sudo ./configure --prefix=/usr/local
make
make install
  • 3、configure: error: Don’t know how to define struct flock on this system, set –enable-opcache=no
    出現這個問題的原因可能是:
    1、手動編譯了libmcrypt
    2、編譯時打開了 –enable-opcache 導致編譯不通過
    參考地址1
    參考地址2
vim /etc/ld.so.conf 時,加入內容 /usr/local/lib  前面不要加 include
編譯仍不成功 加入以下連結
ln -s /usr/local/mysql/lib/libmysqlclient.so /usr/lib/

ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.20
  • 4、找不到 readline.h
yum install readline readline-devel
如果下載不到 更新 yum 源 
yum源 位置/etc/yum.repos.d
  • 5、configure: WARNING: unrecognized options: –with-mysql
# 是因為 php不支援 mysql模組 要改為
--with-pdo-mysql
  • 6、configure: WARNING: unrecognized options: –enable-bz2
安裝  yum install bzip2 bzip2-devel
編譯時 加上 --with-bz2 --enable-bzip2
  • 7 如果編譯成功
make && make test (這一步需要點時間, php要自動測試)
make && sudo make install
  • 8 對php-fpm進行配置
    cd 到解壓後的php7目錄
sudo cp php.ini-production /usr/local/php/etc/php.ini 
sudo cp sapi/fpm/init.d.php-fpm /etc/init.d/php7-fpm

把 php-fpm.conf.default 複製為 php-fpm.conf

cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf

把 www.conf.default 複製為 www.conf

cd /usr/local/php/etc/php-fpm.d
cp www.conf.default www.conf
  • 配置php-fpm
cd /usr/local/php/etc
vim php-fpm.conf

找到 include=/usr/local/php/etc/php-fpm.d/*.conf
將 前面的分號去掉, 
沒有這段程式碼就加上, 注意路徑
  • 配置 www.conf
cd /usr/local/php/etc/php-fpm.d 
找到: listen = /var/run/php-fpm.socket 
//把分號去掉 改為
listen = 127.0.0.1:9000 (如果預設等於 127.0.0.1:9000, 就不管)
  • 啟動php-fpm
sudo /usr/local/php/sbin/php-fpm
  • 關閉php-fpm
方法1:killall php-fpm
方法2:用service 管理 php-fpm, nginx也一樣。
    service php-fpm [start|stop|restart]

centos下 啟動 nginx:
    啟動:service nginx
    停止:service nginx -s stop
  • 檢視監聽埠
netstat -an | grep LISTEN | grep 9000

編譯安裝nginx-1.11.10

參考地址
新建匿名使用者和使用者組

新建的使用者組和使用者主要是在編譯配置的時候指定nginx執行的使用者和使用者組。這樣指定後以後配置使用也方便。

sudo groupadd -r nginx
sudo useradd -s /sbin/nologin -g nginx -r nginx
  • 下載原始碼包
wget http://nginx.org/download/nginx-1.11.10.tar.gz
  • 解壓並編譯
    解壓
tar -zxvf nginx-1.11.10.tar.gz

準備編譯

./configure --prefix=/usr/local/nginx --conf-path=/usr/local/nginx/conf/nginx.conf --user=nginx --group=nginx

如果沒有錯誤可以看到下面的顯示

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used
  + md5: using system crypto library
  + sha1: using system crypto library
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/etc/nginx"
  nginx configuration file: "/etc/nginx/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"
在Ubuntu下可能提示需要安裝 PCRE, Nginx的HTTP模組需要用它解析正則表示式
sudo apt-get install libpcre3 libpcre3-dev

開始編譯安裝

make && make install #根據自己都許可權,新增 sudo
  • 新增nginx 為開機啟動
    參考地址
    在centos 7 下 使用 chkconfig –add nginx 無法新增
    使用 Systemd 為nginx設定開機啟動

在系統服務目錄裡建立nginx.service檔案

vi /lib/systemd/system/nginx.service

新增如下內容 啟動、關閉、重啟都必須是絕對地址

[Unit]
Description=nginx
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

[Unit]:服務的說明
Description:描述服務
After:描述服務類別
[Service]服務執行引數的設定
Type=forking是後臺執行的形式
ExecStart為服務的具體執行命令
ExecReload為重啟命令
ExecStop為停止命令
PrivateTmp=True表示給服務分配獨立的臨時空間
注意:[Service]的啟動、重啟、停止命令全部要求使用絕對路徑
[Install]執行級別下服務安裝的相關設定,可設定為多使用者,即系統執行級別為3

儲存退出。

  • 設定開機啟動 停止開機啟動
systemctl enable nginx.service //啟動
systemctl disable nginx.service //停止
  • 啟動nginx服務
systemctl start nginx.service //啟動
systemctl restart nginx.service //重啟
//檢視nginx服務當前狀態
systemctl status nginx.service

//檢視已啟動的服務
systemctl list-units --type=service