1. 程式人生 > >centos7 部署LNMP

centos7 部署LNMP

cal system 5.6 install emctl class pca root alter

1.安裝Nginx

使用Nginx官方提供的rpm包

[root@nginx ~]# cat /etc/yum.repos.d/nginx.repo

[nginx]

name=nginx repo

baseurl=http://nginx.org/packages/centos/7/$basearch/

gpgcheck=0

enabled=1

//2.執行yum安裝

[root@nginx ~]# yum install nginx -y

[root@nginx ~]# systemctl start nginx

[root@nginx ~]# systemctl enable nginx

2.使用第三方擴展epel源安裝php7.2

移除舊版php

[root@nginx ~]# yum remove php-mysql-5.4 php php-fpm php-common

安裝擴展源

[root@nginx ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

[root@nginx ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

安裝php72版本

[root@nginx ~]# yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache

啟動php

[root@nginx ~]# systemctl start php-fpm

[root@nginx ~]# systemctl enable php-fpm

3.安裝mysql

下載官方擴展源, 擴展源集成mysql5.6、5.7、8.0,僅5.7倉庫是開啟

[root@nginx ~]# rpm -ivh http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm

[root@nginx ~]# yum install mysql-community-server -y

[root@nginx ~]# systemctl start mysqld

[root@nginx ~]# systemctl enable mysqld

如果mysql登陸需要密碼,請查看該文件

[root@nginx ~]# grep ‘temporary password‘ /var/log/mysqld.log

登陸mysql重新配置密碼

[root@nginx ~]# mysql -uroot -p‘password‘

mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘zlx!@345‘; ###必須符合密碼復雜性。

4.配置php 結合nginx

Vi /etc/nginx/conf/conf.d/default.conf

server {

listen 80;

server_name localhost;

location / {

root /usr/share/nginx/html;

index index.php index.html index.htm;

}

location ~ \.php$ {

root html;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

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

include fastcgi_params;

}

5.添加php測試頁面

[root@nginx ~]# cat /usr/share/nginx/html/index.php

<?php

phpinfo();

?>

訪問鏈接:http://192.168.10.145/index.php

技術分享圖片

centos7 部署LNMP