记录下在CentOS 7 安装 LNMP 环境(PHP7 + MySQL5.7 + Nginx1.10)过程笔记。
工具
VMware版本号 : 12.0.0
CentOS版本 : 7.0
一、修改 yum 源
[root@localhost ~]# rpm -Uvh https://dl.Fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[root@localhost ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
[root@localhost ~]# rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpmWebtatic:https://webtatic.com
MySQL:https://dev.mysql.com/downloa…
二、安装 Nginx、MySQL、PHP
[root@localhost ~]# yum -y install nginx
[root@localhost ~]# yum -y install mysql-community-server
[root@localhost ~]# 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三、配置
1、配置 MySQLMySQL 安装完成之后,在 /var/log/mysqld.log 文件中给 root 生成了一个默认密码
通过下面的方式找到root 默认密码,然后登录 MySQL 进行修改:
[root@localhost ~]# systemctl start mysqld # 启动 MySQL
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log # 查找默认密码2017-04-10T02:58:16.806931Z 1 [Note] A temporary password is generated for root@localhost: iacFXpWt-6gJ登录 MySQL:
[root@localhost ~]# mysql -uroot -p'iacFXpWt-6gJ'修改root 默认密码:
mysql> ALTER USER'root'@'localhost' IDENTIFIED BY 'MyPass1!';或者:
mysql> set password for'root'@'localhost'=password('123abc'); 详见 MySQL 官网密码策略详细说明:https://dev.mysql.com/doc/ref…
配置默认编码为 utf8:
修改 /etc/my.cnf 配置文件,在 [mysqld] 下添加编码配置,配置完成后重启:
[root@localhost ~]# vim /etc/my.cnf[mysqld]character_set_server=utf8
init_connect='SET NAMES utf8'[root@localhost ~]# systemctl restart mysqld # 重启 MySQL设置开机启动:
[root@localhost ~]# systemctl enable mysqld默认配置文件路径:
配置文件:/etc/my.cnf
日志文件:/var/log/mysqld.log
服务启动脚本:/usr/lib/systemd/system/mysqld.service
socket 文件:/var/run/mysqld/mysqld.pid
2、配置 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在 server {} 里添加:
location / {
#定义首页索引文件的名称index index.php index.html index.htm;
}
# PHP 脚本请求全部转发到 FastCGI处理. 使用FastCGI默认配置.location~ .php$ {
fastcgi_pass127.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注:本文只是简单配置 Nginx,具体更多配置请自行百度。
设置开机启动:
[root@localhost ~]# systemctl enable nginx3、设置开机启动 php-fpm:
[root@localhost ~]# systemctl enable php-fpm
[root@localhost ~]# systemctl start php-fpm # 启动 php-fpm四、测试
在
/usr/share/nginx/html文件下创建php文件,输出phpinfo信息
文章来源网络,作者:运维,如若转载,请注明出处:https://shuyeidc.com/wp/221204.html<

