欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 教育 > 锐评 > 麒麟操作系统服务架构保姆级教程(七)Nginx+PHP+Mysql部署服务

麒麟操作系统服务架构保姆级教程(七)Nginx+PHP+Mysql部署服务

2025/2/25 3:11:24 来源:https://blog.csdn.net/weixin_62408089/article/details/144853043  浏览:    关键词:麒麟操作系统服务架构保姆级教程(七)Nginx+PHP+Mysql部署服务

上边几篇文章已经交过大家二进制部署nginx和php,现在咱们打通nginx和php,mysql和php,开始部署服务,学会部署服务之后就可以开始学习负载均衡啦,话不多说,咱们直接开始~~~

目录

一、.nginx部署

二、安装PHP服务

三、安装数据库

四、打通Nginx和PHP的联通

五、打通Mysql和PHP的连接

​编辑

六、部署业务

七、统一服务的启动用户


💬欢迎交流:在学习过程中如果你有任何疑问或想法,欢迎在评论区留言,我们可以共同探讨学习的内容。你的支持是我持续创作的动力!

👍点赞、收藏与推荐:如果你觉得这篇文章对你有所帮助,请不要忘记点赞、收藏,并分享给更多的小伙伴!你们的鼓励是我不断进步的源泉!

🚀推广给更多人:如果你认为这篇文章对你有帮助,欢迎分享给更多对Linux感兴趣的朋友,让我们一起进步,共同提升!

一、.nginx部署

1、编译安装,参考之前的文章
https://blog.csdn.net/weixin_62408089/article/details/144616700?fromshare=blogdetail&sharetype=blogdetail&sharerId=144616700&sharerefer=PC&sharesource=weixin_62408089&sharefrom=from_link
2、yum安装
[root@web01 ~]#vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
​
yum -y install nginx

二、安装PHP服务

1、安装PHP
安装方式两种:
1).通过yum安装
[root@web01 ~]# yum -y install php php-bcmath php-cli php-common php-devel php-embedded php-fpm php-gd php-intl php-mbstring php-mysqlnd php-opcache php-pdo   php-process php-xml php-json
​
2).二进制编译安装,可以参考上篇文章
https://blog.csdn.net/weixin_62408089/article/details/144774614?fromshare=blogdetail&sharetype=blogdetail&sharerId=144774614&sharerefer=PC&sharesource=weixin_62408089&sharefrom=from_link3).检查安装是否成功
[root@web01 ~]#rpm -qa|grep php|wc -l
16
​
3.启动PHP服务
[root@web01 ~]#systemctl start php-fpm
[root@web01 ~]#systemctl enable php-fpmCreated symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to 
/usr/lib/systemd/system/php-fpm.service.
4.查看端口
[root@web01 ~]#netstat -tnulp|grep 9000Active Internet connections (only servers)Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      10443/php-fpm: mast 

三、安装数据库

1.安装Mariadb数据库 mysql--->Mariadb
mysql是常用的关系型数据库,MariaDB是MySQL的一个分支。由于Oracle收购了MySQL后,社区担心MySQL未来的开源性等诸多因素,因此Monty Widenius创建了MariaDB,语法和功能兼容:MariaDB的设计目标之一是与 MySQL兼容。在基本的SQL语法、存储过程、视图、索引等常见数据库功能上,MariaDB和MySQL非常相似。这意味着对于大多数用户来说,如果他们已经熟悉MySQL,切换到MariaDB在使用习惯上不会有太大的障碍这里我安装的是mariadb。
[root@web01 ~]#yum -y install mariadb-server
2.启动数据库
[root@web01 ~]#systemctl start mariadb
[root@web01 ~]#systemctl enable mariadb
3.检查端口3306
[root@web01 ~]#netstat -tnulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 127.0.0.1:9000          0.0.0.0:*               LISTEN      10443/php-fpm: mast 
tcp        0      0 0.0.0.0:3306            0.0.0.0:*               LISTEN      10774/mysqld 
4.修改数据库密码
[root@web01 ~]#mysqladmin password 'qy123.com'
5.登录测试
[root@web01 ~]#mysql -uroot -p'qy123.com'
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>quit       # quit退出数据库
Bye

四、打通Nginx和PHP的联通

