CentOS安装Nginx+PHP(Phalcon)
2017-01-15 本文已影响567人
__Bw__
准备工作
- php安装包 http://php.net/downloads.php#v5.6.29
- phalcon扩展 https://github.com/phalcon/cphalcon.git
- nginx安装包 http://nginx.org/en/download.html
- pcre安装包 http://www.pcre.org/
- zlib安装包 http://www.zlib.net/
安装目录
- php安装目录
/usr/local/php
- nginx安装目录
/usr/local/nginx
安装Nginx
- 安装C++
yum install -y gcc gcc-c++
- 安装pcre
tar zxvf pcre-8.35.tar.gz
cd pcre-8.35
./configure
make
make install
- 安装zlib
tar zxvf zlib-1.2.8.tar.gz
cd zlib-1.2.8
./configure
make
make install
- 安装nginx
tar zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2
./configure --with-pcre=../pcre-8.35 --with-zlib=../zlib-1.2.8
make
make install
- 测试nginx
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
- 运行nginx
/usr/local/nginx/sbin/nginx
浏览器打开.png
- 设置nginx为开机启动
echo "/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf" >> /etc/rc.local
- nginx基本命令
/usr/local/nginx/sbin/nginx #启动
/usr/local/nginx/sbin/nginx -s reload #重载
/usr/local/nginx/sbin/nginx -s stop #关闭
安装PHP
- 编译环境及依赖
yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel libmcrypt-devel mhash-devel libxml2-devel libXpm-devel expat-devel curl-devel libtool openssl openssl-devel bzip2-devel
- 安装php及内置php-fpm
tar zxvf php-5.6.29.tar.gz
cd php-5.6.29
./configure --prefix=/usr/local/php --enable-fpm --with-config-file-path=/usr/local/php/etc --enable-mbstring --enable-pdo --with-curl --disable-debug --disable-rpath --enable-inline-optimization --with-bz2 --with-zlib --enable-sockets --enable-sysvsem --enable-sysvshm --enable-pcntl --enable-mbregex -enable-zip --with-pcre-regex --with-mysql --with-mysqli --with-gd --with-jpeg-dir
make
make install
- 拷贝配置文件
cd /usr/local/php/etc/
cp /root/php-5.6.29/php.ini-production ./php.ini #拷贝php配置文件
cp php-fpm.conf.default php-fpm.conf #拷贝php-fpm配置文件
- 测试php-fpm
/usr/local/php/sbin/php-fpm -t
[14-Jan-2017 03:53:04] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
- 拷贝常用命令到系统目录
cp /usr/local/php/bin/php /usr/local/bin/
cp /usr/local/php/bin/phpize /usr/local/bin/
cp /usr/local/php/bin/php-config /usr/local/bin/
- 安装git服务
yum -y install git
- 安装phalcon扩展
cd /root
git clone https://github.com/phalcon/cphalcon.git
cd cphalcon
git checkout 2.1.x #phalcon版本为2.1.0,切为2.1.x分支
cd build
./install
- 添加phalcon扩展到php配置文件
vim /usr/local/php/etc/php.ini
#在配置文件中添加
extension_dir=/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
extension=phalcon.so
- 运行php-fpm
/usr/local/php/sbin/php-fpm -D
配置Nginx及PHP-Fpm
- 修改nginx配置文件
cd /usr/local/nginx/conf/
vim nginx.conf
- 添加配置内容
user nobody;
worker_processes auto;
error_log /usr/local/nginx/logs/error_nginx.log crit;
pid logs/nginx.pid;
worker_rlimit_nofile 655350;
events {
use epoll;
worker_connections 655350;
multi_accept on;
}
http {
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 500m;
sendfile on;
tcp_nopush on;
keepalive_timeout 120;
server_tokens off;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_buffers 16 8k;
gzip_comp_level 6;
gzip_http_version 1.1;
gzip_min_length 256;
gzip_proxied any;
gzip_vary on;
gzip_types
text/xml application/xml application/atom+xml application/rss+xml application/xhtml+xml image/svg+xml
text/javascript application/javascript application/x-javascript
text/x-json application/json application/x-web-app-manifest+json
text/css text/plain text/x-component
font/opentype application/x-font-ttf application/vnd.ms-fontobject
image/x-icon;
gzip_disable "MSIE [1-6].(?!.SV1)";
open_file_cache max=1000 inactive=20s;
open_file_cache_valid 30s;
open_file_cache_min_uses 2;
open_file_cache_errors on;
server {
listen 8080;
server_name localhost;
index index.php index.html;
root /web/sz/public;
location / {
index index.php index.html;
try_files $uri $uri/ /index.php?_url=$uri&$args;
autoindex on;
}
location ~ ..(php|php5)?$
{
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location ~ ..(gif|jpg|jpeg|png|bmp|swf|ico)$
{
expires 30d;
access_log off;
}
location ~ ..(js|css)?$
{
expires 1h;
access_log off;
}
access_log /usr/local/nginx/logs/access/sz.log;
error_log /usr/local/nginx/logs/error/sz.log;
}
upstream backend {
ip_hash;
server 10.85.3.15:8080;
server 10.85.3.16:8080;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://backend;
}
}
}
- 创建日志文件目录
mkdir /usr/local/nginx/logs/access/
mkdir /usr/local/nginx/logs/error/
- 重启Nginx
/usr/local/nginx/sbin/nginx -s reload
web目录
- 创建web目录
mkdir /web/sz