-
构建LNMP平台
-
步骤一:创建并修改php-fpm配置文件
-
1)查看php-fpm配置文件
[root@svr5 etc]# vim /etc/php-fpm.d/www.conf
[www]
listen = 127.0.0.1:9000
listen.allowed_clients = 127.0.0.1
user = apache
group = apache
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
- 2)确认php-fpm服务已经启动
[root@svr5 ~]# systemctl restart php-fpm
[root@svr5 ~]# systemctl status php-fpm
- 步骤二:修改Nginx配置文件并启动服务
[root@svr5 ~]# vim /usr/local/nginx/conf/nginx.conf
location / {
root 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 $document_root$fastcgi_script_name;
include fastcgi.conf;
}
[root@svr5 ~]# /usr/local/nginx/sbin/nginx -s reload
-
步骤三:创建PHP页面,测试LNMP架构能否解析PHP页面
-
1)创建PHP测试页面1:
[root@svr5 ~]# vim /usr/local/nginx/html/test1.php
<?php
phpinfo();
?>
- 2)创建PHP测试页面,连接MariaDB数据库:
[root@svr5 ~]# vim /usr/local/nginx/html/test2.php
<?php
$links=mysql_connect("localhost","root","密码");
#注意:root为mysql账户名称,密码需要修改为实际mysql密码,无密码则留空即可
if($links){
echo "link db ok!!!";
}
else{
echo "link db no!!!";
}
?>
- 3)创建PHP测试页面,连接并查询MariaDB数据库:
[root@svr5 ~]# vim /usr/local/nginx/html/test3.php
<?php
$mysqli = new mysqli('localhost','root','','mysql');
if (mysqli_connect_errno()){
die('Unable to connect!'). mysqli_connect_error();
}
$sql = "select * from user";
$result = $mysqli->query($sql);
while($row = $result->fetch_array()){
printf("Host:%s",$row[0]);
printf("</br>");
printf("Name:%s",$row[1]);
printf("</br>");
}
?>
- 4)客户端使用浏览器访问服务器PHP首页文档,检验是否成功:
[root@client ~]# firefox http://192.168.4.5/test1.php
[root@client ~]# firefox http://192.168.4.5/test2.php
[root@client ~]# firefox http://192.168.4.5/test3.php