摘要:
在64位Ubuntu下源码安装PHP5.3.8,并且配置Nginx为Web服务器。网上对于源码编译安装PHP的文章已经很多了,google下一大摞,但是为啥我还这么写上呢, 一来是因为工作需要,重装了系统比较重要的就是配置环境,以前是一直用sudo apt-get的调过过程的安装方式,所以趁着这个机会能自己尝试下源码方式安装,体验下过程。二来是因为这个是第一次源码安装,特此纪念下。
一、 准备
环境:64位 Ubuntu 11.10
服务器: Nginx 1.1.13
下载PHP源码:本文使用5.3.8版本
二、 安装
# tar zxvf php5.3.8.tar.gz # cd php5.3.8 # ./configure --prefix=/usr/local/php5 --with-config-file-path=/usr/local/php5/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 --with-pdo-mysql --with-openssl --with-xmlrpc --with-xsl --with-bz2 --with-gettext --with-fpm-user=xiaoxiao --with-fpm-group --enable-fpm --enable-exif --enable-wddx --enable-zip --enable-bcmath --enable-calendar --enable-ftp --enable-mbstring --enable-soap --enable-sockets --enable-sqlite-utf8 --enable-shmop --enable-dba --enable-sysvmsg --enable-sysvsem --enable-sysvshm
出现得错误如下:
错误一:
configure: error: xml2-config not found. Please check your libxml2 installation.
而我已经安装过了libxml2,但是还是有这个提示:
解决办法:
# sudo apt-get install libxml2-dev
错误二:
configure: error: Please reinstall the BZip2 distribution
而我也已经安装了bzip2,网上找到得解决方案都是需要安装bzip2-dev,可是11.10里面没有这个库。
解决办法:在网上找到bzip2-1.0.5.tar.gz,解压,直接make ,sudo make install.(我使用的该源来自于http://ishare.iask.sina.com.cn/f/9769001.html)
错误三:
configure: error: Please reinstall the libcurl distribution -easy.h should be in <curl-dir>/include/curl/
解决办法:
# sudo apt-get install libcurl4-gnutls-dev
错误四:
configure: error: jpeglib.h not found.
解决办法:
# sudo apt-get install libjpeg-dev
错误五:
configure: error: png.h not found.
解决办法:
# sudo apt-get install libpng-dev
错误六:
configure: error: libXpm.(a|so) not found.
解决办法:
# sudo apt-get install libxpm-dev
错误七:
configure: error: freetype.h not found.
解决办法:
# sudo apt-get install libfreetype6-dev
错误八:
configure: error: Your t1lib distribution is not installed correctly. Please reinstall it.
解决办法:
# sudo apt-get install libt1-dev
错误九:
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决办法:
# sudo apt-get install libmcrypt-dev
错误十:
configure: error: Cannot find MySQL header files under yes.
Note that the MySQL client library is not bundled anymore!
解决办法:
# sudo apt-get install libmysql++-dev
错误十一:
configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
解决办法:
# sudo apt-get install libxslt1-dev
可见PHP源码安装之前需要先安装这些依赖,详细可见http://forum.ubuntu.org.cn/viewtopic.php?f=88&t=231159
如上错误都解决之后,再次./config....没有错误之后,
# make # sudo make install
三、 配置
php-fpm是一个php fastCGI得管理器,在PHP5.3.X已经集成了这个东西,所以我们可以省去自己装这个得麻烦了,只要配置一下就可以。
先将相关得配置文件都拷贝到php5/etc目录下(该目录是我得配置文件存放目录),主要涉及有:
1、php-fpm配置文件:php源目录/sapi/fpm/php-fpm.conf.in
2、php-fpm启动文件:php源目录/sapi/fpm/init.d.php-fpm.in
3、php本身配置文件:php源目录/php.ini-development php源目录/php.ini-production
如果需要保存一份原始得文件,那么就将以上文件另外cp一份出来,如果是不保存的,那么以上文件cp到etc下就直接更名为自己需要的。我是保留了一份在etc目录下。
现在php5/etc目录下有如下格式配置文件:
php-fpm.conf init.d.php-fpm php.ini pear.conf(安装完成之后就有该文件)
首先:配置php-fpm.conf文件:
1、pid配置
;pid=run/php-fpm.pid
将前面得;号去掉,可以后面得路径可以根据自己得需求配置一个路径。
2、log配置
;error-log=log/php-fpm.log
log的配置可以根据自己的需求是否开启及存放位置
3、listen 配置
listen=127.0.0.1:9000
这个配置主要注意端口不要冲突,我在配置这个的时候采用的是网上说的socket方式,配置如下:
listen=/usr/local/php5/var/run/php-fpm.socket
然后在/usr/local/php5/var/run/该目录下建立该文件,注意权限需要
其他项的配置可以根据自己的需求更改,配置项的说明在这可以看到:http://www.php.net/manual/en/install.fpm.configuration.php。同时在github上有一份比较完整可用的配置:https://github.com/vladgh/VladGh.com/blob/master/php-fpm.conf 可以作为参考。
其次:配置init.d.php-fpm
改文件作为启动文件,需要配置的就是在开头位置的几个变量值,包括:
1、php_fpm_BIN:指向安装好的php目录/sbin/php-fpm
2、php_fpm_CONF:指向安装好的php目录/etc/php-fpm.conf {如果该配置文件你不是叫这个名字,跟这里应该为你真是得配置名}
3、php_fpm_PID:这里指向php-fpm的pid存放路径。
完成之后,将该文件拷贝到/etc/init.d目录下,本文是采用建立软链接的方式:
# sudo ln -s /usr/local/php5/etc/init.d.php-fpm /etc/init.d/php-fpm # sudo update-rc.d -f php-fpm defaults
然后:配置php
我是拿的php.ini- development,几乎不用配置
最后:配置nginx.conf
完成上面之后,需要配置nginx可运行php,如下配置:
Server{}下:
1、root html: 该项配置指明脚本程序的目录,本文是设置为root /home/www
2、识别.php文件:
location / { index index.html index.htm index.php; }
3、解析php脚本:这块只要将注释”#”去掉就好。
location ~ \.php$ { fastcgi_pass unix:/usr/local/php5/var/run/php-fpm.socket; #127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
注意:fastcgi_pass 这里,后面跟php-fpm.conf中配置得listen一致,在listen中我是配置了socket方式,所以这里也这样配。
启动服务:
# sudo /etc/init.d/nginx restart # sudo /etc/init.d/php-fpm start
在网页中输入localhost,就可以看到啦:
如果有需要,可以添加为系统路径中:
# sudo vim /etc/bash.bashrc //在最后添加如下if [ -d "/usr/local/php5/bin" ] && [ -d "/usr/local/php5/sbin" ]; then PATH="$PATH:/usr/local/php5/bin:/usr/local/php5/sbin" fi
四、虚拟机配置
nginx的虚拟机配置其实挺简单的,打开nginx.conf 在http{}中加入 include /usr/local/nginx/conf/virtual_sites.conf;(也可以是文件夹下的文件如sites/*.conf)
然后在virtual_sites.conf中配置需要得虚拟机:
server { listen 80; server_name p9.xxx; root /home/www/p9/www; location / { index index.html index.htm index.php; } location ~ \.php$ { fastcgi_pass unix:/usr/local/php5/var/run/php-fpm.socket; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_index index.php; include fastcgi_params; } }
相关推荐
php-fpm是个中间件,在需要php解释器来处理.php文本时会用到php-fpm。自从php5.3.3以后就将php-fpm集成在php内核中。PHP-FPM提供了更好的PHP进程管理方式,可以有效控制内存和进程、可以平滑重载PHP配置。 作者:...
本文给大家详细介绍了解决php-fpm.service not found问题的相关内容,文中介绍的非常详细,下面来一起看看详细的介绍: 环境介绍 环境:ubuntu 16.04 64 php 版本:php-7.1.4 发现问题 正常编译安装 php 按照以前...
docker-compose php7.3.4-fpm+nginx+mysql配置
php-fpm,用于php网页解析的软件工具包,还有一些php写好的网页
编译源代码时,缺乏顺利开启fpm,于是鼓捣了一下,并打包了一个适用于php5.3.10的 ...上暂时只跟新到 php-5.2.9-fpm-0.5.10-unofficial.diff.gz 编译参数: #./configure --enable-fpm + other custum configure .etc
php-fpm7.1包 yum localinstall -y php-fpm/*安装 包是7.1 tar 压缩 下载后tar解压 yum即可安装
php-fpm。放到/etc/init.d/目录。然后执行:chmod a+x php-fpm 然后就可以/etc/init.d/php-fpm start 或者systemctl start php-fpm
Fedora 15 安装 Nginx (PHP-FPM)+MySQL+PHP Web服务.docx
nginx+php-fpm解决502 Bad Gateway.zip
php-fpm-5.3.3-14.el6_3.x86_64.rpm
安装php所需要的文件,没有此文件将安装失败!!!!!安装php所需要的文件,没有此文件将安装失败!!!!!
基于alpine的php-fpm nginx docker一键环境 可以手动替换所有版本 通过修改dockerfile,支持容器加载代码,或者挂载代码 也可以支持k8s做为基础环境容器,整体已经经过优化
php-5.3.0-fpm-0.5.12
解决nginx+php-fpm无法上传文件问题.docx
Zabbix 监控 php-fpm 的模板
用于安装和运行Docker容器。 支持的分支和相应的Dockerfile链接 主 7.4.10 7.4.4 7.4.2 7.4.0 7.3.10 7.3.9 7.3.8 7.3.7 7.3.6 7.3.3 7.3.2 Dockerfile 7.2.15 Dockerfile 7.2.13 Dockerfile 7.2.2 ...
php-fpm.conf配置文件中文翻译注释
php-5.2.8-fpm-0.5.10.diff.gz
ppa安装php-fpm安装工具包复制代码 代码如下:$ sudo apt-get install python-software-properties 添加ppa源复制代码 代码如下:$ sudo add-apt-repository ppa:yola/php5安装php5-fpm复制代码 代码如下:sudo apt-...
Windows 下使用 RunHiddenConsole 启动 nginx、php-fpm, https://www.nginx.com/resources/wiki/start/topics/examples/phpfastcgionwindows/