php与nginx编译安装实录
2017-12-16 23:45
537 查看
记录一次编译安装php与nginx笔记
以下所有操作均在root 权限下执行,如非root用户,有些命令需要sudo安装编译所需相关软件
yum install gcc gcc++ libxml2-devel安装php
下载源代码
cd ~wget http://hk1.php.net/get/php-7.1.12.tar.gz/from/this/mirror
解压
tar -zxvf mirror编译安装php
cd php-7.1.12./configure –prefix=/usr/local/php7 –enable-fpm (–enable-fpm 添加 php-fpm,nginx与之实现php的通信)
make
undefined reference to `libiconv' 解决办法: 1. wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz 2. tar -zxvf libiconv-1.13.1.tar.gz 3. cd libiconv-1.13.1 4. ./configure --prefix=/usr/local/libiconv 5. make 6. make install
cd ~/php-7.1.12
./configure –prefix=/usr/local/php7 –with-iconv=/usr/local/libiconv –enable-fpm
make
make install
测试php
cd ~vi test.php
<?php echo 'hello world!';
/usr/local/php7/bin/php test.php
hello world
安装nginx 与 pcre(用于支持正则)
下载pcre源代码
cd ~wget https://ftp.pcre.org/pub/pcre/pcre-8.36.tar.gz (pcre源代码,用于支持正则,尽可能下载8.36及之前版本,太高版本, 编译nginx会出问题)
解压
tar -zxvf pcre-8.36.tar.gz编译安装
cd pcre-8.36/./configure –prefix=/usr/local/pcre
make
make install
下载nginx源代码
cd ~wget http://nginx.org/download/nginx-1.12.2.tar.gz
解压
tar -zxvf nginx-1.12.2.tar.gz编译安装
cd nginx-1.12.2/./configure –prefix=/usr/local/nginx –with-pcre=/root/pcre-8.36
make
出现以下问题,说明pcre版本过高,需要更换版本 No rule to make target `libpcre.la'. Stop
make install
测试nginx
/usr/local/nginx/sbinps aux | grep nginx (出现nginx进程)
浏览器输入IP地址查看,能看到nginx默认页面
配置nginx与php(php-fpm)通信
启动php-fpm
cd /usr/local/php7/sbin./php-fpm
ERROR: failed to open configuration file '/usr/local/php7/etc/php-fpm.conf': No such file or directory (2) ERROR: failed to load configuration file '/usr/local/php7/etc/php-fpm.conf' ERROR: FPM initialization failed 以上说明php-fpm的配置文件不存在,因为默认php-fpm的配置文件有一个默认模板文件,只需要复制一份修改后缀即可
cd /usr/local/php7/etc/
cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php7/sbin/
./php-fpm
WARNING: Nothing matches the include pattern '/usr/local/php7/etc/php-fpm.d/*.conf' from /usr/local/php7/etc/php-fpm.conf at line 125. ERROR: No pool defined. at least one pool section must be specified in config file ERROR: failed to post process the configuration ERROR: FPM initialization failed 此问题与上述一致
cd /usr/local/php7/etc/php-fpm.d/
cp www.conf.default www.conf
cd /usr/local/php7/sbin/
./php-fpm
ps aux | grep php-fpm (查看php-fpm进程是否存在)
nginx配置
cd /usr/local/nginx/confvi nginx.conf
-修改成以下内容(主要是打开了 FastCGI 配置,默认是注释掉的,还有修改了fastcgi_param)
#user nobody; worker_processes 1; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index 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 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 html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; 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; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }
/usr/local/nginx/sbin/nginx -s reload (修改配置文件后,重启nginx)
测试
cd /usr/local/nginx/html (默认nginx 网站根目录)vi test.php
<?php echo 'hello world!';
浏览器访问 ip/test.php
以上,就是本次实录所有过程。
相关文章推荐
- 编译安装LNMP(Redhat5.4+nginx+mysql+php-5.3.6)
- WdOS系统下源代码编译安装PHP(搭配nginx运行)
- Linux-rhel6.4 编译安装PHP,Nginx与php连接
- 查看Nnginx、Apache、MySQL、PHP安装时的编译参数
- Centos+Nginx+PHP7.0编译安装(和PHP5.6老版本共存)
- CentOS 6.2 上编译安装 Nginx 1.0.15 + PHP 5.3.16 + MySQL 5.1.62
- nginx1.6 + php5.4+phpmyadmin 编译安装配置
- 获取安装后Apache、MySQL、Nginx、PHP编译时参数
- CentOS 编译 nginx+php+mysql 安装手记
- 编译安装nginx1.9.7+php7.0.0服务器环境
- Nginx + PHP + MySQL 在 CentOS 下的编译安装
- Nginx PHP MySql 编译安装
- 虚拟机上CentOS 7.0编译安装Nginx+MySQL+PHP(二)
- CentOS6.x编译安装LNMP(Linux+Nginx+Mysql+PHP)
- linux编译安装LNMP:Linux+Nginx+MariaDB+PHP
- Linux\CentOS系统下的服务器搭建,下载编译环境,安装vsFtpd、nginx、MySQL、JDK、Tomcat、PHP
- Linux-rhel6.4 编译安装PHP,Nginx与php连接
- Mac OS Lion 下编译安装Nginx 1.0.12 + PHP 5.3.10 + Mysql 5.5.18 + Xdebug + PHPUnit
- 获取安装后Apache、MySQL、Nginx、PHP编译时参数
- CentOS 编译 nginx+php+mysql 安装手记