一、LNMP动态网站部署
1.1 Linux部署
stop firewalld
disable selinux
/etc/selinux/config
1.2 Nginx部署
yum install -y nginx
1.3 php-fpm部署
yum install -y php-fpm php-mysql php-gd #如果报错$ yum install mariadb-embedded mariadb-libs mariadbbench mariadb mariadb-sever
systemctl restart php-fpm
systemctl enable php-fpm #开机启动
netstat -anpt | grep 9000 #查看PHP端口号
vim /usr/share/nginx/html/index.php
#pnpinfo()调用PHP版本信息函数
<?php
phpinfo();
?>
vim /etc/nginx/conf.d/default.conf
#增加php主页 index.php
server {
location / {
...
index index.php index.html;
...
}
}
`vim /etc/nginx/conf.d/default.conf`
#启动nginx_fastcgi功能
server {
location / {
index index.php;
}
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
重启ngix
浏览器登录 192.168.238.132
1.4 mysql部署
RPM部署
yum -y install mariadb-server mariadb
systemctl start mariadb
systemctl enable mariadb
mysqladmin password '123456'
create database bbs;
grant all on bbs.* to phptest@'192.168.100.10' identified by '123456'; #IP输入自己的IP地址
flush privileges;
vim /usr/share/nginx/html/index.php
<?php
$link=mysqli_connect('192.168.100.10','phptest','123456');
if (!$link)
echo "Successfuly";
else
echo "Faile";
mysql_close();
?>
浏览器测试 Successfuly
1.5 业务上线
wget https://cn.wordpress.org/wordpress-4.9.1-zh_CN.zip
unzip wordpress-4.9.1-zh_CN.zip
rm -rf /usr/share/nginx/html/index.php
cp -rf /root/wordpress/* /usr/share/nginx/html
chown -R nginx.nginx /usr/share/nginx/html/*
chmod 777 /usr/share/nginx/html/
浏览器访问
如果出现wp-config.php文件不可写。请手动创建。
vim /usr/local/nginx/html/wp-config.php
#版本不同默认不同,如果没有 wp-config.php;默认文件是wp-config-sample.php
mv /usr/local/nginx/html/wp-config-sample.php /usr/local/nginx/html/wp-config.php
vim /usr/loacl/nginx/html/wp-config.php #修改mysql登录数据
***************
下面mysql数据库主机与编码版本不同设置不同
***************
我第二次尝试出错后更改了主机:localhost
编码:utf8
再访问浏览器
二、fastCGI & php-fpm
2.1 静态网站
nginx服务器能处理的是静态元素 .html .jpg .mp4 .css
2.2 nginx动态网站接口
ngx_fastcgi_modul 处理动态请求的接口 ## fastcgi 快速通用网关接口
fastCGI详解
nginx 通过ngx_fastcgi nginx 通过ngx_fastcgi_modul模块 链接 php-fpm处理动态请求。
2.3 php-fpm
PHP-FPM(FastCGI Process Manager:FastCGI进程管理器)
是一个PHP FastCGI管理器。
PHP通过php-fpm接收前台nginx的动态访问的请求,比如向后端Mysql进行查询请求后