ubantu 安装PHP

检查是否已安装openssl:

sudo apt-get install openssl

如果已安装执行以下操作:
sudo apt-get install libssl-dev
sudo apt-get install libssl0.9.8

sudo apt-get  install libxml2

sudo apt-get  install libxml2-dev

Ubuntu 下安装 GTK+ 开发库
sudo apt-get install libgtk2.0-dev

安装php:
先安装libevent和libiconv:

wget https://github.com/downloads/libevent/libevent/libevent-1.4.14b-stable.tar.gz
tar zxvf libevent-1.4.14b-stable.tar.gz
cd libevent-1.4.14b-stable
./configure&&make&&make install

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar zxvf libiconv-1.14.tar.gz
cd  libiconv-1.14
./configure
make
make install
ln -sf /usr/local/lib/libiconv.so.2 /usr/lib/libiconv.so.2

现在安装php:

wget http://cn.php.net/distributions/php-5.4.0.tar.gz
tar zxvf php-5.4.0.tar.gz
cd php-5.4.0

./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config  --with-openssl --enable-fpm  --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-iconv-dir=/usr/local

make ZEND_EXTRA_LIBS='-liconv'        #因为-liconv的目录不是在/usr/local下所以安装时需要手动指定
make install

其中:
–with-mysql和–with-mysqli的路径是你mysql的具体所在的目录
–enable-fpm 启动fpm。其他都是些基本选项,简单易懂

cp php.ini-production /usr/local/php/etc/php.ini

修改配置文件:

vim /usr/local/php/etc/php-fpm.conf
1
2
3
4
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 35

启动:

/usr/local/php/sbin/php-fpm &

检查是否正常启动:

netstat -tunlp|grep 9000
tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      7826/php-fpm

将 /usr/local/php/sbin/php-fpm &加入到rc.local:

echo '/usr/local/php/sbin/php-fpm &' >>/etc/rc.local

sudo  ln -s /usr/local/php/bin/php  /usr/bin/php

配置fastcgi_params 文件:

vim /etc/nginx/fastcgi_params

将内容替换为:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;
# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

最后修改nginx.conf配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
vim /etc/nginx/nginx.conf
location ~ \.php$ {
            root           /www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            include        fastcgi_params;
        }
 
location / {
            root   /www;
            index  index.php index.html index.htm;
        }

保存退出。
启动nginx :

service nginxd start

 

Jason.wang

When you find your talent can't afford to be ambitious, be quiet and study !

You may also like...