快速搭建LNMP环境

一、nginx安装

获取nginx源

yum localinstall http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

安装

yum -y install nginx

启动

systemctl start nginx

设置开机自启

systemctl enable nginx

在这里插入图片描述

二、php安装

获取yum源

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

安装模块

yum -y install php71w php71w-fpm php71w-mbstring php71w-common php71w-gd php71w-mcrypt php71w-mysql php71w-xml php71w-cli php71w-devel php71w-pecl-memcached php71w-pecl-redis php71w-opcache

php71w-mysql安装失败时,可以安装mysql-community-libs-compat-5.7.30-1.el7.x86_64.rpm
验证是否安装成功

php -v

启动

systemctl start  php-fpm.service

设置开机自启

systemctl enable  php-fpm

nginx与php连通
修改nginx配置文件

vim /etc/nginx/nginx.conf   在server里添加
location ~ .php$ {
        root           /usr/share/nginx/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;
}

重启nginx

systemctl reload nginx

创建php文件

vim /usr/share/nginx/html/1.php
<?php
phpinfo();
?>

在这里插入图片描述

三、mysql安装

移除mariadb

rpm -qa|grep mariadb
mariadb-libs-5.5.60-1.el7_5.x86_64
 yum remove mariadb-libs-5.5.60-1.el7_5.x86_64

安装mysql源

yum -y localinstall  http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm
yum -y install mysql-community-server install mysql-community-devel

启动mysql

systemctl start mysqld.service

设置开机自启

systemctl enable mysqld.service

查看密码

grep "password" /var/log/mysqld.log

登入mysql修改密码

mysql -uroot -p
set global validate_password_policy=0;
set global validate_password_length=1;
alter user 'root'@'localhost' identified by '123456';

mysql与php连通
vim /usr/share/nginx/html/2.php

<?php
$servername = "localhost";
$username = "root";
$password = "123456";
try {
$conn = new PDO("mysql:host=$servername;dbname=mysql;port=3306", $username, $password);
echo "successful";
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

real向往

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值