5分钟搭建 nginx +php --------------(LNMP)新手专用
版权声明:本文为博主原创文章,未经博主允许不得转载。
这里要先声明一下,针对Nginx的PHP安装和针对apache的php安装是有区别的,因为Nginx中的php是以fastcgi的方式结合nginx的,可以理解为nginx代理了php的fastcgi,而apache是把php作为自己的模块来调用的。
先把php 和php-fpm编译安装吧 请看http://heilinux.blog.51cto.com/6123663/1575582
修改配置文件
1
|
cd php-5.6.2 |
cp php.ini-production /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default.conf php-fpm.conf
保存配置文件后,检验配置是否正确的方法为:
/usr/local/php/sbin/php-fpm -t
如果出现诸如 “test is successful” 字样,说明配置没有问题。
启动php-fpm
cp /usr/local/src/php-5.3.27/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod 755 /etc/init.d/php-fpm
service php-fpm start
如果想让它开机启动,执行:
chkconfig php-fpm on
检测是否启动:
ps aux |grep php-fpm
netstat -ant |grep 9000
看看是不是有很多个进程(大概20多个)还有你的9000端口开启了么?。
》》》》》》》》》》》》》》》》华华丽丽的分隔符《《《《《《《《《《《《《《《《《《《
安装nginx
开始安装nginx吧
1
2
|
wget http: //nginx .org /download/nginx-1 .6.2. tar .gz // 最新稳定版哦 |
解压nginx
tar zxvf nginx-1.6.2.tar.gz
配置编译参数
cd nginx-1.6.2
./configure \
--prefix=/usr/local/nginx \
--with-http_realip_module \
--with-http_sub_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--with-pcre
编译nginx
make
安装nginx
make install
因为nginx比较小,所以很快就会安装完,而且也不会出什么错误,如果出错了,yum安装pcre-devel(嘿嘿,我是这个问题了,至于你出别的问题问度娘吧。)
》》》》》》》》》》》》》》》》》》华丽的分隔符《《《《《《《《《《《《《《《《《《《《《
添加一个nginx主程序的符号链接
1
2
|
ln -sf /usr/local/nginx/sbin/nginx /usr/sbin |
1
|
nginx -t 测试一下吧,成功了吧,是不是很有成就感,别着急 咱们继续! |
更改nginx配置
首先把原来的配置文件清空:
> /usr/local/nginx/conf/nginx.conf
“>” 这个符号之前阿铭介绍过,为重定向的意思,单独用它,可以把一个文本文档快速清空。
vim /usr/local/nginx/conf/nginx.conf
写入如下内容:
user nobody nobody;
worker_processes 2;
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200; events
{
use epoll;
worker_connections 6000;
} http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
'$host "$request_uri" $status'
'"$http_referer" "$http_user_agent"';
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm application/xml; server
{
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /usr/local/nginx/html; location ~ \.php$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
} } }
》》》》》》》》》》》》》》》》你相信么,你已经搞定了LNMP了《《《《《《《《《《《《《《
测试是否解析php文件
创建测试文件:
vim /usr/local/nginx/html/2.php
内容如下:
<?php
echo "测试php是否解析";
?>
测试:
curl localhost/2.php
看到什么了。。不要怀疑自己的眼睛,不要热泪盈眶。你已经成功了。
----------------
最近在学习nginx,看了好多帖子终于安装成功了。
经验,首先不要用yum安装,安装完以后根本找不到安装目录在哪里呀,然后安装失败以后会很不方便。
最终选择了自己编译安装。
看了好多帖子都不行,终于找到一个靠谱的呀,好详细。帖子地址http://www.cnblogs.com/zxpo/p/3798983.html
php-fpm打补丁
cd /usr/local/src
gzip -cd php-5.2.8-fpm-0.5.10.diff.gz | patch -d php-5.2.8 -p1
下面是粘贴过来的帖子内容;
1、下载php源码包
http://www.php.net/downloads.php
2 、安装php
tar -xvf php-5.5.13.tar.bz2
cd php-5.5.13
./configure --prefix=/usr/local/php --with-config-file-path=/etc --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-opcache --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-gettext --enable-mbstring --with-iconv --with-mcrypt --with-mhash --with-openssl --enable-bcmath --enable-soap --with-libxml-dir --enable-pcntl --enable-shmop --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-sockets --with-curl --with-zlib --enable-zip --with-bz2 --with-readline --without-sqlite3 --without-pdo-sqlite --with-pear
出现错误: congigure error: xml2-config not found.
解决办法:
执行命令: sudo yum install libxml2-devel
查看是否成功: find / -name "xml2-config"
出现错误: congigure error: Cannot find OpenSSL's <evp.h>
解决办法:
yum install openssl openssl-devel
ln -s /usr/lib64/libssl.so /usr/lib/
出现错误: configure: error: Please reinstall the BZip2 distribution
解决办法:yum install bzip2 bzip2-devel
出现错误: configure: error: Please reinstall the libcurl distribution -easy.h should be in <curl-dir>/include/curl/
解决办法:yum -y install curl-devel
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
sudo yum install libmcrypt libmcrypt-devel mcrypt mhash
configure: error: Please reinstall readline - I cannot find readline.h
sudo yum install readline-devel
make
make install
添加 PHP 命令到环境变量
vim /etc/profile
在末尾加入
PATH=$PATH:/usr/local/php/bin
export PATH
要使改动立即生效执行
. /etc/profile 或 source /etc/profile
查看环境变量
echo $PATH
查看php版本
php -v
PHP 5.5.13 (cli) (built: Jun 20 2014 11:11:26)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
配置php-fpm
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
启动php-fpm
sudo /usr/local/php/sbin/php-fpm
修改nginx的配置文件(/etc/nginx/conf.d/default.conf)
location / {
root web根目录;
index index.html index.htm index.php;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME web根目录$fastcgi_script_name;
include fastcgi_params;
}
重启nginx
/etc/init.d/nginx restart
在web根目录下创建index.php
<?php echo phpinfo(); ?>
在浏览器中输入http://ip/index.php查看成功即可。
//注:根据自己的配置修改web根目录即可,如我的为/usr/share/nginx/html。
如果启动php-fpm出现错误: can not get uid for www,修改php-fpm.conf中user为nginx group为nginx
关闭SELINUX
vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
shutdown -r now #重启系统
安装ngnix
安装GCC编译器及相关工具
yum -y install gcc gcc-c++ autoconf automake
安装模块依赖的库
yum -y install zlib zlib-devel openssl openssl–devel pcre pcre-devel
更新系统时间
ntpdate time.nist.gov
让对时服务开机启动
chkconfig ntpd on
如果需要编译安装最新的
获取ngnix版本
wget http://nginx.org/download/nginx-1.0.14.tar.gz
tar zxvf nginx-1.0.14.tar.gz
cd nginx-1.0.14
直接yum安装
yum install -y nginx
将安装在/usr/share/nginx/
启动nginx
service ngnix start
安装PHP
cd /etc/yum.repos.d
wget http://dev.centos.org/centos/5/CentOS-Testing.repo
rpm –import http://dev.centos.org/centos/RPM-GPG-KEY-CentOS-testing
yum install -y php php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt libmcrypt-devel php-fpm
#启动php-fpm
/etc/rc.d/init.d/php-fpm start
设置自动启动
chkconfig php-fpm on
配置nginx支持php
cp /etc/nginx/nginx.conf /etc/nginx/nginx.confbak
vi /etc/nginx/nginx.conf
#修改nginx运行账号为:nginx组的nginx用户
user nginx nginx;
cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.confbak
vi /etc/nginx/conf.d/default.conf
#增加index.php
index index.php index.html index.htm;
取消FastCGI server部分location的注释,并要注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径
配置php-fpm
cp /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.confbak
vi /etc/php-fpm.d/www.conf
#修改用户为nginx
user = nginx
#修改组为nginx
group = nginx
安装MYSQL
yum -y install mysql mysql-server
启动mysql
service mysqld start
chkconfig mysqld on #设为开机启动
为root账户设置密码
mysql_secure_installation
重启所有服务
service mysqld restart
service nginx restart
/etc/rc.d/init.d/php-fpm restart
测试成功
安装ssh服务器和subversion服务器
yum install -y openssh-server
yum install -y subversion
5分钟搭建 nginx +php --------------(LNMP)新手专用的更多相关文章
- 新手搭建 nginx + php (LNMP)
配置源 纯净的Centos 6.5系统 配置163yum源 (这个比较简单,百度能解决很多问题) 开始 安装 开发软件包:yum -y groupinstall "Developmen ...
- docker一分钟搭建nginx服务器
运行nginx服务 拉取: docker pull nginx:1.17.9 运行: docker run -d --name nginx -P 80:80 nginx:1.17.9 -d表示在后台启 ...
- Linux 之 LNMP服务器搭建-Nginx
LNMP服务器搭建-Nginx 参考教程:[千峰教育] 系统版本: CentOS 6.8 关闭防火墙和Selinux service iptables stop setenforce 安装Nginx ...
- 在阿里云 ECS 搭建 nginx https nodejs 环境(二、https)
在阿里云 ECS 搭建 nginx https nodejs 环境(二) 这次主要内容是 如何在 ubuntu 的nginx 下配置 二级域名. 一. 域名解析 首先你需要去到你的 域名服务商那边 进 ...
- 在阿里云上搭建nginx + ThinkPHP 的实践
作为一个程序猿,理应用linux系统来作为平时的工作机环境,哎,之前倒是用过一段时间的linux,可惜后来换了本本,后来竟然没有保持,嗷嗷后悔中... 废话不多说,大家用windows的理由都一样,但 ...
- Linux 学习笔记 6 搭建nginx 实现二级域名访问
前言 在前一节的内容里面,我们学习了如何使用yum 包管理工具来安装我们需要的软件,这节内容,通过搭建Nginx 反向代理服务器,以及学习服务的配置等内容. NGINX Nginx是一款轻量级的Web ...
- ELK+redis搭建nginx日志分析平台
ELK+redis搭建nginx日志分析平台发表于 2015-08-19 | 分类于 Linux/Unix | ELK简介ELKStack即Elasticsearch + Logstas ...
- 在阿里云服务器(ECS)上从零开始搭建nginx服务器
本文介绍了如何在阿里云服务器上从零开始搭建nginx服务器.阿里云服务器(ECS)相信大家都不陌生,感兴趣的同学可以到http://www.aliyun.com/product/ecs去购买,或到体验 ...
- 基于ubuntu 14搭建nginx+php+mysql环境
基于最新的Ubuntu 14.04(2014年9月)搭建nginx.php.mysql环境, 以下全部命令行操作: 1 由于需要大量的权限操作,方便起见临时提升权限,使用root账号 sudo su ...
随机推荐
- Shiro自定义Realm时用注解的方式注入父类的credentialsMatcher
用Shiro做登录权限控制时,密码加密是自定义的. 数据库的密码通过散列获取,如下,算法为:md5,盐为一个随机数字,散列迭代次数为3次,最终将salt与散列后的密码保存到数据库内,第二次登录时将登录 ...
- prototype和_proto_
__proto__(隐式原型)与prototype(显式原型) 显式原型 explicit prototype property:用来实现基于原型的继承与属性的共享. 每一个函数在创建之后都会拥有一个 ...
- 路由器DHCP服务及DHCP中继
实验要求:掌握路由配置DHCP服务配置 拓扑如下: R1enable 进入特权模式config terminal 进入全局模式interface s0/0/0 进入端口ip address 192 ...
- tomcat自动缓存的几种解决方式
第一种方法:打开一个项目,这里我打开的Mail项目,然后点击Myeclipse菜单栏中的project-选择clean: 选择要clean的项目,确定即可不用进入tomcat服务器直接清理缓存. 上面 ...
- PHP安全之Web攻击(转)
一.SQL注入攻击(SQL Injection) 攻击者把SQL命令插入到Web表单的输入域或页面请求的字符串,欺骗服务器执行恶意的SQL命令.在某些表单中,用户输入的内容直接用来构造(或者影响)动态 ...
- DG搭建方式区分
DG搭建三种方式: 一.异机恢复,restore database,recover database 二. duplicate target database for standby from act ...
- 【leetcode】344. Reverse String
problem 344. Reverse String solution: class Solution { public: void reverseString(vector<char> ...
- PHP5和PHP7的安装、PHP和apache的整合!
1.PHP5的安装: 下载: wget -c http://cn2.php.net/distributions/php-5.6.36.tar.gz (php5) wget -c http://cn2 ...
- java-SimpleDateFormat类
1.SimpleDateFormat类实现日期和字符串的相互转换 * A:DateFormat类的概述 * DateFormat 是日期/时间格式化子类的抽象类,它以与语言无关的方式格式化并解析日期或 ...
- Odoo9以后的社区版本和企业版功能上的区别
Odoo9以后的社区版本和企业版除了授权模式的区别外,整理功能上的区别 透过功能设置菜单整理的区别如下,主要功能模块. 未包括所有模块,毕竟模块太多了. 以下是企业版有,而社区版没有的功能.