centos7 部署LNMP
Posted zoulixiang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7 部署LNMP相关的知识,希望对你有一定的参考价值。
1.安装nginx
使用Nginx官方提供的rpm包
[[email protected] ~]# 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安装
[[email protected] ~]# yum install nginx -y
[[email protected] ~]# systemctl start nginx
[[email protected] ~]# systemctl enable nginx
2.使用第三方扩展epel源安装php7.2
移除旧版php
[[email protected] ~]# yum remove php-mysql-5.4 php php-fpm php-common
安装扩展源
[[email protected] ~]# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
[[email protected] ~]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
安装php72版本
[[email protected] ~]# 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
[[email protected] ~]# systemctl start php-fpm
[[email protected] ~]# systemctl enable php-fpm
3.安装mysql
下载官方扩展源, 扩展源集成mysql5.6、5.7、8.0,仅5.7仓库是开启
[[email protected] ~]# rpm -ivh http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm
[[email protected] ~]# yum install mysql-community-server -y
[[email protected] ~]# systemctl start mysqld
[[email protected] ~]# systemctl enable mysqld
如果mysql登陆需要密码,请查看该文件
[[email protected] ~]# grep ‘temporary password‘ /var/log/mysqld.log
登陆mysql重新配置密码
[[email protected] ~]# mysql -uroot -p‘password‘
mysql> ALTER USER ‘root‘@‘localhost‘ IDENTIFIED BY ‘[email protected]‘; ###必须符合密码复杂性。
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测试页面
[[email protected] ~]# cat /usr/share/nginx/html/index.php
<?php
phpinfo();
?>
访问链接:http://192.168.10.145/index.php
以上是关于centos7 部署LNMP的主要内容,如果未能解决你的问题,请参考以下文章