CentOS7下部署LNMP服务上架
环境准备:
服务器1:192.168.248.100 搭载http、MySQL服务
服务器2:192.168.248.101 搭载DNS服务
配置yum源
- PHP与Apache的安装
yum install -y php
#安装php时,会预装Apache
#查看httpd状态
systemclt status httpd
systemctl start httpd
测试访问:
Apache服务器地址:192.168.248.100
测试php是否可以运行(默认的Apache站点目录:/var/www/html/)
cd /var/www/html/
vim index.php
#在index中写入
<?php
phpinfo();
重启http服务,查看测试页:
systemctl restart httpd
打开服务器防火墙
firewall-cmd --permanent --add-service=http
success
firewall-cmd --permanent --add-service=https
success
firewall-cmd --reload
success
访问:http://192.168.248.100/
2. MariaDB的安装与初始化
安装MariaDB
yum install -y mariadb-server
初始化
#初始化前启动MariaDB
systemctl status mariadb
systemctl start mariadb
#初始化
mysql_secure_installation
#配置文件
[root@localhost /]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
#进入配置
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
#设置数据库密码
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
#删除匿名账户
Remove anonymous users? [Y/n] y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
#允许root远程登陆
Disallow root login remotely? [Y/n] y
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
#删除测试数据库
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
#添加权限
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
初始化完成
测试命令行登录:
mysql -u root -p
如果需要远程登陆,则需要修改登陆主机
MariaDB [mysql]> update user set host = '%' where host = '127.0.0.1';
MariaDB [mysql]> select user,host from user;
重启MariaDB或者刷新权限:
Mysql>flush privileges;
防火墙放行安全组端口:
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --add-port=80/tcp --permanent
#个别需要关闭防火墙,否则navicat无法访问
systemctl stop firewalld
使用navicat进行远程登陆:
3. 项目上线
项目使用Discuz_X3.2_SC_GBK
解压Discuz_X3.2_SC_GBK.zip,将upload其中的内容上传到服务器站点目录(/var/www/html/)
使用filezille将文件上传到Linux服务器
查看文件
上传完成后,重启http服务
systemctl restart httpd
systemctl status httpd
访问服务器:192.168.248.100
乱码修改方法:修改/etc/php.ini 文件
vim /etc/php.ini
#重启http服务
systemctl restart httpd
开始安装Discuz
赋予指定目录权限
chmod 777 /var/www/html
重启服务,刷新安装页面,如果失败,则重启服务器
缺少扩展函数mysqli_connect()
安装mysqli_connect()
#安装mysqli_connect
yum install -y mysqli*
或者
yum install -y php-mysql
配置数据库
开始安装
项目上线成功
如果需要域名解析,添加DNS服务即可!