ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

LAMP单虚拟机部署网站

2022-07-25 22:02:58  阅读:218  来源: 互联网

标签:部署 虚拟机 aws nginx LAMP conf MariaDB root fastcgi


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和数据库的连通

先检查驱动是否正常,通过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
1398787859@qq.com

安装完毕后,删除安装程序

[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           |
+--------------------+
| information_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


标签:部署,虚拟机,aws,nginx,LAMP,conf,MariaDB,root,fastcgi
来源: https://www.cnblogs.com/Xafei/p/16518992.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有