ubuntu11.04版本,以下步骤是本人在前两天安装的基础上,又在纯新的ubuntu下安装一遍
步骤都是顺序操作的,希望朋友按照顺序来操作,以免要回过头来反复操作,希望能为您节省时间
?
一、安装前准备
下载php-5.4.13.tar.gz最新版本放到/user/src目录下
?
二、安装
??? 因为在安装php过程中,会依赖安装很多库,为了不让你反复安装,建议按步骤操作
??? 安装autoconf工具
apt-get install autoconf
??? 安装libxml2库
apt-get install libxml2-dev
??? 安装libbz2-dev
apt-get install libbz2-dev
??? 安装curl
apt-get install libcurl4-gnutls-dev
??? 安装jpeglib
apt-get install libjpeg-dev
??? 安装png
apt-get install libpng-dev
? ? 安装libxpm-dev
apt-get install libxpm-dev
??? 安装freetype
apt-get install libfreetype6-dev
??? 安装libt1
apt-get install libt1-dev
??? 安装mcrypt
apt-get install libmcrypt-dev
??? 安装xslt
apt-get install libxslt1-dev
???
??? 按照上面的步骤安装将会为您节省至少20分钟的时间,甚至更多;如果还有错误,则根据提示安装库
??? 最后执行安装命令,当前在解压好的php原文件包/usr/src/php-5.4.13目录
安装成功!!
?
三、配置php
??? 将php安装目录加到PATH中
echo 'if [ -d "/usr/local/php/bin" ] && [ -d "/usr/local/php/sbin" ]; then PATH="$PATH:/usr/local/php/bin:/usr/local/php/sbin" fi' >> /etc/bash.bashrc
??? 当前会员也加到PATH中
export PATH="$PATH:/usr/local/php/bin:/usr/local/php/sbin"
??? 准备php的日志文件目录
mkdir /var/log/php-fpm chown -R www:www /var/log/php-fpm
??? 准备php的配置文件
cd /usr/src/php-5.4.13 cp -f php.ini-production /usr/local/php/etc/php.ini <span><span class="func">chmod</span><span>?644?/usr/local/php/etc/php.ini</span></span> <span><span>cp?/usr/local/php/etc/php-fpm.conf.</span><span class="keyword">default</span><span>?/usr/local/php/etc/php-fpm.conf </span></span>
注意: PHP的配置文件在/usr/local/php/etc/php.ini,
???????? php-fpm的配置文件在/usr/local/php/etc/php-fpm.conf.
?
??? 设置php-fpm启动管理文件,并让PHP在ubuntu启动时自动运行
cp -f sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm chmod 755 /etc/init.d/php-fpm update-rc.d -f php-fpm defaults
??? 设置PHP的自动日志分割和压缩
vi /etc/logrotate.d/php-fpm 输入一下内容: /var/log/php-fpm/*.log { weekly missingok rotate 52 compress delaycompress notifempty create 640 www www sharedscripts postrotate [ ! -f /usr/local/php /var/run/php-fpm.pid ] || kill -USR1 `cat /usr/local/php/ /var/run/php-fpm.pid` endscript }
?
四、配置php-fpm和nginx
??? 打开php-fpm配置文件
<strong>vi /usr/local/php/etc/php-fpm.conf</strong>
?? 下面的参数需要改下
error_log = log/php-fpm.log
log_level = notice
;emergency_restart_threshold = 0
;emergency_restart_interval = 0
;process_control_timeout = 0
;daemonize = yes
[www]
;prefix = /path/to/pools/$pool
listen = 127.0.0.1:9000
; listen.backlog = -1
listen.allowed_clients = 127.0.0.1
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
然后配置nginx
vi /usr/local/nginx/conf/nginx.conf
? ? 内容如下
worker_processes 2;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events
{
use epoll;
worker_connections 1024;
}
http
{
include mime.types;
default_type application/octet-stream;
#charset gb2312;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 8M;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300s;
fastcgi_send_timeout 300s;
fastcgi_read_timeout 300s;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m;
server
{
listen 80; #/*监听端口*/
server_name localhost; #/*服务器名称*/
index index.html index.htm index.php; #/*缺省主页名称*/
root /var/www; #/*网站根目录,也可以采用下面内容*/
#也可以采用相对路径,下面注释部分*/
#location / {
# root html;
# index index.html index.htm;
# }
#limit_conn crawler 20;
#通过FastCGI方式支持PHP,php页面由fastcgi代理处理,这也是反向代理的一个应用,这里可以是jsp/asp等脚本。
location ~ .*\.(php|php5)?$
{
include /etc/nginx/fastcgi_params;#为FastCGI模块设置了基本的环境变量
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/$fastcgi_script_name;
#include fcgi.conf; #/*fastcgi配置文件,修改为以下内容*/
}
#对于某一类型的文件,设置过期时间,静态的页面通常设置长一点。
#静态文件,nginx自己处理
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
{
expires 30d;
}
#日志的格式
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /var/log/nginx/access.log access;
}
}
??? 保存退出,重启fpm和nginx
/etc/init.d/php-fpm restart /etc/init.d/nginx restart
??? 安装完成!!!