centos搭建nginx,php,mysql

关闭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 nginx 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

注意问题:lnmp安装好后,访问php文件提示Aaccess denied,访问html文件提示404 not found

原因:由于nginx配置文件未配好导致的,需要将对应的解析文件修改为可解析php文件,定义web的根目录

解决方法:

vi /etc/nginx/conf.d/default.conf

location ~ \.php$ {

            root           html;//需要更换为网站的根目录

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            include        fastcgi_params;

        }

 

这个用出现找不到php的错误。因为$document_root 的参数是由root html那一行定义的,默认是在/etc/nginx/html/ 所以把 html换成站点根目录就正常了。

 

            location ~ \.php$ {

            root           /var/www/html;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

            include        fastcgi_params;

        }



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值