Linux中LAMP/LNMP環境下部署網站/導入項目【VMware環境下】

来源:https://www.cnblogs.com/wangyang0210/archive/2018/09/19/9673707.html
-Advertisement-
Play Games

環境搭建 無人值守搭建 LNMP一鍵安裝包無人值守命令生成器 支持LAMP/LNMP/LNMPA的一鍵搭建,根據自己的需求配置好之後點擊生成就會生成腳本,然後只需簡單的複製粘貼,再去喝杯咖啡回來後即可享受已經生成好的環境。 當然前提是你要把虛擬機的網路配置好吆~一定要能夠和外網連通哦(づ ̄ 3 ̄)づ ...


環境搭建

  1. 無人值守搭建

    LNMP一鍵安裝包無人值守命令生成器

    支持LAMP/LNMP/LNMPA的一鍵搭建,根據自己的需求配置好之後點擊生成就會生成腳本,然後只需簡單的複製粘貼,再去喝杯咖啡回來後即可享受已經生成好的環境。

    當然前提是你要把虛擬機的網路配置好吆~一定要能夠和外網連通哦(づ ̄ 3 ̄)づ

  2. 手動搭建【LAMP】

    突然想起來,之前給一位同學錄的視頻,剛好是從虛擬機搭建到LAMP環境的配置,這邊剛好拿來用,O(∩_∩)O哈哈~

    錄視頻的時候忘記關閉錄製聲音了,所以看視頻的時候未滿18歲的一定要把聲音關了,不關的請在大人陪同下觀看~

    鏈接:https://pan.baidu.com/s/1RMHzve9y3XnbMe_3zeL-cg 密碼:r7yq

    好了,正文開始恢復快照,開始搭建LAMP

    快照環境:

         IP配置完成

           防火牆已關閉/selinux已關閉

           LAMP包已經導入

          鏡像已導入

    參考文檔:

         龍哥秘制~

 第一步:配置本地yum源

 1.掛載鏡像

  1.1 直接掛載鏡像文件,前提鏡像文件已經導入,本人比較喜歡,有安全感,掛載後不要忘記查看下~

# mount -o loop CentOS-6.8-i386-bin-DVD1.iso  /mnt/

  # ll /mnt/
  總用量 542
  -r--r--r--. 2 root root 14 5月 22 2016 CentOS_BuildTag
  -r--r--r--. 2 root root 212 11月 27 2013 EULA
  -r--r--r--. 2 root root 18009 11月 27 2013 GPL
  dr-xr-xr-x. 3 root root 2048 5月 23 2016 images
  dr-xr-xr-x. 2 root root 2048 5月 22 2016 isolinux
  dr-xr-xr-x. 2 root root 514048 5月 23 2016 Packages
  -r--r--r--. 2 root root 1359 5月 22 2016 RELEASE-NOTES-en-US.html
  dr-xr-xr-x. 2 root root 4096 5月 23 2016 repodata
  -r--r--r--. 2 root root 1706 11月 27 2013 RPM-GPG-KEY-CentOS-6
  -r--r--r--. 2 root root 1730 11月 27 2013 RPM-GPG-KEY-CentOS-Debug-6
  -r--r--r--. 2 root root 1730 11月 27 2013 RPM-GPG-KEY-CentOS-Security-6
  -r--r--r--. 2 root root 1734 11月 27 2013 RPM-GPG-KEY-CentOS-Testing-6
  -r--r--r--. 1 root root 3165 5月 23 2016 TRANS.TBL

  1.2 掛載光碟機/dev/cdrom,總感覺這樣掛載會少點什麼所以我一般不用這個掛載

# mount -o loop /dev/cdrom /mnt/

 

  上面掛載都只是臨時的,一旦重啟將會消失,因為我們都想持久,所以這裡我們要轉下

 

2.在/opt下創建文件夾centos

# mkdir /opt/centos

 

3.將/mnt下的文件複製到/opt/centos下

