centos7利用yum安装lnmp的教程(linux+nginx+php7.1+mysql5.7)
Posted 无它唯手熟尔
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7利用yum安装lnmp的教程(linux+nginx+php7.1+mysql5.7)相关的知识,希望对你有一定的参考价值。
步骤如下:
yum的安装
1
|
yum update |
yum安装nginx
安装nginx最新源
1
2
|
yum localinstall http: //nginx .org /packages/centos/7/noarch/RPMS/nginx-release-centos-7-0 .el7.ngx.noarch.rpm yum repolist enabled | grep "nginx*" |
安装nginx
1
|
yum -y install nginx |
启动nginx
1
|
service nginx start |
设置nginx服务器开机自启动
1
|
systemctl enable nginx.service |
检查开机自动是否设置成功
1
|
systemctl list-dependencies | grep nginx |
浏览器中输入公网ip,检测是否安装成功
使用yum安装mysql5.7
安装mysql源
1
2
|
yum -y localinstall http: //dev .mysql.com /get/mysql57-community-release-el7-7 .noarch.rpm yum repolist enabled | grep "mysql.*-community.*" |
安装mysql
1
|
yum -y install mysql-community-server install mysql-community-devel |
启动mysql
1
|
service mysqld start |
检查mysql启动是否正常
1
|
service mysqld status 或者 ps -ef | grep mysql |
设置mysqld服务开机自启动
1
|
systemctl enable mysqld.service |
检查mysqld开机自启动是否设置成功
1
|
systemctl list-dependencies | grep mysqld |
mysql5.7以后的争强了安全机制, 所以使用yum安装,启动会系统会自动生成一个随机的密码,修改mysql密码
查看mysql的随机密码
1
|
grep ‘temporary password‘ /var/log/mysqld .log |
使用查询得到的随机密码在终端登录
1
2
|
mysql -u root -p 更改密码(mysql文档规定,密码必须包括大小写字母数字加特殊符号>8位) ALTER USER ‘root‘ @ ‘localhost‘ IDENTIFIED BY ‘Yourpassword‘ ; |
退出mysql客户端,用刚才修改的密码登录确保密码修改成功
1
2
|
exit ; mysql -u root -p |
安装php7.1
安装php源
1
2
|
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 |
检查源是否安装成功
1
|
yum repolist enabled | grep "webtatic*" |
安装php扩展源
1
2
3
4
|
yum -y install php71w php71w-fpm yum -y install php71w-mbstring php71w-common php71w-gd php71w-mcrypt yum -y install php71w-mysql php71w-xml php71w-cli php71w-devel yum -y install php71w-pecl-memcached php71w-pecl-redis php71w-opcache |
验证php7.1.x和扩展是否安装成功
验证php是否安装成功
1
|
php - v |
验证对应的扩展是否安装成功
1
|
php -m |
设置php-fpm并检测php-fpm的运行状态
启动php-fpm
1
|
service php-fpm star |
检查启动是否成功
1
|
service php-fpm status |
设置开机自启动
1
|
systemctl enable php-fpm.service |
检查开机自启动是否设置成功
1
2
|
systemctl list-dependencies | grep php-fpm ps -ef | grep php-fpm |
nginx配置如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
server{ listen 80; server_name youserver; index index.html index.php; root /home/public ; #charset koi8-r; #access_log logs/host.access.log main; location / { index index.html index.htm index.php; try_files $uri $uri/ /index .php?$query_string; } error_page 404 /404 .html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x .html; location = /50x .html { root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ .php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ .php$ { root /home/public ; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /home/public $fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache‘s document root # concurs with nginx‘s one # location ~ /.ht { deny all; } } |
以上是关于centos7利用yum安装lnmp的教程(linux+nginx+php7.1+mysql5.7)的主要内容,如果未能解决你的问题,请参考以下文章