環境搭建
-
無人值守搭建
支持LAMP/LNMP/LNMPA的一鍵搭建,根據自己的需求配置好之后點擊生成就會生成腳本,然后只需簡單的復制粘貼,再去喝杯咖啡回來后即可享受已經生成好的環境。
當然前提是你要把虛擬機的網絡配置好吆~一定要能夠和外網連通哦(づ ̄ 3 ̄)づ
這個也挺好用的,用起來也是很絲滑,具體用哪個,看你的選擇了
-
手動搭建【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正常工作
9.4.3 設置Apache系統引導啟動
echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.local
10.安裝ncurses
yum -y install ncurses-devel
10.1 編譯安裝ncurses-5.9
[root@centos_6_8 ~]# cd lamp/ncurses-5.9 [root@centos_6_8 ncurses-5.9]# ./configure --with-shared --without-debug --without-ada --enable-overwrite [root@centos_6_8 ncurses-5.9]# make && make install
11.安裝cmake和bison
yum -y install cmake bison
12.安裝Mysql
[root@centos_6_8 ncurses-5.9]# groupadd mysql [root@centos_6_8 ncurses-5.9]# useradd -g mysql mysql [root@centos_6_8 ~]# cd lamp/mysql-5.5.48 [root@centos_6_8 mysql-5.5.48]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 && make && make install -DCMAKE_INSTALL_PREFIX=/usr/local/mysql 安裝位置 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock 指定socket(套接字)文件位置 -DEXTRA_CHARSETS=all 擴展字符支持 -DDEFAULT_CHARSET=utf8 默認字符集 -DDEFAULT_COLLATION=utf8_general_ci 默認字符校對 -DWITH_MYISAM_STORAGE_ENGINE=1 安裝myisam存儲引擎 -DWITH_INNOBASE_STORAGE_ENGINE=1 安裝innodb存儲引擎 -DWITH_MEMORY_STORAGE_ENGINE=1 安裝memory存儲引擎 -DWITH_READLINE=1 支持readline庫 -DENABLED_LOCAL_INFILE=1 啟用加載本地數據 -DMYSQL_USER=mysql 指定mysql運行用戶 -DMYSQL_TCP_PORT=3306 指定mysql端口
12.1 配置數據庫
[root@centos_6_8 mysql-5.5.48]# cd /usr/local/mysql/ [root@centos_6_8 mysql]# chown -R mysql . [root@centos_6_8 mysql]# chgrp -R mysql . [root@centos_6_8 mysql]# /usr/local/mysql/scripts/mysql_install_db --user=mysql [root@centos_6_8 mysql]# chown -R root . [root@centos_6_8 mysql]# chown -R mysql data [root@centos_6_8 mysql]# cp support-files/my-medium.cnf /etc/my.cnf cp:是否覆蓋"/etc/my.cnf"? yes [root@centos_6_8 mysql]# /usr/local/mysql/scripts/mysql_install_db --user=mysql
12.2 啟動服務並測試是否可正常使用
[root@centos_6_8 mysql]# /usr/local/mysql/bin/mysqld_safe --user=mysql & //這句跑完回車下,不會自己跳出來 [root@centos_6_8 mysql]# echo "/usr/local/mysql/bin/mysqld_safe --user=mysql &" >> /etc/rc.local [root@centos_6_8 mysql]# /usr/local/mysql/bin/mysqladmin -uroot password 000000 [root@centos_6_8 mysql]# /usr/local/mysql/bin/mysql -uroot -p000000 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.5.48-log Source distribution Copyright (c) 2000, 2016, 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> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | test | +--------------------+ 4 rows in set (0.05 sec) mysql> select now(); +---------------------+ | now() | +---------------------+ | 2018-08-21 12:22:21 | +---------------------+ 1 row in set (0.00 sec) mysql> Ctrl-C -- exit! Aborted [root@centos_6_8 mysql]#
13.安裝php
13.1 安裝libtool和libtool-ltdl軟件包
[root@centos_6_8 mysql]# yum -y install "libtool*"
13.2 編譯安裝php
[root@centos_6_8 ~]# cd lamp/php-7.0.7 [root@centos_6_8 php-7.0.7]# ./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg6/ --with-png-dir=/usr/local/libpng/ --with-freetype-dir=/usr/local/freetype/ --with-gd --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets --with-pdo-mysql=/usr/local/mysql --without-pear && make && make install --with-config-file-path=/usr/local/php/etc/ 指定配置文件目錄 --with-apxs2=/usr/local/apache2/bin/apxs 指定apache動態模塊位置 --with-mysql=/usr/local/mysql/ 指定mysql位置 --with-libxml-dir=/usr/local/libxml2/ 指定libxml位置 --with-jpeg-dir=/usr/local/jpeg6/ 指定jpeg位置 --with-png-dir=/usr/local/libpng/ 指定libpng位置 --with-freetype-dir=/usr/local/freetype/ 指定freetype位置 --with-mcrypt=/usr/local/libmcrypt/ 指定libmcrypt位置 --with-mysqli=/usr/local/mysql/bin/mysql_config 指定mysqli位置 --with-gd 啟用gd庫 --enable-soap 支持soap服務 --enable-mbstring=all 支持多字節,字符串 --enable-sockets 支持套接字 --with-pdo-mysql=/usr/local/mysql 啟用mysql的pdo模塊支持 --without-pear 不安裝pear(安裝pear需要連接互聯網。 PEAR是PHP擴展與應用庫)
13.3 php配置
[root@centos_6_8 ~]# mkdir -p /usr/local/php/etc [root@centos_6_8 ~]# cp -rvf lamp/php-7.0.7/php.ini-production /usr/local/php/etc/php.ini "lamp/php-7.0.7/php.ini-production" -> "/usr/local/php/etc/php.ini"
13.4測試Apache與php的連通性, 配置httpd.conf
[root@centos_6_8 php-7.0.7]# vi /usr/local/apache2/etc/httpd.conf AddType application/x-httpd-php .php .phtml AddType application/x-httpd-php-source .phps
13.5 重啟Apcahe服務
[root@centos_6_8 php-7.0.7]# /usr/local/apache2/bin/apachectl stop 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 php-7.0.7]# /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 php-7.0.7]#
13.5 查看php是否安裝成功
[root@centos_6_8 php-7.0.7]# vi /usr/local/apache2/htdocs/info.php <?php phpinfo(); ?>
13.6 添加環境變量
[root@centos_6_8 php-7.0.7]# echo 'export PATH="/usr/local/php/bin:$PATH"' >> /etc/profile [root@centos_6_8 php-7.0.7]# echo 'export PATH="/usr/local/mysql/bin:$PATH"' >> /etc/profile
14. 安裝phpMyAdmin
[root@centos_6_8 ~]# cp -rvf lamp/phpMyAdmin-4.1.4-all-languages /usr/local/apache2/htdocs/phpmyadmin [root@centos_6_8 ~]# cd /usr/local/apache2/htdocs/phpmyadmin [root@centos_6_8 phpmyadmin]# cp config.sample.inc.php config.inc.php [root@centos_6_8 phpmyadmin]# vi config.inc.php 將cookie $cfg['Servers'][$i]['auth_type'] = 'cookie'; 改為htp $cfg['Servers'][$i]['auth_type'] = 'http';
14.1 查看是否安裝成功
輸入虛擬機IP地址/phpmyadmin/----->點擊index.php------>輸入用戶和密碼----->看到頁面即成功
15.打開php報錯
[root@centos_6_8 ~]# vi /usr/local/php/etc/php.ini
display_errors = On
error_reporting = E_ALL & ~E_NOTICE
項目導入
LAMP導入
第一步:
通過遠程工具將項目放置網站根目錄下
第二步:
配置Apache,配置文件均為
1.配置域名
[root@centos_6_8 ~]# vi /usr/local/apache2/etc/httpd.conf ServerName www.tt.com:80 #190行
2.配置windos下hosts文件
3.重啟Apache服務,域名訪問可通
[root@centos_6_8 ~]# /usr/local/apache2/bin/apachectl restart
4.配置自動解析index.php文件
[root@centos_6_8 ~]# vi /usr/local/apache2/etc/httpd.conf
<IfModule dir_module> DirectoryIndex index.html index.php </IfModule>
5.在httpd.conf下打開466行的注釋,載入虛擬主機配置
466 Include etc//extra/httpd-vhosts.conf
6.配置虛擬主機
[root@centos_6_8 ~]# vi /usr/local/apache2/etc/extra/httpd-vhosts.conf
#httpd.conf 347-351行
#<Directory "/usr/local/apache2/htdocs/project/">改為自己項目所在的文件夾
<Directory "/usr/local/apache2/htdocs/project/">
AllowOverride All
Options None
Require all granted
</Directory>
<VirtualHost *:80>
#管理員郵箱
ServerAdmin 2752154874@qq.com
#項目目錄
DocumentRoot "/usr/local/apache2/htdocs/project/"
#域名
ServerName www.tt.com
#別名
ServerAlias tt.com
#日志
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
7.在httpd.conf中打開speling模塊
忽略url中的大小寫
LoadModule speling_module modules/mod_speling.so
#配置文件最后加入下面的命令
CheckSpelling On
8.數據庫
8.1 創建項目數據庫(需要與配置文件中的數據庫一致)
[root@centos_6_8 ~]# mysql -uroot -p000000 Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 41 Server version: 5.5.48-log Source distribution Copyright (c) 2000, 2016, 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> create database project; Query OK, 1 row affected (0.00 sec) mysql> use project; Database changed mysql> source /usr/local/apache2/htdocs/project/project.sql
Query OK, 0 rows affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 0 rows affected (0.02 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
mysql> Ctrl-C -- exit!
Aborted
[root@centos_6_8 ~]#
圈起來的需要注意!!!
9.重啟Apache服務,輸入域名訪問
[root@centos_6_8 ~]# /usr/local/apache2/bin/apachectl restart
10.配置文件
httpd.conf
[root@centos_6_8 ~]# cat /usr/local/apache2/etc/httpd.conf # # This is the main Apache HTTP server configuration file. It contains the # configuration directives that give the server its instructions. # See <URL:http://httpd.apache.org/docs/2.4/> for detailed information. # In particular, see # <URL:http://httpd.apache.org/docs/2.4/mod/directives.html> # for a discussion of each configuration directive. # # Do NOT simply read the instructions in here without understanding # what they do. They're here only as hints or reminders. If you are unsure # consult the online docs. You have been warned. # # Configuration and logfile names: If the filenames you specify for many # of the server's control files begin with "/" (or "drive:/" for Win32), the # server will use that explicit path. If the filenames do *not* begin # with "/", the value of ServerRoot is prepended -- so "logs/access_log" # with ServerRoot set to "/usr/local/apache2" will be interpreted by the # server as "/usr/local/apache2/logs/access_log", whereas "/logs/access_log" # will be interpreted as '/logs/access_log'. # # ServerRoot: The top of the directory tree under which the server's # configuration, error, and log files are kept. # # Do not add a slash at the end of the directory path. If you point # ServerRoot at a non-local disk, be sure to specify a local disk on the # Mutex directive, if file-based mutexes are used. If you wish to share the # same ServerRoot for multiple httpd daemons, you will need to change at # least PidFile. # ServerRoot "/usr/local/apache2/" # # Mutex: Allows you to set the mutex mechanism and mutex file directory # for individual mutexes, or change the global defaults # # Uncomment and change the directory if mutexes are file-based and the default # mutex file directory is not on a local disk or is not appropriate for some # other reason. # # Mutex default:logs # # Listen: Allows you to bind Apache to specific IP addresses and/or # ports, instead of the default. See also the <VirtualHost> # directive. # # Change this to Listen on specific IP addresses as shown below to # prevent Apache from glomming onto all bound IP addresses. # #Listen 12.34.56.78:80 Listen 80 # # Dynamic Shared Object (DSO) Support # # To be able to use the functionality of a module which was built as a DSO you # have to place corresponding `LoadModule' lines at this location so the # directives contained in it are actually available _before_ they are used. # Statically compiled modules (those listed by `httpd -l') do not need # to be loaded here. # # Example: # LoadModule foo_module modules/mod_foo.so # LoadModule authn_file_module modules/mod_authn_file.so #LoadModule authn_dbm_module modules/mod_authn_dbm.so #LoadModule authn_anon_module modules/mod_authn_anon.so #LoadModule authn_dbd_module modules/mod_authn_dbd.so #LoadModule authn_socache_module modules/mod_authn_socache.so LoadModule authn_core_module modules/mod_authn_core.so LoadModule authz_host_module modules/mod_authz_host.so LoadModule authz_groupfile_module modules/mod_authz_groupfile.so LoadModule authz_user_module modules/mod_authz_user.so #LoadModule authz_dbm_module modules/mod_authz_dbm.so #LoadModule authz_owner_module modules/mod_authz_owner.so #LoadModule authz_dbd_module modules/mod_authz_dbd.so LoadModule authz_core_module modules/mod_authz_core.so LoadModule access_compat_module modules/mod_access_compat.so LoadModule auth_basic_module modules/mod_auth_basic.so #LoadModule auth_form_module modules/mod_auth_form.so #LoadModule auth_digest_module modules/mod_auth_digest.so #LoadModule allowmethods_module modules/mod_allowmethods.so #LoadModule file_cache_module modules/mod_file_cache.so #LoadModule cache_module modules/mod_cache.so #LoadModule cache_disk_module modules/mod_cache_disk.so #LoadModule cache_socache_module modules/mod_cache_socache.so #LoadModule socache_shmcb_module modules/mod_socache_shmcb.so #LoadModule socache_dbm_module modules/mod_socache_dbm.so #LoadModule socache_memcache_module modules/mod_socache_memcache.so #LoadModule macro_module modules/mod_macro.so #LoadModule dbd_module modules/mod_dbd.so #LoadModule dumpio_module modules/mod_dumpio.so #LoadModule buffer_module modules/mod_buffer.so #LoadModule ratelimit_module modules/mod_ratelimit.so LoadModule reqtimeout_module modules/mod_reqtimeout.so #LoadModule ext_filter_module modules/mod_ext_filter.so #LoadModule request_module modules/mod_request.so #LoadModule include_module modules/mod_include.so LoadModule filter_module modules/mod_filter.so #LoadModule substitute_module modules/mod_substitute.so #LoadModule sed_module modules/mod_sed.so #LoadModule deflate_module modules/mod_deflate.so LoadModule mime_module modules/mod_mime.so LoadModule log_config_module modules/mod_log_config.so #LoadModule log_debug_module modules/mod_log_debug.so #LoadModule logio_module modules/mod_logio.so LoadModule env_module modules/mod_env.so #LoadModule expires_module modules/mod_expires.so LoadModule headers_module modules/mod_headers.so #LoadModule unique_id_module modules/mod_unique_id.so LoadModule setenvif_module modules/mod_setenvif.so LoadModule version_module modules/mod_version.so #LoadModule remoteip_module modules/mod_remoteip.so #LoadModule proxy_module modules/mod_proxy.so #LoadModule proxy_connect_module modules/mod_proxy_connect.so #LoadModule proxy_ftp_module modules/mod_proxy_ftp.so #LoadModule proxy_http_module modules/mod_proxy_http.so #LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so #LoadModule proxy_scgi_module modules/mod_proxy_scgi.so #LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so #LoadModule proxy_ajp_module modules/mod_proxy_ajp.so #LoadModule proxy_balancer_module modules/mod_proxy_balancer.so #LoadModule proxy_express_module modules/mod_proxy_express.so #LoadModule session_module modules/mod_session.so #LoadModule session_cookie_module modules/mod_session_cookie.so #LoadModule session_dbd_module modules/mod_session_dbd.so #LoadModule slotmem_shm_module modules/mod_slotmem_shm.so #LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so #LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so #LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so #LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so LoadModule unixd_module modules/mod_unixd.so #LoadModule dav_module modules/mod_dav.so LoadModule status_module modules/mod_status.so LoadModule autoindex_module modules/mod_autoindex.so #LoadModule info_module modules/mod_info.so #LoadModule cgid_module modules/mod_cgid.so #LoadModule dav_fs_module modules/mod_dav_fs.so #LoadModule vhost_alias_module modules/mod_vhost_alias.so #LoadModule negotiation_module modules/mod_negotiation.so LoadModule dir_module modules/mod_dir.so #LoadModule actions_module modules/mod_actions.so LoadModule speling_module modules/mod_speling.so #LoadModule userdir_module modules/mod_userdir.so LoadModule alias_module modules/mod_alias.so #LoadModule rewrite_module modules/mod_rewrite.so LoadModule php7_module modules/libphp7.so <IfModule unixd_module> # # If you wish httpd to run as a different user or group, you must run # httpd as root initially and it will switch. # # User/Group: The name (or #number) of the user/group to run httpd as. # It is usually good practice to create a dedicated user and group for # running httpd, as with most system services. # User daemon Group daemon </IfModule> # 'Main' server configuration # # The directives in this section set up the values used by the 'main' # server, which responds to any requests that aren't handled by a # <VirtualHost> definition. These values also provide defaults for # any <VirtualHost> containers you may define later in the file. # # All of these directives may appear inside <VirtualHost> containers, # in which case these default settings will be overridden for the # virtual host being defined. # # # ServerAdmin: Your address, where problems with the server should be # e-mailed. This address appears on some server-generated pages, such # as error documents. e.g. admin@your-domain.com # ServerAdmin you@example.com # # ServerName gives the name and port that the server uses to identify itself. # This can often be determined automatically, but we recommend you specify # it explicitly to prevent problems during startup. # # If your host doesn't have a registered DNS name, enter its IP address here. # ServerName www.tt.com:80 # # Deny access to the entirety of your server's filesystem. You must # explicitly permit access to web content directories in other # <Directory> blocks below. # <Directory /> AllowOverride none Require all denied </Directory> # # Note that from this point forward you must specifically allow # particular features to be enabled - so if something's not working as # you might expect, make sure that you have specifically enabled it # below. # # # DocumentRoot: The directory out of which you will serve your # documents. By default, all requests are taken from this directory, but # symbolic links and aliases may be used to point to other locations. # DocumentRoot "/usr/local/apache2//htdocs" <Directory "/usr/local/apache2//htdocs"> # # Possible values for the Options directive are "None", "All", # or any combination of: # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews # # Note that "MultiViews" must be named *explicitly* --- "Options All" # doesn't give it to you. # # The Options directive is both complicated and important. Please see # http://httpd.apache.org/docs/2.4/mod/core.html#options # for more information. # Options Indexes FollowSymLinks # # AllowOverride controls what directives may be placed in .htaccess files. # It can be "All", "None", or any combination of the keywords: # AllowOverride FileInfo AuthConfig Limit # AllowOverride None # # Controls who can get stuff from this server. # Require all granted </Directory> # # DirectoryIndex: sets the file that Apache will serve if a directory # is requested. # <IfModule dir_module> DirectoryIndex index.html index.php </IfModule> # # The following lines prevent .htaccess and .htpasswd files from being # viewed by Web clients. # <Files ".ht*"> Require all denied </Files> # # ErrorLog: The location of the error log file. # If you do not specify an ErrorLog directive within a <VirtualHost> # container, error messages relating to that virtual host will be # logged here. If you *do* define an error logfile for a <VirtualHost> # container, that host's errors will be logged there and not here. # ErrorLog "logs/error_log" # # LogLevel: Control the number of messages logged to the error_log. # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. # LogLevel warn <IfModule log_config_module> # # The following directives define some format nicknames for use with # a CustomLog directive (see below). # LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined LogFormat "%h %l %u %t \"%r\" %>s %b" common <IfModule logio_module> # You need to enable mod_logio.c to use %I and %O LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio </IfModule> # # The location and format of the access logfile (Common Logfile Format). # If you do not define any access logfiles within a <VirtualHost> # container, they will be logged here. Contrariwise, if you *do* # define per-<VirtualHost> access logfiles, transactions will be # logged therein and *not* in this file. # CustomLog "logs/access_log" common # # If you prefer a logfile with access, agent, and referer information # (Combined Logfile Format) you can use the following directive. # #CustomLog "logs/access_log" combined </IfModule> <IfModule alias_module> # # Redirect: Allows you to tell clients about documents that used to # exist in your server's namespace, but do not anymore. The client # will make a new request for the document at its new location. # Example: # Redirect permanent /foo http://www.example.com/bar # # Alias: Maps web paths into filesystem paths and is used to # access content that does not live under the DocumentRoot. # Example: # Alias /webpath /full/filesystem/path # # If you include a trailing / on /webpath then the server will # require it to be present in the URL. You will also likely # need to provide a <Directory> section to allow access to # the filesystem path. # # ScriptAlias: This controls which directories contain server scripts. # ScriptAliases are essentially the same as Aliases, except that # documents in the target directory are treated as applications and # run by the server when requested rather than as documents sent to the # client. The same rules about trailing "/" apply to ScriptAlias # directives as to Alias. # ScriptAlias /cgi-bin/ "/usr/local/apache2//cgi-bin/" </IfModule> <IfModule cgid_module> # # ScriptSock: On threaded servers, designate the path to the UNIX # socket used to communicate with the CGI daemon of mod_cgid. # #Scriptsock cgisock </IfModule> # # "/usr/local/apache2//cgi-bin" should be changed to whatever your ScriptAliased # CGI directory exists, if you have that configured. # <Directory "/usr/local/apache2//cgi-bin"> AllowOverride None Options None Require all granted </Directory> <IfModule mime_module> # # TypesConfig points to the file containing the list of mappings from # filename extension to MIME-type. # TypesConfig etc//mime.types # # AddType allows you to add to or override the MIME configuration # file specified in TypesConfig for specific file types. # #AddType application/x-gzip .tgz # # AddEncoding allows you to have certain browsers uncompress # information on the fly. Note: Not all browsers support this. # #AddEncoding x-compress .Z #AddEncoding x-gzip .gz .tgz # # If the AddEncoding directives above are commented-out, then you # probably should define those extensions to indicate media types: # AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddType application/x-httpd-php .php .phtml AddType application/x-httpd-php-source .phps # # AddHandler allows you to map certain file extensions to "handlers": # actions unrelated to filetype. These can be either built into the server # or added with the Action directive (see below) # # To use CGI scripts outside of ScriptAliased directories: # (You will also need to add "ExecCGI" to the "Options" directive.) # #AddHandler cgi-script .cgi # For type maps (negotiated resources): #AddHandler type-map var # # Filters allow you to process content before it is sent to the client. # # To parse .shtml files for server-side includes (SSI): # (You will also need to add "Includes" to the "Options" directive.) # #AddType text/html .shtml #AddOutputFilter INCLUDES .shtml </IfModule> # # The mod_mime_magic module allows the server to use various hints from the # contents of the file itself to determine its type. The MIMEMagicFile # directive tells the module where the hint definitions are located. # #MIMEMagicFile etc//magic # # Customizable error responses come in three flavors: # 1) plain text 2) local redirects 3) external redirects # # Some examples: #ErrorDocument 500 "The server made a boo boo." #ErrorDocument 404 /missing.html #ErrorDocument 404 "/cgi-bin/missing_handler.pl" #ErrorDocument 402 http://www.example.com/subscription_info.html # # # MaxRanges: Maximum number of Ranges in a request before # returning the entire resource, or one of the special # values 'default', 'none' or 'unlimited'. # Default setting is to accept 200 Ranges. #MaxRanges unlimited # # EnableMMAP and EnableSendfile: On systems that support it, # memory-mapping or the sendfile syscall may be used to deliver # files. This usually improves server performance, but must # be turned off when serving from networked-mounted # filesystems or if support for these functions is otherwise # broken on your system. # Defaults: EnableMMAP On, EnableSendfile Off # #EnableMMAP off #EnableSendfile on # Supplemental configuration # # The configuration files in the etc//extra/ directory can be # included to add extra features or to modify the default configuration of # the server, or you may simply copy their contents here and change as # necessary. # Server-pool management (MPM specific) #Include etc//extra/httpd-mpm.conf # Multi-language error messages #Include etc//extra/httpd-multilang-errordoc.conf # Fancy directory listings #Include etc//extra/httpd-autoindex.conf # Language settings #Include etc//extra/httpd-languages.conf # User home directories #Include etc//extra/httpd-userdir.conf # Real-time info on requests and configuration #Include etc//extra/httpd-info.conf # Virtual hosts Include etc//extra/httpd-vhosts.conf # Local access to the Apache HTTP Server Manual #Include etc//extra/httpd-manual.conf # Distributed authoring and versioning (WebDAV) #Include etc//extra/httpd-dav.conf # Various default settings #Include etc//extra/httpd-default.conf # Configure mod_proxy_html to understand HTML4/XHTML1 <IfModule proxy_html_module> Include etc//extra/proxy-html.conf </IfModule> # Secure (SSL/TLS) connections #Include etc//extra/httpd-ssl.conf # # Note: The following must must be present to support # starting without SSL on platforms with no /dev/random equivalent # but a statically compiled-in mod_ssl. # <IfModule ssl_module> SSLRandomSeed startup builtin SSLRandomSeed connect builtin </IfModule> # # uncomment out the below to deal with user agents that deliberately # violate open standards by misusing DNT (DNT *must* be a specific # end-user choice) # #<IfModule setenvif_module> #BrowserMatch "MSIE 10.0;" bad_DNT #</IfModule> #<IfModule headers_module> #RequestHeader unset DNT env=bad_DNT #</IfModule> CheckSpelling On
httpd-vhost.conf
[root@centos_6_8 ~]# cat /usr/local/apache2/etc/extra/httpd-vhosts.conf # Virtual Hosts # # Required modules: mod_log_config # If you want to maintain multiple domains/hostnames on your # machine you can setup VirtualHost containers for them. Most configurations # use only name-based virtual hosts so the server doesn't need to worry about # IP addresses. This is indicated by the asterisks in the directives below. # # Please see the documentation at # <URL:http://httpd.apache.org/docs/2.4/vhosts/> # for further details before you try to setup virtual hosts. # # You may use the command line option '-S' to verify your virtual host # configuration. # # VirtualHost example: # Almost any Apache directive may go into a VirtualHost container. # The first VirtualHost section is used for all requests that do not # match a ServerName or ServerAlias in any <VirtualHost> block. # <Directory "/usr/local/apache2/htdocs/project/"> AllowOverride All Options None Require all granted </Directory> <VirtualHost *:80> ServerAdmin 2752154874@qq.com DocumentRoot "/usr/local/apache2/htdocs/project/" ServerName www.tt.com ServerAlias tt.com ErrorLog "logs/dummy-host.example.com-error_log" CustomLog "logs/dummy-host.example.com-access_log" common </VirtualHost>
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 ================================================
具體添加詳解,請參考
第二步:
導入項目,切記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配置文件樣式路徑
請求不正常
500錯誤
1.數據庫連接問題
403錯誤
1.httpd.conf中的index.php未設置解析