# cp -rvf /mnt/* /opt/centos

 

4.將原有yum源移到備份文件夾中

# mv /etc/yum.repos.d/* /yumback

 

5.製作本地yum源

# vi /etc/yum.repos.d/centos.repo

  [centos]              #倉庫的名稱必須是獨一無二的
  name=centos            #對倉庫的描述
  gpgcheck=0             #是否是否進行gpg(GNU Private Guard) 校驗,以確定rpm 包的來源是有效和安全的。1開啟0關閉
  enabled=1              #組的可用性,1可用0不可用   
  baseurl=file:///opt/centos    #倉庫地址支持file/ftp/url/http 我知道就這些,因為本地所以我們使用file協議即可

 

6.清除緩存並重新顯示所有軟體包

# yum clean all
# yum list

  ps:遇到報錯可能有以下原因

    1.防火牆未關閉

    2.yum配置錯誤

    3.具體請看報錯信息,yum的總結的文件在另一個筆記本上,但是一般都是這兩個問題~

第二步: 解壓源碼包/安裝gcc和gcc-c++

     開兩個遠程視窗,一個解壓一個安裝

# yum install -y gcc gcc-c++ 
#編寫解壓腳本
# vi tar.sh

  #!/bin/bash

ls lamp/ > list
for TAR in `cat list`

do
  tar -zxvf lamp/$TAR -C lamp/

  done


  rm list

# chmod 777 tar.sh 

# sh tar.sh 

 

 第三步:安裝軟體包

   1.安裝libxml2

    1.1 安裝libxml2-devel python-devel

yum  install  -y  libxml2-devel   python-devel

    1.2 進入到lamp/libxml2-2.9.1目錄下執行檢查和編譯安裝

[root@centos_6_8 ~]# cd lamp/libxml2-2.9.1
[root@centos_6_8 libxml2-2.9.1]# ./configure --prefix=/usr/local/libxml2/   #進行下一步的時候,請確定是檢查完成而不是因為錯誤停止,否則無法進行編譯安裝
[root@centos_6_8 libxml2-2.9.1]# make && make install

 

  

  2.安裝libmcrypt

    每一次安裝下一個軟體包的時候,都必須保證上一個軟體包是真正的安裝完成停止的,不是因為錯誤而停止的.

    2.1  進入到lamp/libmcrypt-2.5.8目錄下執行檢查和編譯安裝

[root@centos_6_8 ~]# cd lamp/libmcrypt-2.5.8
[root@centos_6_8 libmcrypt-2.5.8]# ./configure --prefix=/usr/local/libmcrypt/
[root@centos_6_8 libmcrypt-2.5.8]# make && make install

    2.2  進入到lamp/libmcrypt-2.5.8/libltdl/目錄下執行檢查和編譯安裝

[root@centos_6_8 libmcrypt-2.5.8]# cd libltdl/
[root@centos_6_8 libltdl]#  ./configure --enable-ltdl-install
[root@centos_6_8 libltdl]# make && make install

  3.安裝mhash

[root@centos_6_8 ~]# cd lamp/mhash-0.9.9.9
[root@centos_6_8 mhash-0.9.9.9]# ./configure
[root@centos_6_8 mhash-0.9.9.9]# make && make install

  4.安裝mcrypt

[root@centos_6_8 ~]# cd lamp/mcrypt-2.6.8
[root@centos_6_8 mcrypt-2.6.8]# LD_LIBRARY_PATH=/usr/local/libmcrypt/lib:/usr/local/lib ./configure --with-libmcrypt-prefix=/usr/local/libmcrypt
[root@centos_6_8 mcrypt-2.6.8]# make && make install

  5.安裝zlib

[root@centos_6_8 ~]# cd lamp/zlib-1.2.3
[root@centos_6_8 zlib-1.2.3]# ./configure
[root@centos_6_8 zlib-1.2.3]# make && make install >>/root/zlib.log

  6.安裝libpng

