LAMP/LNMP环境下部署网站/导入PHP项目【VMware环境】

2024-08-16 09:34:10 浏览数 (4)

前言

很久之前写的文章了,当时还不是用markdown写的,这里更改为markdown

内容

环境搭建

无人值守搭建

?> 网络配置成功的话,以下两种都可以,不过更推荐oneinstack

LNMP一键安装包无人值守命令生成器 | oneinstack

手动搭建【LAMP】

!> 手动搭建适合深入学习,如果一般使用推荐直接使用脚本搭建;

快照环境:

方便直接回滚到初始环境

代码语言:javascript复制
IP配置完成
防火墙已关闭/selinux已关闭
LAMP包已经导入
镜像已导入

配置本地yum源

1.挂载镜像

直接挂载镜像文件,前提镜像文件已经导入,本人比较喜欢,有安全感,挂载后不要忘记查看下~

代码语言:javascript复制
# 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

挂载光驱/dev/cdrom,总感觉这样挂载会少点什么所以我一般不用这个挂载

代码语言:javascript复制
# mount -o loop /dev/cdrom /mnt/

上面挂载都只是临时的,一旦重启将会消失;

2.在/opt下创建文件夹centos

代码语言:javascript复制
# mkdir /opt/centos

3.将/mnt下的文件复制到/opt/centos下

代码语言:javascript复制
# cp -rvf /mnt/* /opt/centos

4.将原有yum源移到备份文件夹中

代码语言:javascript复制
# mv /etc/yum.repos.d/* /yumback

5.制作本地yum源

