一、安装前准备
下载php-5.4.13.tar.gz最新版本放到/user/src目录下
二、安装
因为在安装php过程中,会依赖安装很多库,为了不让你反复安装,建议按步骤操作
安装autoconf工具
sudo apt-get install autoconf
安装libxml2库
sudo apt-get install libxml2-dev
安装libbz2-dev
sudo apt-get install libbz2-dev
安装curl
sudo apt-get install libcurl4-gnutls-dev
安装jpeglib
sudo apt-get install libjpeg-dev
安装png
sudo apt-get install libpng-dev
安装libxpm-dev
sudo apt-get install libxpm-dev
安装freetype
sudo apt-get install libfreetype6-dev
安装libt1
sudo apt-get install libt1-dev
安装mcrypt
sudo apt-get install libmcrypt-dev
安装xslt
sudo apt-get install libxslt1-dev
按照上面的步骤安装将会为您节省至少20分钟的时间,甚至更多;如果还有错误,则根据提示安装库
最后执行安装命令,当前在解压好的php原文件包/usr/src/php-5.4.13目录
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-curl --with-pear --with-gd --with-jpeg-dir --with-png-dir --with-zlib --with-xpm-dir --with-freetype-dir --with-t1lib --with-mcrypt --with-mhash --with-mysql --with-mysqli --enable-pdo --with-pdo-mysql --with-openssl --with-xmlrpc --with-xsl --with-gettext --with-fpm-user=www-data --with-fpm-group=www-data --enable-fpm --enable-exif --enable-wddx --enable-zip --enable-bcmath -with-bz2 --enable-calendar --enable-ftp --enable-mbstring --enable-soap --enable-sockets --enable-shmop --enable-dba --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-debug --enable-maintainer-zts --enable-embed
make && make install
如果出现安装 openssl/evp.h:没有那个文件或目录 错误
使用sudo apt-cache search openssl
经过查找libcurl4-openssl-dev 出现这个包
sudo apt-get install libcurl4-openssl-dev
安装这个
安装成功!!
三、配置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
chmod 644 /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
注意: 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-data www-data sharedscripts postrotate [ ! -f /opt/php5/var/run/php-fpm.pid ] || kill -USR1 `cat /opt/php5/ /var/run/php-fpm.pid` endscript }
四、配置php-fpm和nginx
打开php-fpm配置文件
vi /usr/local/php/etc/php-fpm.conf
下面的参数需要改下
pid = run/php-fpm.pid //这个必去将前面的;注释去掉(一开始没去掉结果出502错误)
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
内容如下
user www;
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
ubuntu下源码方式安装php5.4,布布扣,bubuko.com
原文地址:http://www.cnblogs.com/breg/p/3833442.html