[root@centos_6_8 ~]# cd lamp/libpng-1.2.31
[root@centos_6_8 libpng-1.2.31]#  ./configure --prefix=/usr/local/libpng
[root@centos_6_8 libpng-1.2.31]# make && make install

  7.安裝jpeg6

    7.1 手動創建目錄

mkdir /usr/local/jpeg6    
mkdir /usr/local/jpeg6/bin
mkdir /usr/local/jpeg6/lib
mkdir /usr/local/jpeg6/include
mkdir -p /usr/local/jpeg6/man/man1

    7.2 進入到lamp/jpeg-6b的目錄進行編譯安裝

[root@centos_6_8 ~]# cd lamp/jpeg-6b/
[root@centos_6_8 jpeg-6b]#  ./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
[root@centos_6_8 jpeg-6b]# make && make install

  8.安裝freetype

[root@centos_6_8 ~]# cd lamp/freetype-2.3.5
[root@centos_6_8 freetype-2.3.5]# ./configure --prefix=/usr/local/freetype/
[root@centos_6_8 freetype-2.3.5]# make && make install

  9.安裝Apache

    9.1 將apr-1.4.6和apr-util-1.4.1複製到httpd-2.4.7的目錄下

#cp  -rvf  lamp/apr-1.4.6  lamp/httpd-2.4.7/srclib/apr
#cp  -rvf  lamp/apr-util-1.4.1  lamp/httpd-2.4.7/srclib/apr-util

    9.2 進入到lamp/pcre-8.34目錄進行編譯安裝

[root@centos_6_8 ~]# cd lamp/pcre-8.34
[root@centos_6_8 pcre-8.34]# ./configure && make && make install

    9.3 進入到 lamp/httpd-2.4.7目錄進行編譯安裝

[root@centos_6_8 ~]# cd lamp/httpd-2.4.7/
[root@centos_6_8 httpd-2.4.7]#  ./configure --prefix=/usr/local/apache2/ --sysconfdir=/usr/local/apache2/etc/ --with-included-apr --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared 
[root@centos_6_8 httpd-2.4.7]# make && make install

    9.4 啟動測試

      9.4.1 查看服務進程是否運行

[root@centos_6_8 ~]# /usr/local/apache2/bin/apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.13.111. Set the 'ServerName' directive globally to suppress this message
 [root@centos_6_8 ~]# ps aux | grep httpd   
 root 8650 0.0 0.2 5196 2444 ? Ss 11:42 0:00 /usr/local/apache2//bin/httpd -k start
 daemon 8651 0.0 0.2 282928 2148 ? Sl 11:42 0:00 /usr/local/apache2//bin/httpd -k start
 daemon 8652 0.0 0.2 282928 2152 ? Sl 11:42 0:00 /usr/local/apache2//bin/httpd -k start
 daemon 8653 0.0 0.2 282928 2152 ? Sl 11:42 0:00 /usr/local/apache2//bin/httpd -k start
 root 8738 0.0 0.0 6056 760 pts/0 S+ 11:42 0:00 grep httpd

     9.4.2 通過瀏覽器輸入地址訪問:http://Apache伺服器IP地址,若顯示“It works”即表明Apache正常工作

     

 

    暫停一下...明天繼續...

 

 

項目導入

一鍵搭建的環境非常簡單!簡單到令人髮指啊!所以這時候請先感謝大牛給我們這些小白帶來的便利。

LNMP一鍵安裝包

有條件的話,大家也可以支持下,且行且珍惜~

正片開始

 

第一步:

添加虛擬主機

[root@centos_6_8 ~]# lnmp vhost add
+-------------------------------------------+
|    Manager for LNMP, Written by Licess    |
+-------------------------------------------+
|              https://lnmp.org             |
+-------------------------------------------+
Please enter domain(example: www.lnmp.org): www.tt.com                              
 Your domain: www.tt.com
Enter more domain name(example: lnmp.org *.lnmp.org): tt.com
 domain list: tt.com