[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协议即可

代码语言:javascript复制
# vi /etc/yum.repos.d/centos.repo

6.清除缓存并重新显示所有软件包

代码语言:javascript复制
# yum clean all
# yum list

!>遇到报错可能有以下原因 1.防火墙未关闭 2.yum配置错误 3.具体请看报错信息,yum的总结的文件在另一个笔记本上,但是一般都是这两个问题~

解压源码包/安装gcc和gcc-c

开两个远程窗口,一个解压一个安装

代码语言:javascript复制
# yum install -y gcc gcc-c   

编写解压脚本

代码语言:javascript复制
# vi tar.sh

#!/bin/bash
ls lamp/ > list
for TAR in `cat list`
do
  tar -zxvf lamp/$TAR -C lamp/
 done
 rm list

使用脚本

代码语言:javascript复制
# chmod 777 tar.sh 
# sh tar.sh 

第三步:安装软件包

1.安装libxml2

安装libxml2-devel python-devel

代码语言:javascript复制
yum  install  -y  libxml2-devel   python-devel

进入到lamp/libxml2-2.9.1目录下执行检查和编译安装

代码语言:javascript复制
[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目录下执行检查和编译安装

代码语言:javascript复制
[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/目录下执行检查和编译安装

代码语言:javascript复制
[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

代码语言:javascript复制
[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

代码语言:javascript复制
[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

代码语言:javascript复制
[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

代码语言:javascript复制
[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 手动创建目录

代码语言:javascript复制
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的目录进行编译安装

代码语言:javascript复制
[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

代码语言:javascript复制
[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的目录下

代码语言:javascript复制
#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目录进行编译安装

代码语言:javascript复制
[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目录进行编译安装

代码语言:javascript复制
[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 查看服务进程是否运行

代码语言:javascript复制
[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正常工作

imgimg

9.4.3 设置Apache系统引导启动

代码语言:javascript复制
echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.local

10.安装ncurses  

代码语言:javascript复制
yum -y install ncurses-devel

10.1 编译安装ncurses-5.9

代码语言:javascript复制
[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

代码语言:javascript复制
yum -y install cmake bison

12.安装Mysql

代码语言:javascript复制
[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 配置数据库

代码语言:javascript复制
[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 启动服务并测试是否可正常使用

代码语言:javascript复制
[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软件包

代码语言:javascript复制
[root@centos_6_8 mysql]# yum -y install "libtool*"

13.2 编译安装php

代码语言:javascript复制
[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配置

代码语言:javascript复制
[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

代码语言:javascript复制
[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服务

代码语言:javascript复制
[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.6 查看php是否安装成功

代码语言:javascript复制
[root@centos_6_8 php-7.0.7]# vi /usr/local/apache2/htdocs/info.php
<?php

phpinfo();

?>
imgimg

13.7 添加环境变量

代码语言:javascript复制
[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 
  1. 安装phpMyAdmin
代码语言:javascript复制
[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------>输入用户和密码----->看到页面即成功

imgimg
imgimg

15.打开php报错

代码语言:javascript复制
[root@centos_6_8 ~]# vi /usr/local/php/etc/php.ini 
   display_errors = On
   error_reporting = E_ALL & ~E_NOTICE
imgimg

项目导入

![img](file:///D:/phpStudy/PHPTutorial/WWW/PhpLearn/Xmind/project/money.png?lastModify=1537326120)

LAMP导入
  1. 通过远程工具将项目放置网站根目录下
imgimg
imgimg
  1. 配置Apache

1).配置域名

代码语言:javascript复制
[root@centos_6_8 ~]# vi /usr/local/apache2/etc/httpd.conf
ServerName www.tt.com:80  #190行

2).配置windos下hosts文件

imgimg

3).重启Apache服务,域名访问可通

代码语言:javascript复制
[root@centos_6_8 ~]# /usr/local/apache2/bin/apachectl  restart
imgimg

4).配置自动解析index.php文件

代码语言:javascript复制
[root@centos_6_8 ~]# vi /usr/local/apache2/etc/httpd.conf
    <IfModule dir_module>
         DirectoryIndex index.html index.php
     </IfModule>

5).在httpd.conf下打开466行的注释,载入虚拟主机配置

代码语言:javascript复制
466 Include etc//extra/httpd-vhosts.conf

6).配置虚拟主机

代码语言:javascript复制
[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中的大小写

代码语言:javascript复制
LoadModule speling_module modules/mod_speling.so

#配置文件最后加入下面的命令
CheckSpelling On

8).数据库

 8.1 创建项目数据库(需要与配置文件中的数据库一致)

代码语言:javascript复制
[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
imgimg

9).重启Apache服务,输入域名访问

代码语言:javascript复制
[root@centos_6_8 ~]# /usr/local/apache2/bin/apachectl restart
imgimg

10).配置文件 httpd.conf

代码语言:javascript复制
[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

代码语言:javascript复制
[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导入
  1. 添加虚拟主机
代码语言:javascript复制
[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
================================================

![img](file:///D:/phpStudy/PHPTutorial/WWW/PhpLearn/Xmind/project/lnmpinclude.png?lastModify=1537326120)

具体添加详解,请参考LNMP添加、删除虚拟主机及伪静态使用教程

  1. 导入项目
代码语言:javascript复制
导入项目,切记Linux是严格区分大小写的,如果网站文件中,大小写不规范,有可能导致页面不正常显示或者不显示,具体的稍后总结。

 通过远程工具,将项目直接放入到刚才创建好的虚拟主机的网页目录下

 例如:

 我的网站存放目录

 /home/wwwroot/<域名>/

 目录下文件,不要把整个文件夹放进来,不然还要配置vhost文件
imgimg
  1. 导入数据库

导入数据库之前请先将项目的数据库转为sql文件,本来不想在这多占篇幅写如何导出的,但是为了以防万一,还是写出来吧

导出数据库

1).打开wamp环境,使用Navicat Premium连上项目的数据库

imgimg

2).选择数据库-->右击转存为SQL文件-->结构数据

imgimg

3).选择存储位置,然后执行

imgimg

4).将SQL导入linux下

因为上面已经创建好了,数据库所以直接进入数据库中,然后导入数据即可

代码语言:javascript复制
[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退出即可,当然不放心最好再查看下数据文件是否真的导入

imgimg

5).修改php文件中数据库连接的配置文件

如:数据库的名称/密码,具体配置文件请根据自己的环境来

代码语言:javascript复制
[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文件

4.配置windows下的hosts文件

代码语言:javascript复制
文件位置:
C:WindowsSystem32driversetc

格式:

IP 域名

<虚拟机IP> <虚拟主机域名>
imgimg
  1. 打开浏览器输入域名访问
imgimg

错误总结

1.配置完成,访问后一片空白。 排查:F12--->Network--->F5--->查看请求状态

如果请求正常,页面未显示或者部分不显示有以下原因 1).mvc中control下php文件中入口文件,查看下,是不是view文件目录大小写搞错了 2).页面文件路径错误,config配置文件样式路径

imgimg
  1. 403错误

1).httpd.conf中的index.php未设置解析

1 人点赞