很多PHP工程师没有做过编译安装的工作,经过一段探究,今天写个小博客。
一 源码编译安装PHP
1 下载PHP7.0源码包7.0.13tar.gz
2 tar -zxvf 源码包
3 切换到源码包目录执行:
./configure --prefix=/usr/local/php/php-7.0 --with-config-file-path=/usr/local/php/php-7.0/etc --with-iconv=/usr/local/opt/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib-dir=/usr/local/opt/zlib --enable-xml --disable-rpath --enable-discard-path --enable-safe-mode --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl=/usr/local/opt/curl --with-curlwrappers --enable-mbregex --enable-fastcgi --enable-fpm --enable-force-cgi-redirect --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-ttf --with-openssl=/usr/local/opt/openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --enable-pdo --with-pdo-mysql --enable-op-cache
生成makefile文件。接着执行 make & make install
4 配置php.ini
cp php.ini-production /usr/local/php7.0/lib/php.ini
在安装目录的 etc 目录可看到 php-fpm.conf.default 和 php-fpm.d文件
cp /usr/local/php7.0/etc/php-fpm.conf.default /usr/local/php7.0/etc/php-fpm.conf
cp /usr/local/php7.0/etc/php-fpm.d/www.conf.default /usr/local/php7.0/etc/php-fpm.d/www.conf
源码目录下init.d.php-fpm配置到/usr/bin/php-fpm
cp /usr/local/src/php-7.0.18/sapi/fpm/init.d.php-fpm /usr/bin/php-fpm
其中 www.conf 配置文件配置 php fpm 的端口号等信息
执行php-fpm可以启动。
二 源码编译安装nginx
1 下载nginx-1.14.0.tar.gz
2 ./configure --prefix=/usr/local/nginx/nginx-1.14.0
Make & make install
3 配置nginx.conf
user apple;
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 82;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
index index.html index.htm index.php;
set $root /Users/apple/WORK/holonet/web;
#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 $root;
}
# 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 $root;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
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;
}
location / {
try_files $uri $uri/ /index.php?$query_string;
if (!-e $request_filename){
rewrite ^/(.*) /index.php last;
}
}
}
# 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;
# }
#}
}
启动nginx。