Please enter the directory for the domain: www.tt.com
Default directory: /home/wwwroot/www.tt.com: 
Virtual Host Directory: /home/wwwroot/www.tt.com
Allow Rewrite rule? (y/n) n
You choose rewrite: none
Allow access log? (y/n) y
Enter access log filename(Default:www.tt.com.log): 
You access log filename: www.tt.com.log
Create database and MySQL user with same name (y/n) y
Enter current root password of Database (Password will not shown): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Enter current root password of Database (Password will not shown): 
OK, MySQL root password correct.
Enter database name: project
Your will create a database and MySQL user with same name: project
Please enter password for mysql user project: 000000
Your password: 000000 
Add SSL Certificate (y/n) n
​
Press any key to start create virtul host...
​
Create Virtul Host directory......
set permissions of Virtual Host directory......
You select the exist rewrite rule:/usr/local/nginx/conf/none.conf
Test Nginx configure file......
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
Reload Nginx......
Gracefully shutting down php-fpm  done
Starting php-fpm  done
Add database Sucessfully.
================================================
Virtualhost infomation:
Your domain: www.tt.com
Home Directory: /home/wwwroot/www.tt.com
Rewrite: none
Enable log: yes
Database username: project
Database userpassword: 000000
Database Name: project
Create ftp account: no
================================================

 

 

具體添加詳解,請參考

LNMP添加、刪除虛擬主機及偽靜態使用教程

 

第二步:

導入項目,切記Linux是嚴格區分大小寫的,如果網站文件中,大小寫不規範,有可能導致頁面不正常顯示或者不顯示,具體的稍後總結。

通過遠程工具,將項目直接放入到剛纔創建好的虛擬主機的網頁目錄下

例如:

我的網站存放目錄

/home/wwwroot/<功能變數名稱>/

目錄下文件,不要把整個文件夾放進來,不然還要配置vhost文件

 

 第三步:

 導入資料庫,導入資料庫之前請先將項目的資料庫轉為sql文件,本來不想在這多占篇幅寫如何導出的,但是為了以防萬一,還是寫出來吧

 導出資料庫

  1.打開wamp環境,使用Navicat Premium連上項目的資料庫

  

  2.選擇資料庫-->右擊轉存為SQL文件-->結構數據

  

  3.選擇存儲位置,然後執行

  

  4.將SQL導入linux下

  因為上面已經創建好了,資料庫所以直接進入資料庫中,然後導入數據即可

  [root@centos_6_8 project]# mysql -uroot -p000000
  

Welcome to the MySQL monitor. Commands end with ; or \g.
  Your MySQL connection id is 4
  Server version: 5.5.56-log Source distribution

  Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

  Oracle is a registered trademark of Oracle Corporation and/or its
  affiliates. Other names may be trademarks of their respective
  owners.

  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  mysql> use project;
  Database changed
  mysql> source /home/wwwroot/www.tt.com/project.sql;
  Query OK, 0 rows affected (0.00 sec)

  Query OK, 0 rows affected, 1 warning (0.00 sec)

  Query OK, 0 rows affected (0.03 sec)

  Query OK, 1 row affected (0.00 sec)

  mysql> Ctrl-C -- exit!
  Aborted

 

  數據導入完成後,直接ctrl+c退出即可,當然不放心最好再查看下數據文件是否真的導入

  

  5.修改php文件中資料庫連接的配置文件

  如:

    資料庫的名稱/密碼,具體配置文件請根據自己的環境來

   [root@centos_6_8 ~]# vi /home/wwwroot/www.tt.com/Conf/config.php 

<?php

// 資料庫參數
define('DSN', 'mysql:host=localhost;dbname=project;charset=utf8');
define('USER', 'root');
define('PWD', '000000');

// 開啟session
session_start();

// 時區
date_default_timezone_set('PRC');

// 編碼
header('content-type: text/html; charset=utf-8');

// 錯誤級別
error_reporting(0);

// 每頁顯示的行數
define('ROWS', 8);

