centos 7.0 lnmp成功安装过程(很乱)

时间:2023-03-09 08:07:53
centos 7.0 lnmp成功安装过程(很乱)

下载nginx

centos 7.0 lnmp成功安装过程(很乱)
[root@localhost src]# wget http://nginx.org/download/nginx-1.7.9.tar.gz
--2015-01-24 12:55:21-- http://nginx.org/download/nginx-1.7.9.tar.gz
正在解析主机 nginx.org (nginx.org)... 206.251.255.63
正在连接 nginx.org (nginx.org)|206.251.255.63|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:827263 (808K) [application/octet-stream]
正在保存至: “nginx-1.7.9.tar.gz” 100%[======================================>] 827,263 154KB/s 用时 6.5s 2015-01-24 12:55:28 (125 KB/s) - 已保存 “nginx-1.7.9.tar.gz” [827263/827263]) [root@localhost src]# ls
nginx-1.7.9.tar.gz
centos 7.0 lnmp成功安装过程(很乱)

解压压缩包 .tar.gz

解压压缩包 到指定的目录

-C /usr/local/bin
注意大小写的区别
 -c或--create   建立新的备份文件。
  -C<目的目录>或--directory=<目的目录>   切换到指定的目录。

centos 7.0 lnmp成功安装过程(很乱)


centos 7.0 lnmp成功安装过程(很乱)
[root@localhost src]# tar zxvf nginx-1.7.9.tar.gz -C /usr/local/bin
centos 7.0 lnmp成功安装过程(很乱)

结果查看

[root@localhost src]# cd /usr/local/bin
[root@localhost bin]# ls
nginx-1.7.9

进入解压目录查看

centos 7.0 lnmp成功安装过程(很乱)

还需要安装下面这些东西,否则./configure 会报错

centos 7.0 lnmp成功安装过程(很乱)
[root@localhost nginx-1.7.9]# yum -y install gcc-c++  pcre-devel zlib-devel
centos 7.0 lnmp成功安装过程(很乱)

下面开始编译nginx 最简单 最少的编辑

centos 7.0 lnmp成功安装过程(很乱)
[root@localhost nginx-1.7.9]# ./configure --prefix=/usr/etc/ngin
centos 7.0 lnmp成功安装过程(很乱)

需要再执行下面的make 和make install ,/usr/etc/ngin里面才会有东西

make

make install

启动nginx

centos 7.0 lnmp成功安装过程(很乱)
[root@localhost nginx-1.7.9]# cd /usr/etc
[root@localhost etc]# ls
ngin
[root@localhost etc]# cd ngin
[root@localhost ngin]# ls
conf html logs sbin
[root@localhost ngin]# cd sbin
[root@localhost sbin]# ls
nginx
[root@localhost sbin]# ./nginx
centos 7.0 lnmp成功安装过程(很乱)

查看进程  查看nginx是否启用

[root@localhost sbin]# ps -ef|grep nginx
root 13536 1 0 14:14 ? 00:00:00 nginx: master process ./nginx
nobody 13537 13536 0 14:14 ? 00:00:00 nginx: worker process
root 13540 2281 0 14:16 pts/0 00:00:00 grep --color=auto nginx
lsof -i:80 安装root用户的才是 默认的nobody需要删除
[root@localhost sbin]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 13536 root 6u IPv4 32434 0t0 TCP *:http (LISTEN)
nginx 13548 nobody 6u IPv4 32434 0t0 TCP *:http (LISTEN)
 

重启nginx

[root@localhost sbin]# ./nginx -s reload

查看iptables表的规则 是否限制了80等、

centos 7.0 lnmp成功安装过程(很乱)
[root@localhost sbin]# iptables -nL --line-number
centos 7.0 lnmp成功安装过程(很乱)

现在访问http://192.168.1.103/ 无法访问 不知道什么情况额~ IP 肯定没错啊

centos 7.0 lnmp成功安装过程(很乱)
[root@localhost sbin]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 6c:62:6d:73:e6:4a brd ff:ff:ff:ff:ff:ff
inet 192.168.1.103/24 brd 192.168.1.255 scope global enp2s0
valid_lft forever preferred_lft forever
inet6 fe80::6e62:6dff:fe73:e64a/64 scope link
valid_lft forever preferred_lft forever
centos 7.0 lnmp成功安装过程(很乱)

后记:

查询一个包是否被安装 
# rpm -q < rpm package name> 列出所有被安装的rpm package
# rpm -qa
centos 7.0 lnmp成功安装过程(很乱)
[root@localhost sbin]# rpm -qa
centos 7.0 lnmp成功安装过程(很乱)

lsof 安装 查询端口启用情况 可以查询 nginx是否启用

