centos6.9 yum方式搭建lnmp环境

本人是在虚拟机上进行的,关于如何在虚拟机上安装centos6.9不再累述。

cat /etc/issue 查看版本

安装nginx

安装nginx之前先配置nginx仓库,(最好去参考nginx官网安装)

使用vim将下面的配置保存到/etc/yum.repos.d/nginx.repo文件中

[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/6/$basearch/
gpgcheck=0
enabled=1

然后直接使用以下命令进行安装nginx

yum install -y nginx

启动nginx

service nginx start

可以使用以下命令查看80端口

netstat -tunlp|grep 80

配置nginx为启动项,执行如下命令

chkconfig nginx on

安装mysql

安装之前删除自带版本执行如下命令

yum remove mysql mysql-server mysql-libs compat-mysql51

rm -rf /var/lib/mysql

rm /etc/my.cnf

查看是否还有mysql残留

rpm -qa|grep mysql

下载mysql rpm安装包

wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm

安装下载好的rpm文件

rpm -ivh mysql-community-release-el6-5.noarch.rpm

yum安装mysql-community-server

yum install mysql-community-server

安装过程会遇到询问是否下载直接y即可

启动mysql

service mysqld start

添加启动项

chkconfig mysqld on

查看3306端口状态

netstat -tunlp|grep 3306

安装php7.1

卸载php

.首先查看机器上安装的所有php相关的rpm包

[root@localhost nginx]# rpm -qa | grep php

php-cli-5.3.3-22.el6.x86_64

php-pdo-5.3.3-22.el6.x86_64

php-gd-5.3.3-22.el6.x86_64

php-fpm-5.3.3-22.el6.x86_64

php-common-5.3.3-22.el6.x86_64

php-5.3.3-22.el6.x86_64

php-xml-5.3.3-22.el6.x86_64

php-pear-1.9.4-4.el6.noarch

2.按依赖顺序进行删除

rpm -e php-fpm-5.3.3-22.el6.x86_64

rpm-e php-pdo-5.3.3-22.el6.x86_64

rpm -e php-pear-1.9.4-4.el6.noarch

rpm-e php-cli-5.3.3-22.el6.x86_64

rpm -e php-5.3.3-22.el6.x86_64

rpm-e php-xml-5.3.3-22.el6.x86_64

rpm -e php-gd-5.3.3-22.el6.x86_64

rpm-e php-common-5.3.3-22.el6.x86_64 

安装php

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

//查看
yum search php71w

//安装php以及扩展
yum install php71w php71w-fpm php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath

//后期缺少扩展的话直接使用以下类似命令
//yum install php71w-xml
//开启服务
service php-fpm start

//修改/etc/nginx/nginx.conf  使其支持php 见下
//重启nginx
service nginx restart
重新加载nginx服务
service nginx reload

在安装过程可能会遇到curl: (35) SSL connect error问题,使用以下命令更新之后重新尝试安装

yum update nss

如果还是出现此问题,使用以下命令,删除源,重新安装。参考https://blog.csdn.net/blue_red_1314/article/details/78804999

1、卸载epel-release-latest-7.noarch.rpm : yum remove epel-release
2、清空epel目录 : rm -rf /var/cache/yum/x86_64/6/epel/* 

 

如果遇到Error: xz compression not available的错误查看:https://blog.csdn.net/benben0729/article/details/82432431

开机启动

chkconfig php-fpm on
service php-fpm start

配置nginx支持php

vim /etc/nginx/conf.d/default.conf

修改
    # 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;
    #    include        fastcgi_params;
    #}

改为

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 /usr/share/nginx/html$fastcgi_script_name;
        include        fastcgi_params;
    }

如果在访问php文件时出现file not found,查看配置网张根目录是否正确

fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;

 

 

 

 

 

 

 

你可能感兴趣的:(远程服务器,个人日志)