LNMP环境架构部署
部署Nginx支持fastcgi
fastcgi_pass 请求转发
官网文档
https://Nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_pass
Syntax: fastcgi_pass address;
Default: —
Context: location, if in location
Sets the address of a FastCGI server. The address can be specified as a domain name or IP address, and a port:
用法1,转发给ip:port形式
fastcgi_pass localhost:9000;
用法2,转发给unix socket本地进程套接字
fastcgi_pass unix:/tmp/fastcgi.socket;
设置fastcgi首页,需要结合fastcgi_param。
https://Nginx.org/en/docs/http/ngx_http_fastcgi_module.html#fastcgi_index
语法
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME /home/www/scripts/PHP$fastcgi_script_name;
具体配置
[root@web-8 /etc/Nginx/conf.d]#cat PHP.conf
server{
listen 80;
server_name yuchaoit.cn;
# 静态请求,资源存放路径
root /www;
index index.PHP index.html;
# 动态请求处理
location ~ \.PHP$ {
root /code;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
$document_root 就表示当前locatin设置的root或是alias的目录
SCRIPT_FILENAME 用于在PHP中确定脚本名字
fastcgi_script_name 请求的URL
整体意思是,用户发来的PHP相关请求,包括请求中的所有参数,全部转发给127.0.0.1:9000的PHP程序。
创建PHP程序目录
[root@web-8 ~]#mkdir -p /code
[root@web-8 ~]#chown -R www.www /code
[root@web-8 ~]#vim /code/test-PHPinfo.PHP
[root@web-8 /etc/Nginx/conf.d]#cat /code/test-PHPinfo.PHP
<?PHP
PHPinfo();
echo "welcome to yuchaoit.cn"
?>
检查Nginx语法且启动
[root@web-8 ~]#Nginx -t
Nginx: the configuration file /etc/Nginx/Nginx.conf Syntax is ok
Nginx: configuration file /etc/Nginx/Nginx.conf test is successful
[root@web-8 ~]#systemctl start Nginx
[root@web-8 ~]#pe -es | grep Nginx
-bash: pe: command not found
[root@web-8 ~]#pe -ef | grep Nginx
-bash: pe: command not found
[root@web-8 ~]#ps -ef | grep Nginx
root 2702 1 0 May25 ? 00:00:00 Nginx: master process /usr/sbin/Nginx -c /etc/Nginx/Nginx.conf
Nginx 2703 2702 0 May25 ? 00:00:00 Nginx: worker process
root 3797 3015 0 00:08 pts/1 00:00:00 grep --color=auto Nginx
绑定本地hosts
测试PHP和数据库的连通
先检查驱动是否正常,通过PHP-info页面,查看PHP的详细信息。
代码测试
[root@web-8 /etc/Nginx/conf.d]#cat /code/MysqL-test.PHP
<?PHP
$server="127.0.0.1";
$MysqL_user="root";
$MysqL_pwd="222222";
// 创建数据库连接
$conn=MysqLi_connect($server,$MysqL_user,$MysqL_pwd);
// 检测连通性
if($conn){
echo "MysqL successful by yuchaoit.cn \n";
}else {
die( "Connection Failed: " . MysqLi_connect_error());
}
?>
五、部署知识社区网站
1.创建Nginx虚拟主机
[root@web-8 /etc/Nginx/conf.d]#cat wecenter.conf
server{
listen 80;
server_name wecenter.laoliu.cc;
# 静态请求,资源存放路径
root /code/wecenter;
index index.PHP index.html;
# 动态请求处理
location ~ \.PHP$ {
root /code/wecenter;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
测试语法
[root@web-8 /etc/Nginx/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@web-8 /etc/Nginx/conf.d]#systemctl restart Nginx
2.获取wecenter源码
下载地址
[root@web-8 /etc/Nginx/conf.d]#mkdir /code/wecenter
[root@web-8 /etc/Nginx/conf.d]#cd /code/wecenter && wget http://yuchaoit.cn/data/wecenter.zip
解压缩,授权,进入PHP代码目录
unzip wecenter.zip
授权
chown -R www.www /code/
3.创建wecenter数据库
[root@web-8 /code/wecenter]#MysqL -uroot -p222222
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
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)]> create database wecenter character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> quit
Bye
4.访问页面
填入信息
MysqL -uroot -p222222
use wecenter;
show tables;
MariaDB [wecenter]> use wecenter;
Database changed
MariaDB [wecenter]> show tables;
+--------------------------------+
| Tables_in_wecenter |
+--------------------------------+
| aws_action_log |
| aws_active_data |
| aws_answer |
| aws_answer_comments |
| aws_answer_thanks |
| aws_answer_uninterested |
| aws_answer_Vote |
| aws_approval |
| aws_article |
| aws_article_comments |
| aws_article_Vote |
| aws_attach |
| aws_ban_ip |
| aws_category |
| aws_column |
| aws_column_focus |
| aws_draft |
| aws_edm_task |
| aws_edm_taskdata |
| aws_edm_unsubscription |
| aws_edm_userdata |
| aws_edm_usergroup |
| aws_education_experience |
| aws_favorite |
| aws_favorite_tag |
| aws_feature |
| aws_feature_topic |
| aws_geo_location |
| aws_help_chapter |
| aws_hook |
| aws_hook_plugins |
| aws_inBox |
| aws_inBox_dialog |
| aws_integral_log |
| aws_invitation |
| aws_jobs |
| aws_mail_queue |
| aws_menu |
| aws_nav |
| aws_nav_menu |
| aws_notes |
| aws_notification |
| aws_notification_data |
| aws_order_detail |
| aws_pages |
| aws_payment |
| aws_plugins |
| aws_posts_index |
| aws_product_order |
| aws_project |
| aws_project_like |
| aws_project_product |
| aws_question |
| aws_question_comments |
| aws_question_complain |
| aws_question_focus |
| aws_question_invite |
| aws_question_thanks |
| aws_question_uninterested |
| aws_received_email |
| aws_receiving_email_config |
| aws_redirect |
| aws_related_links |
| aws_related_topic |
| aws_report |
| aws_reputation_category |
| aws_reputation_topic |
| aws_school |
| aws_search_cache |
| aws_sessions |
| aws_sysaccount |
| aws_system_setting |
| aws_ticket |
| aws_ticket_invite |
| aws_ticket_log |
| aws_ticket_reply |
| aws_topic |
| aws_topic_focus |
| aws_topic_merge |
| aws_topic_relation |
| aws_user_account |
| aws_user_action_history |
| aws_user_action_history_data |
| aws_user_action_history_fresh |
| aws_user_follow |
| aws_user_refund |
| aws_user_withdraw |
| aws_users |
| aws_users_attrib |
| aws_users_facebook |
| aws_users_google |
| aws_users_group |
| aws_users_notification_setting |
| aws_users_online |
| aws_users_qq |
| aws_users_sina |
| aws_users_twitter |
| aws_users_ucenter |
| aws_users_weixin |
| aws_verify_apply |
| aws_weibo_msg |
| aws_weixin_accounts |
| aws_weixin_login |
| aws_weixin_message |
| aws_weixin_msg |
| aws_weixin_qr_code |
| aws_weixin_reply_rule |
| aws_weixin_template |
| aws_weixin_third_party_api |
| aws_work_experience |
+--------------------------------+
110 rows in set (0.00 sec)
MariaDB [wecenter]> quit
Bye
xafei
l123456
[email protected]
安装完毕后,删除安装程序
[root@web-8 /code/wecenter]#ls
app index.PHP Nginx.htaccess system views
cache install plugins tmp wecenter.zip
changelog.txt language README.md uploads
composer.json license.txt robots.txt vendor
composer.lock models static version.PHP
删除
[root@web-8 /code/wecenter]#rm -rf install/
登录问答网站
可以在数据库中查询到用户信息。
[root@web-8 /code/wecenter]#MysqL -uroot -p222222
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 14
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)]> select user_name,password from wecenter.aws_users;
+-----------+----------------------------------+
| user_name | password |
+-----------+----------------------------------+
| xafei | a713e5ae6ce99b7d6cb61915f5dd80ef |
+-----------+----------------------------------+
1 row in set (0.00 sec)
部署wordpress
Nginx环境搭建
[root@web-8 /etc/Nginx/conf.d]#cat wordpress.conf
server{
listen 80;
server_name wordpress.laoliu.cc;
# 静态请求,资源存放路径
root /code/wordpress;
index index.PHP index.html;
# 动态请求处理
location ~ \.PHP$ {
root /code/wordpress;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
2.重启Nginx
[root@web-7 /etc/Nginx/conf.d]#systemctl restart Nginx
3.解压
mkdir -p /code/wordpress ; cd /code/wordpress ; wget https://cn.wordpress.org/latest-zh_CN.zip
解压缩
unzip latest-zh_CN.zip
mv wordpress/* .
授权
[root@web-8 /code/wordpress]#chown -R www.www /code/
4.创建数据库
[root@web-7 /code/wordpress]#MysqL -uroot -p222222
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
dns解析
客户端访问
发表文章
检查数据库
[root@web-8 /code/wordpress]#!MysqL
MysqL -uroot -p222222
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 51
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)]> show databases;
+--------------------+
| Database |
+--------------------+
| @R_792_4045@ion_schema |
| MysqL |
| performance_schema |
| test |
| wecenter |
| wordpress |
+--------------------+
6 rows in set (0.00 sec)
MariaDB [(none)]>
查看数据表
MariaDB [wordpress]> show tables;
查看文章表
MariaDB [wordpress]> desc wp_posts;
查看文章数据
MariaDB [wordpress]>select post_content from wp_posts;
自建yum源
[root@master-61 ~]#mkdir /yumrpm
[root@master-61 ~]#mkdir /yumrpm
[root@master-61 ~]#cd /yumrpm/
[root@master-61 /yumrpm]#ll
total 0
[root@master-61 /yumrpm]#rz -E
rz waiting to receive.
[root@master-61 /yumrpm]#ll
total 83908
-rw-r--r-- 1 root root 85919950 May 26 13:33 all-rpm.tgz
[root@master-61 /yumrpm]#tar -zxf all-rpm.tgz
[root@master-61 /yumrpm]#ll
total 83924
-rw-r--r-- 1 root root 85919950 May 26 13:33 all-rpm.tgz
drwxr-xr-x 2 root root 12288 May 26 07:56 local_yum_rpm
[root@master-61 /yumrpm]#yum install Nginx -y
[root@master-61 /yumrpm]#cd /etc/Nginx/conf.d/
[root@master-61 /etc/Nginx/conf.d]#ls
[root@master-61 /etc/Nginx/conf.d]#vim download.conf
[root@master-61 /etc/Nginx/conf.d]#cat download.conf
server {
listen 23456;
server_name localhost;
charset utf-8;
location / {
root /yumrpm/;
autoindex on;
autoindex_localtime on;
autoindex_exact_size off;
}
}
[root@master-61 /etc/Nginx/conf.d]#systemctl start Nginx
[root@master-61 /etc/Nginx/conf.d]#systemctl enable Nginx
Created symlink from /etc/systemd/system/multi-user.target.wants/Nginx.service to /usr/lib/systemd/system/Nginx.service.
[root@master-61 /etc/Nginx/conf.d]#yum install createrepo -y
[root@master-61 /yumrpm]#createrepo /yumrpm/
Spawning worker 0 with 160 pkgs
Workers Finished
Saving Primary Metadata
Saving file lists Metadata
Saving other Metadata
Generating sqlite DBs
sqlite DBs complete
[root@web-7 /etc/yum.repos.d]#cat yumrpm.repo
[all-rpm]
name=all repo
baseurl=http://10.0.0.61:23456
enabled=1
gpgcheck=0
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。