目录
[安装 nginx](#安装 nginx)
[安装 mysql](#安装 mysql)
[安装 php](#安装 php)
[配置 nginx 支持 PHP 解析](#配置 nginx 支持 PHP 解析)
安装 nginx
修改yum源
将原本的yum源备份
vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
清除缓存,加载配置
yum clean all && yum makecache fast
yum安装nginx
yum install nginx -y
systemctl start nginx(开启nginx服务)
systemctl enable nginx(设置开机自启)
安装 mysql
桌面安装可能带有mariadb,先删除。
yum remove mariadb* -y
修改yum源
cd /etc/yum.repos.d
下载mysql57的yum源
wget https://repo.mysql.com/mysql57-community-release-el7-11.noarch.rpm
rpm -ivh mysql57-community-release-el7-11.noarch.rpm
sed -i 's/gpgcheck=1/gpgcheck=0/' mysql-community.repo
备份原来的yum源
mv nginx.repo localbak
yum安装
yum -y install mysql-server
systemctl start mysqld.service(开启mysql服务)
systemctl enable mysqld.service(设置开机自启)
在日志文件中找出root用户的初始密码
grep "password" /var/log/mysqld.log
也可以使用正则表达式提取出密码
grep "password" /var/log/mysqld.log | awk '{print $NF}'
登录 mysql
mysql -uroot -p
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Admin@123';
授权远程登录
grant all privileges on *.* to 'root'@'%' identified by 'Admin@123' with grant option;
重新加载授权
flush privileges;
安装 php
修改yum源
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum -y install epel-release
yum -y install https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum安装php
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
国外网站可能网络不稳定无法完成,这时可以使用本地安装
将下载好的软件包上传到机器上
解压
tar xf php.tar.gz
将解压出来的rpm包移动到一个文件夹中
mkdir php-pkgs
mv *rpm php-pkgs
createrepo php-pkgs(解决软件的依赖关系,生成一个数据库文件)
修改yum源
cd /etc/yum.repos.d/
将现有源移入备份中
mv *.repo ./localbak/
将local.repo移出来
mv local.repo ./
修改local.repo文件
清理缓存,加载配置
yum clean all && yum makecache fast
再yum安装
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
安装完毕
systemctl start php-fpm(开启服务)
systemctl enable php-fpm(设置开机自启)
配置lnmp
配置 nginx 支持 PHP 解析
修改nginx配置
vim /etc/nginx/conf.d/default.conf
取消php块的注释
上图红框内容与这处保持一致:
检查配置文件修改是否有误
nginx -t
无误则重启服务
systemctl restart nginx
修改php配置文件
vim /etc/php.ini
date.timezone = Asia/Shanghai
vim /etc/php-fpm.d/www.conf
systemctl restart php-fpm.service
vi /etc/nginx/conf.d/default.conf
systemctl restart nginx
编写php测试页面
vim /usr/share/nginx/html/index.php
vim index.php
<?php
phpinfo();
?>
浏览器访问
测试mysql是否能连接成功
vim /usr/share/nginx/html/test.php
<?php
$link=mysqli_connect('192.168.110.60','root','Admin@123');
if($link) echo "<h1> connect successfully </h1>";
else echo "<h1> connect failed </h1>";
?>
浏览器访问
完成