具体使用

[root@localhost sbin]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 13536 root 6u IPv4 32434 0t0 TCP *:http (LISTEN)
nginx 13548 nobody 6u IPv4 32434 0t0 TCP *:http (LISTEN)
centos 7.0 lnmp成功安装过程(很乱)
[root@localhost sbin]# yum -y install lsof
centos 7.0 lnmp成功安装过程(很乱)

使用vi命令

不保存退出:q!

保存退出:wq

插入数据    i

跳转到命令行   比如插入修改数据完成后 ESC 后输入 :wq  保存退出

centos 7.0 lnmp成功安装过程(很乱)
[root@localhost /]# find -name nginx  查看根目录下的所有nginx
./usr/etc/ngin/sbin/nginx
./usr/local/bin/nginx-1.7.9/objs/nginx
[root@localhost /]# yum remove nginx 尝试 删除默认yum安装的nginx
已加载插件:fastestmirror
参数 nginx 没有匹配
不删除任何软件包
centos 7.0 lnmp成功安装过程(很乱)

查询80端口

netstat -ano | grep 80  没有就先安装
yum -y install net-tools

centos 7.0 lnmp成功安装过程(很乱)
[root@localhost sbin]# yum -y install net-tools

[root@localhost sbin]# netstat -ano | grep 80
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN off (0.00/0/0)
tcp 0 0 192.168.1.103:38036 114.247.56.117:80 TIME_WAIT timewait (0.00/0/0)
unix 3 [ ] STREAM CONNECTED 16806 /var/run/dbus/system_bus_socket
unix 3 [ ] STREAM CONNECTED 20180
unix 3 [ ] STREAM CONNECTED 16805
centos 7.0 lnmp成功安装过程(很乱)

最后的最后 居然是防火墙的问题

CentOS 7.0默认使用的是firewall作为防火墙

关闭防火墙

systemctl stop firewalld.service #停止firewall

在IP 访问一切正常

systemctl disable firewalld.service #禁止firewall开机启动

[root@localhost init.d]# systemctl start firewalld.service 开启防火墙firewall
[root@localhost init.d]# firewall-cmd --state 查看防火墙firewall运行状态
running

启动后增加端口 通过规则

[root@localhost init.d]# firewall-cmd --add-port=80/tcp
success

再次访问 http://192.168.1.103/ 正常

centos 7.0 lnmp成功安装过程(很乱)

查看firewall 运行情况

[root@localhost init.d]# firewall-cmd --state

not running

接着mysql/mariadb的安装: yum install mysql mysql-server (yum install mariadb mariadb-server,启动服务器后,输入mysql_secure_installation回车进行修改命令)

然后php的安装:

安装 一些必要的 YUM 库

root 用户执行:

# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

安装 PHP 及重要插件 php-fpm

root 用户执行:

# yum install php-fpm php

配置、启动 php-fpm

配置 /etc/php.ini:

# 找到并取消注释,设置成:
cgi.fix_pathinfo=0

配置 /etc/php-fpm.d/www.conf:

# 找到并取消注释,设置成你希望管理 www 应用的用户(我这里统一用用户 theflash)
listen.owner = theflash
listen.group = theflash

启动 php-fpm 监听服务

# service php-fpm start

停止 php-fpm 监听服务

# service php-fpm stop

配置、启动 Nginx

更换网站目录所有者为 bp。  root 用户执行

# chown bp:bp /usr/etc/ngin/html -Rf

从此,以后就用用户 bp 来登录并维护

/usr/etc/ngin/html
中的数据

直接分享我的配置 /usr/etc/ngin/conf/nginx.conf

user bp;#把原来的那句注释去掉,修改用户名

events {
} http {
include /etc/nginx/mime.types;
server {
root /data/wwwroot; location / {
index index.html index.htm index.php;
} error_page 404 /404.html; location ~* \.php$ {
fastcgi_index index.php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;#改$document_root那里就可以了
include fastcgi_params;
}
}
}

重启 Nginx 服务器,这步也很关键

测试php是否能用vi /usr/etc/ngin/html/index.php,内容如下<?php    echo phpinfo();  ?>正常的话会正常显示php信息

现在来测试php是否能连接上mysql(mariadb),把网页文件内容改为

<?php
$link=mysql_connect('localhost','root','yourpassword');
if(!$link) echo "fail";
else echo "success";
mysql_close();
?>

连接正确会显示success,失败的话会显示fail

如果不能浏览网页的话,就直接把防火墙和selinux关闭,应该就可以,怎们在不关闭它们的情况下正常访问的配置我以后再加上来

原文http://www.cnblogs.com/xxx91hx/p/4245901.html