ラベル PHP の投稿を表示しています。 すべての投稿を表示
ラベル PHP の投稿を表示しています。 すべての投稿を表示

2017年1月12日木曜日

AWS Centos6.5 nginx php-fpm インストール

  • このエントリーをはてなブックマークに追加


AWS Centos6.5 nginx php-fpm インストール AWSのEC2(CentOS 6.5)にnginx、PHP-fpmのインストール手順をメモしておきます。

nginx install

sudo sudo rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
sudo yum install nginx

php-fpm install

sudo yum install php
yum list | grep php-fpm

php-fpm 設定

sudo cp -p /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.org
sudo sed -i -e 's/user = apache/user = nginx/' /etc/php-fpm.d/www.conf

sudo sed -i -e 's/group = apache/group = nginx/' /etc/php-fpm.d/www.conf

直接viで編集してもよい。ユーザー、groupをnginxに変更

nginx 設定

例:rootディレクトリを/var/www/htmlにする
sudo cp -p /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.org
以下の様な感じで変更
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /var/www/html;
        index  index.php index.html index.htm;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /var/www/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /var/www/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

起動

sudo /etc/init.d/php-fpm start
sudo /etc/init.d/nginx start

自動起動を設定
sudo chkconfig nginx on
sudo chkconfig php-fpm on

動作確認

sudo echo '' > /var/www/html/phpinfo.php
この状態だと、アクセス拒否されてできないです。
AWSインスタンスで既定でiptables,ip6tablesが有効になっているからです。
無効にする
sudo /etc/init.d/iptables stop
sudo /etc/init.d/ip6tables stop
sudo chkconfig iptables off
sudo chkconfig ip6tables off
以上でnginxとphp連携できた。

2016年2月1日月曜日

php7 memcachedインストール失敗

  • このエントリーをはてなブックマークに追加


php7の環境にmemcachedを入れようとするとエラーが出ました。バグみたい。
●libmemcachedインストール
http://libmemcached.org/libMemcached.html  からダウンロードし解凍してインストール

./configure
make
make install  (g++が必要なので、・yum install gcc-c++)
●memcachedインストール
make の時に ,以下の様なエラーが表示される
In file included from /tmp/php-memcached/php_memcached.c:26:0: 
/tmp/php-memcached/php_memcached_private.h:44:40: fatal error: ext/standard/php_smart_str.h: No such file or directory
#include <ext/standard/php_smart_str.h>
php7でmemcachedがまだサポートされていないみたい。失敗する
参照リンク
https://bugs.php.net/bug.php?id=71139






2015年10月11日日曜日

PHP4でsimplexml_load_file()と同等の機能を実装

  • このエントリーをはてなブックマークに追加


最近、仕事でXMLファイルを加工するPHPスクリプトを書いています。テスト環境で、PHP5でしたので、simplexml_load_file()を使って、ファイルをロードし、XML各要素の値を出しています。
こちらsimplexml_load_fileの紹介をご参照ください。
基本的な SimpleXML の使用法 ¶


しかし、本番環境に持って行ったら、なんとPHPのバージョンは4点台だった。参りましたね。スクリプトを書く前にきちんと本番環境を確認しないと、実感しました。

で、PHPのバージョンも上げるのかありだが、それはちょっと影響範囲が大きいため、諦めた。そして、simplexml_load_file()のような機能がPHP4であるかどうか調べたら、ありましたよ。助かりました。

Implementation of simplexml_load_file() in PHP4

miniXMLというライブラリを使えば実現できます。
miniXMLはこちらからダウンロードしてください。
http://sourceforge.net/projects/minixml/


自分で簡単にサンプルコードも作ってみました。
======================================================
<?php
/* xml sample file
<?xml version='1.0' standalone='yes'?>
<movies>
 <movie>
  <title>PHP: Behind the Parser</title>
  <characters>
   <character>
    <name>Ms. Coder</name>
    <actor>Onlivia Actora</actor>
   </character>
   <character>
    <name>Mr. Coder</name>
    <actor>El Act&#211;r</actor>
   </character>
  </characters>
  <plot>
   So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
  </plot>
  <great-lines>
   <line>PHP solves all my web problems</line>
  </great-lines>
  <rating type="thumbs">7</rating>
  <rating type="stars">5</rating>
 </movie>
</movies>
*/

require_once(".\minixml-1.3.8\minixml.inc.php");
$xml = new MiniXMLDoc();
$xml->fromFile('.\movies.xml');
$rootElement = & $xml->getRoot();

$movie = $rootElement->getElementByPath('movie');
$title = $rootElement->getElementByPath('movie/title')->getValue();
echo "$title\n";

$characters = $movie->getElementByPath('characters');
$characters_all = $characters->getAllChildren('character');
foreach($characters_all as $c){
  $name = $c->getElementByPath('name')->getValue();
  $actor = $c->getElementByPath('actor')->getValue();
  echo "$name,$actor\n";
}

$plot = $movie->getElementByPath('plot')->getValue();
echo "$plot\n";

$greatlines = $movie->getElementByPath('great-lines');
$greatlines_all = $greatlines->getAllChildren('line');
foreach($greatlines_all as $l){
  $greatline = $l->getValue();
  echo "$greatline\n";
}

$ratings = $movie->getAllChildren('rating');
foreach ($ratings as $r){
  $type = $r->xattributes['type'];
  $rating = $r->getValue();
  echo "$type,$rating\n";
}
?>
======================================================


実行結果は下記の通りです。
c:\php>php parsexml.php
PHP: Behind the Parser
Ms. Coder,Onlivia Actora
Mr. Coder,El ActÓr
So, this language. It's like, a programming language. Or is it a
   scripting language? All is revealed in this thrilling horror spoof
   of a documentary.
PHP solves all my web problems
thumbs,7
stars,5

XMLの要素を全部出力できました。



PHP configure時によくあるエラー

  • このエントリーをはてなブックマークに追加


CentOS/RedHatではPHP ソースからインストールする場合、Configure時によくあるエラー一覧です。


configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
yum install libxslt-devel

configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.

yum install net-snmp-devel

configure: error: Please reinstall readline - I cannot find readline.h

yum install readline-devel

configure: error: Cannot find pspell

yum install aspell-devel

checking for unixODBC support... configure: error: ODBC header file '/usr/include/sqlext.h' not found!

yum install unixODBC-devel

configure: error: Unable to detect ICU prefix or /usr/bin/icu-config failed. Please verify ICU install prefix and make sure icu-config works.

yum install libicu-devel

configure: error: utf8mime2text() has new signature, but U8TCANONICAL is missing. This should not happen. Check config.log for additional information.

yum install libc-client-devel

configure: error: freetype.h not found.

yum install freetype-devel

configure: error: xpm.h not found.

yum install libXpm-devel

configure: error: png.h not found.

yum install libpng-devel

configure: error: vpx_codec.h not found.

yum install libvpx-devel

configure: error: Cannot find enchant

yum install enchant-devel

configure: error: Please reinstall the libcurl distribution - easy.h should be in /include/curl/

yum install libcurl-devel