// 後臺的css, js, images 地址
define('AC','/Admin/Style/css/');
define('AJ','/Admin/Style/js/');
define('AI','/Admin/Style/images/');

// 前臺的css, js, images 地址
define('HC','/Home/Style/css/');
define('HJ','/Home/Style/js/');
define('HI','/Home/Style/images/');

include 'function.php';

include 'check.php';

include 'CCPRestSDK.php';

include 'sign.php';

?>

到這裡linux的配置基本完成,因為是虛擬機所以,我們要在外部window下配置hosts文件

 

第四步:

配置windows下的hosts文件

文件位置:

    C:\Windows\System32\drivers\etc

       格式:

         IP 功能變數名稱

      IP為虛擬機IP

      功能變數名稱為虛擬主機功能變數名稱

 

 

​第五步:

    打開瀏覽器輸入功能變數名稱訪問

    

 

​【錯誤總結】

  1.配置完成,訪問後一片空白。

    排查:F12--->Network--->F5--->查看請求狀態

    如果請求正常,頁面未顯示或者部分不顯示有以下原因

    1.mvc中control下php文件中入口文件,查看下,是不是view文件目錄大小寫搞錯了

    2.頁面文件路徑錯誤,config配置文件樣式路徑

    

 

     請求不正常

    1.資料庫連接問題

   

 

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 雖然有kali linux這樣集合了很多安全工具的操作系統,但是kali的軟體源相對老舊,沒有ubuntu等主流debian系統豐富,kali預設使用su許可權進入圖形化界面也是違背linux許可權機制的體現之一,故使用主流debian系linux系統安裝安全工具集比kali更具可用性,但是許多安全工具 ...
  •     在awk中常用的內置函數大概分為:數值函數、字元函數、時間函數、二進位操作函數、數組函數、自定義函數等。 數值函數   常用的數值函數主要有int、rand、srand、sqrt等。詳細如下所示: | 函數 | 說明 | | | | | int(expr) | ...
  • 最近由於在學習STM32看到別人用寄存器編程式控制制跑馬燈,於是自己也想試一試。可是試了好久終究弄不出來。回頭看了下庫函數的調用關係才搞明白。首先通過查看GPIOA的設置函數發現設置如下: 改機構體根據結構體成員函數的大小自己形成了針對首地址的偏移量。從而與需要操作的寄存器地址偏移一一對應。通過查看設置 ...
  • 一、什麼是SSH? 簡單說,SSH是一種網路協議,用於電腦之間的加密登錄。 如果一個用戶從本地電腦,使用SSH協議登錄另一臺遠程電腦,我們就可以認為,這種登錄是安全的,即使被中途截獲,密碼也不會泄露。 最早的時候,互聯網通信都是明文通信,一旦被截獲,內容就暴露無疑。1995年,芬蘭學者Tatu ...
  • 一. 概述 linux安全系統的核心是用戶賬戶。 創建用戶時會分配用戶ID(UID)。 UID是唯一的,但在登錄系統時不是用UID,而是用登錄名。在講文件許可權之之前,先瞭解下linux是怎樣處理用戶賬戶的。以及用戶賬戶需要的文件和工具,這樣處理文件許可權問題時,就知道如何使用它們了。 1.1 /etc ...
  • 基於Keepalived+Varnish+Nginx實現的高可用LAMP架構 註意:各節點的時間需要同步(ntpdate ntp1.aliyun.com),關閉firewalld(systemctl stop firewalld.service,systemctl disable firewalld ...
  • 使用parted和resize2fs擴容GPT分區表格式 rootfs ...
  • 在做的項目在nginx下訪問緩衝時間過長,明顯比apache下訪問蠻11倍有餘, 解決辦法: 1增加nginx的upstream,其中upstream中為php-cgi的地址; 2利用nginx作為反向代理,分支法解決併發量; 3增加php-cgi的進程數,(這裡會受到機器資源的限制,因此,也並不能 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...