Centos 7.6搭建LNMP环境的web服务器

一.安装软件

1.1.MYSQL安装

下载mysql的repo源:

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

安装mysql-community-release-el7-5.noarch.rpm包

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

安装MYSQL

sudo yum install -y  mysql-server

重启服务:

systemctl restart mysql 或
systemctl restart mysql.service

登录,并修改密码:

mysql -u root
mysql > use mysql;
mysql > update user set password=password(‘123456‘) where user=‘root‘;
mysql > grant all on *.* to admin@'%' identified by '123456' with grant option; 
mysql > flush privileges;
mysql
> exit;

修改yum源

下载对应当前系统版本的nginx包

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

安装 Nginx、PHP

yum -y install nginx
yum -y install php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64  php70w-pdo.x86_64   php70w-mysqlnd  php70w-fpm php70w-opcache 

php70w-pecl-redis php70w-pecl-mongo

配置默认编码为 utf8

vim /etc/my.cnf

设置开机启动:

[root@localhost ~]# systemctl enable mysqld

默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket 文件:/var/run/mysqld/mysqld.pid

配置 Nginx
安装完成以后查看自己防火墙是否开启,如果已开启,我们需要修改防火墙配置,开启 Nginx 外网端口访问。

[root@localhost ~]# systemctl status firewalld

如果显示 active (running),则需要调整防火墙规则的配置。

 

修改 /etc/firewalld/zones/public.xml文件,在zone一节中增加
保存后重新加载 firewalld 服务:

 

[root@localhost ~]# vim /etc/firewalld/zones/public.xml
<zone>
    ...
    <service name="nginx"/>
<zone>
[root@localhost ~]# systemctl reload firewalld

 

修改 Nginx 配置:

[root@localhost ~]# vim /etc/nginx/nginx.conf

location / {
    #定义首页索引文件的名称
    index index.php index.html index.htm;   
}

# PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置.
location ~ .php$ {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include fastcgi_params;
}

配置完成重启 Nginx

[root@localhost ~]# systemctl start nginx    # 启动 Nginx

设置开机启动:

[root@localhost ~]# systemctl enable nginx

3、设置开机启动 php-fpm

[root@localhost ~]# systemctl enable php-fpm
[root@localhost ~]# systemctl start php-fpm    # 启动 php-fpm

开启80端口:

iptables -I INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

四、测试

放入测试文件:

cd  /usr/share/nginx/html
echo '<?php phpinfo(); ?>' >info.php
  • 在 /usr/share/nginx/html 文件下创建php文件,输出 phpinfo 信息

  • 浏览器访问 http://<内网IP地址>/info.php,如果看到 PHP信息,说明安装成

​ 看启动状态:

systemctl status php-fpm.service 

posted @ 2019-01-07 17:15  人走茶良  阅读(1982)  评论(0编辑  收藏  举报
推荐:华为云