[root@web01 conf.d]#cat php.conf 
server {listen 80;server_name www.php.com;root /php;location / {index index.php index.html;}location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
}
创建/php目录
mkdir /php
写入代码
[root@web01 conf.d]#cat /php/index.php 
<?phpphpinfo();
?>
windows做hosts解析
浏览器访问:  php.oldoy.com 显示php的信息

五、打通Mysql和PHP的连接

[root@web01 conf.d]#cat /php/mysql.php 
<?php$servername = "localhost";$username = "root";$password = "qy123.com";// 创建连接$conn = mysqli_connect($servername, $username, $password);// 检测连接if (!$conn) {die("Connection failed: " . mysqli_connect_error());}echo "php连接mysql成功";?><img style='width:100%;height:100%;' src=/477.png>
浏览器访问: http://www.php.com/mysql.php

六、部署业务

Nginx+MySQL+PHP部署完成
1.配置Nginx
[root@web01 conf.d]#cat wordpress.conf 
server {listen 80;server_name www.wp.com;root /code/wordpress;location / {index index.php index.html;}location ~ \.php$ {fastcgi_pass 127.0.0.1:9000;fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;include fastcgi_params;}
}
语法检测
[root@web01 conf.d]#nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
重启
[root@web01 conf.d]#systemctl restart nginx
2.创建代码目录/code/wordpress
[root@web01 conf.d]#mkdir /code/wordpress
3.下载wordpress代码到代码目录
[root@web01 wordpress]#wget https://cn.wordpress.org/wordpress-5.8.7-zh_CN.tar.gz4.解压代码
[root@web01 wordpress]#tar xf wordpress-5.8.7-zh_CN.tar.gz 
[root@web01 wordpress]#lltotal 15428drwxr-xr-x 5 1006 1006     
4096 May 17  2023 wordpress-rw-r--r-- 1 root root 15792879 May 17  2023 wordpress-5.8.7-zh_CN.tar.gz
[root@web01 wordpress]#mv wordpress/* .5.访问wordpres页面
windows做hosts解析
10.0.0.7   
www.wp.com
​
连接数据库创建wordpress库
[root@web01 wordpress]#mysql -uroot -pqy123.com -e "create database wordpress;"
[root@web01 wordpress]#mysql -uroot -pqy123.com -e "show databases;"+--------------------+| Database           |+--------------------+| information_schema || mysql              || performance_schema || test               || wordpress          |+--------------------+

 

回到服务器操作,将提示的内容写入文件中
[root@web01 wordpress]#vim wp-config.php
[root@web01 wordpress]#
输入信息

 

七、统一服务的启动用户

groupadd -g666 www
useradd -u666 -g666 -M -s /sbin/nologin www
修改nginx启动用户
[root@web01 ~]#head -3 /etc/nginx/nginx.conf
user  www;
修改后重启nginx
[root@web01 ~]#systemctl restart nginx
修改php启动用户
[root@web01 ~]#egrep '^user|^group' /etc/php-fpm.d/www.conf
user = www
group = www
[root@web01 ~]#systemctl restart php-fpm
检查是否修改成功
[root@web01 ~]#ps axu|grep nginx
root      11357  0.0  0.0  59444  1176 ?        Ss   12:04   0:00 nginx: master process /usr/sbin/nginx -c 
/etc/nginx/nginx.conf
www       11358  0.0  0.1  59940  2064 ?        S    12:04   0:00 nginx: worker process
root      11427  0.0  0.0 112808   968 pts/0    R+   12:06   0:00 grep --color=auto nginx
[root@web01 ~]#ps axu|grep php
root      11419  0.2  1.6 490152 32636 ?        Ss   12:05   0:00 php-fpm: master process (/etc/php
fpm.conf)www       11421  0.0  0.3 490152  7588 ?        S    12:05   0:00 php-fpm: pool wwwwww       11422  0.0  0.3 490152  7588 ?        S    12:05   0:00 php-fpm: pool www
最后将/code/wordpress 属主属组修改为www
[root@web01 ~]#chown -R www.www /code/wordpress/
后台地址:
http://www.wp.com/wp-login.php
http://www.wp.com/

今天的单机LNMP告一段落了,接下来咱们学习架构拆分~~~


想成为大佬,就要从小白开始,从0开始,一点一点的积累,慢慢成长,明天你就是大佬!!想学习更多麒麟操作系统的知识,关注小屁,让你成为运维老鸟~~~~~ 

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词