LAMP搭建与配置

  • Post author:
  • Post category:其他



目录


1.安装MySQL


2.安装Apache


3. 安装PHP


4.httpd解析PHP


二.任务2 Apache配置


1. 默认虚拟主机


2.用户认证


3.域名跳转


4.访问日志


5访问日记不记录静态文件


6.访问日记切割


7.静态元素过期时间


8.配置防盗链


9.访问控制-Diretory\FileMatch


10.访问控制-禁止解析PHP


11.访问控制-user_agent


三.任务3 PHP配置


四.任务4 PHP 扩展模块安装


1.安装MySQL

把软件包移动到/usr/local/src/下

    1. 初始化

 #tar -xzvf mysql-5.6.45-linux-glibc2.12-x86_64.tar.gz   //解压

 #[ -d /usr/local/mysql ] && mv /usr/local/mysql mysql/usr/local/mysql_old

 #mv mysql-5.6.45-linux-glibc2.12-x86_64 /usr/local/mysql

 #useradd -s /sbin/nologin mysql   //建立MySQL用户,启动时需要该用户

 #cd usr/local/mysql

 #mkdir -p /data/mysql             //创建datadir,数据库文件会放到这里面
     
 #chown -R mysql:mysql /data/mysql  //更改权限

 # ./scripts/mtsql_install_db   --user=mysql    --datadir=/data/mysql

出现问题

解决

# yum -y per-Module-Install
    1. 配置MySQL
#cp support-files/my-default.cnf /etc/my.cnf


2.安装


Apache



2.1下载httpd-2.4.39.tar、apr-1.6.5.tar和apr-util-1.6.1.tar。

2.2 解压

  #tar -zxvf httpd-2.4.39.tar

  #tar -zxvf apr-1.6.5.tar

  #tar -zxvf apr-util-1.6.1.tar

(3)安装和配置

# cd /usr/local/src/apr-1.5.2

# yum install -y expat-devel

# yum install -y libtool*

# ./configure --prefix=/usr/local/apr  

# make &&make install    //安装Make

# cd /usr/local/src/apr-util-1.5.4

# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

# make &&make install

# cd httpd-2.4.49

# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most

# make &&make install

# cd ..

# cp -r apr-1.5.2 httpd-2.4.49/srclib/apr

# cp -r apr-util-1.5.4 httpd-2.4.49/srclib/apr-util

# make &&make install

# /usr/local/apache2.4/bin/apachectl -M

(4)安装成功


3. 安装PHP

3.1下载 php-5.6.30.tar

3.2解压

   #cd /usr/local/src

   #tar -zxvf php-5.6.30.tar.gz

3.3安装和配置

   #yum install -y libxml2-devel

   #yum installl -y openssl openssl -devel

   #yum install -y bzip2 bzip2-devel

   #yum install -y libpng libpng-devel

   #yum install -y freetype freetype-devel

   #yum install -y epel-release

   #yum install -y libmcrypt-devel

   #cd php-5.6.30

   #./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir--with-gd --with-jpeg-dir --with-png-dir--with-freetype-dir --with-iconv-dir--with-zlib-dir --with-bz2 --with-openssl--with-mcrypt --enable-soap--enable-gd-native-ttf  --enable-mbstring--enable-sockets --enable-exif

   #make  -j4 && make install

   #vi  ../conf/httpd.conf

安装成功


4.


httpd解析PHP

4.1配置

#vim /usr/local/apache2.4/conf/httpd.conf  //编辑httpd的主配置文件

搜索ServerName,把ServerName www.example.com:80前#去掉;

<Directory />

AllowOverride none

Require all denied

</Directory>

改为:

<Directory />

AllowOverride none

Require all granted

</Directory>

搜索AddType application/x-gzip .gz .tgz,在下面添加一行 AddType application/x-httpd-php .php;

<IfModule dir_module>

DirectoryIndex index.html

</IfModule>

改成:

<IfModule dir_module>

DirectoryIndex index.html index.php

</IfModule>

4.2测试安装

  1. 测试配置文件是否正确

   #/usr/local/apache2.4/bin/apachectl -t    //检验配置文件是否正确:Syntax OK

   #/usr/local/apache2.4/bin/apachectl start  //启动httpd命令

   #netstat -lnp |grep httpd  //查看是否启动

   #curl localhost     

   <html><body><h1>It works!<h1><body><html>   //使用curl命令简单测试,,显示了就是成功
  1. 检测是否正确解析PHP

#vi /usr/localapache2.4/htdocs/1.php

              <?php

             echo  “php解析正确”

              ?>  //编写一个测试脚本

         #curl localhost/1.php

php解析正确   //PHP解析正确

4.3 安装成功

出现错误

解决

#yum install net-tools




二.任务2 Apache配置




1.


默认虚拟主机

​
# cd /usr/local/apache2.4/conf/

# vim httpd.conf       //修改主配置文件

搜索vhosts,把Include conf/extra/httpd-vhosts.conf前#去掉

# cd /usr/local/apache2.4/conf/extra/

# cp httpd-vhosts.conf httpd-vhosts.conf-bak     //备份配置文件

# vim httpd-vhosts.conf      //修改配置内容如下:

        <VirtualHost *:80>

       ServerAdmin webmaster@dummy-host.example.com      //指定管理员邮箱

       DocumentRoot "/usr/local/apache2.4/docs/gaoshuang.com"   //虚拟主机站点的根目录

      ServerName gaoshuang.com             

      ServerAlias www.gaoshuang.com www.111.com          

      ErrorLog "logs/gaoshuang.com-error_log"            

      CustomLog "logs/gaoshuang.com-access_log" common    

</VirtualHost>

            

      <VirtualHost *:80>

      ErrorLog "logs/111.com-error_log"            

      CustomLog "logs/111.com-access_log" common    

</VirtualHost>

 # cd /usr/local/apache2.4/

# mkdir docs

# cd docs/

# mkdir gaoshuang.com

# mkdir 111.com         //创建网络文件

# vim gaoshuang.com/index.html

  gaoshuang.com

# vim 111.com/index.html

111.com

          # cd /usr/local/apache2.4/conf/

# cd extra/

# /usr/local/apache2.4/bin/apachectl -t   //测试配置文件

Syntax OK

# /usr/local/apache2.4/bin/apachectl graceful  //重新加载服务

​


2.


用户认证

#vim /usr/local/apache2.4/conf/extra/httpd-vhost.conf

    <Directory /usr/local/apache2.4/docs/gaoshuang.com> //指定认证目录

        AllowOverride AuthConfig                       //打开认证开关

        AuthName "gaoshuang.com user auth"             //自定义认证的名字

        AuthType Basic                                //认证的类型,一般为Basic

        AuthUserFile /usr/local/apache2.4/docs/.htpasswd  //指定密码文件所

在位置

        require valid-user                           //指定需要认证的用户为全部可用用户

      </Directory>

      # cd /usr/local/apache2.4/docs/gaoshuang.com/

# /usr/local/apache2.4/bin/apachectl -t       //测试配置文件

Syntax OK

# /usr/local/apache2.4/bin/apachectl graceful //重新加载服务

# /usr/local/apache2.4/bin/htpasswd -cm /usr/local/apache2.4/docs/.htpasswd gaoshuang      //创建用户

# curl -xlocalhost:80 gaoshuang.com -I

# curl -xlocalhost:80 -u gaoshuang:000000 gaoshuang.com -I //测试连接

  

配置验证:在C:\Windows\System32\drivers\etc\hosts 最后一行中输入192.168.49.133 gaoshaung.com www.gaoshuang.com 111.com 然后在浏览器中访问


3.域名跳转

把123.com域名跳转为www.123.com,配置如下:

 # cd /usr/local/apache2.4/conf/extra/

 # vim httpd-vhosts.conf  //修改配置文件增加内容如下:

  <IfModule mod_rewrite.c> //需要mod_rewrite模块支持

  RewriteEngine on  //打开rewrite功能

RewriteCond %{HTTP_HOST} !^www.123.com$  //定义rewrite的条件,主机名   (>域名)不是www.123.com满足条件

RewriteRule ^/(.*)$ http://www.123.com/$1 [R=301,L] //定义rewrite规则,当满足上面的条件时,这条规则才会执行

​
</IfModule>

 # /usr/local/apache2.4/bin/apachectl -t  //测试配置文件

# mkdir www.111.com 

# cd www.111.com/

  # vim index.html

   www.111.com

# vim 123.php

 <?php

echo "www.111.com/123.php";

?>

​

要实现跳转,需要rewrite模块的支持,所以查看是否安装该模块。如果没有则还需要一些配置:

# /usr/local/apache2.4/bin/apachectl -M | grep -i rewrite

            

# vim /usr/local/apache2.4/conf/httpd.conf

LoadModule rewrite_module modules/mod_rewrite.so前面#去掉

# /usr/local/apache2.4/bin/apachectl graceful   //重新加载服务

查看是否安装  /usr/local/apache2.4/bin/apachectl -M | grep -i rewrite

# curl -xlocalhost:80 2111.com.cn -I  //验证是否跳转


4.访问日志

# vim httpd-vhosts.conf   //编辑配置文件如下:

CustomLog "logs/gaoshuang.com-access_log" common改为CustomLog "logs/gaoshuang.com-access_log" combined

保存配置文件后,测试语法并重新加载配置:

# /usr/local/apache2.4/bin/apachectl -t

Syntax OK

# /usr/local/apache2.4/bin/apachectl graceful

配置验证

   # cd /usr/local/apache2.4/logs/

# cat gaoshuang.com-access_log

验证成功:


5


访问日记不记录静态文件

 # vim httpd-vhosts.conf    //修改配置文件如下:

     增加内容

SetEnvIf Request_URI ".*\.gif$" img

    SetEnvIf Request_URI ".*\.jpg$" img

    SetEnvIf Request_URI ".*\.png$" img

    SetEnvIf Request_URI ".*\.bmp$" img

    SetEnvIf Request_URI ".*\.swf$" img

    SetEnvIf Request_URI ".*\.js$" img

    SetEnvIf Request_URI ".*\.css$" img

    CustomLog "logs/123.com-access_log" combined env=!img

在CustomLog "logs/gaoshuang.com-access_log" combined前加#

保存配置后,测试配置文件是否正确,没有错误重新加载服务:

# /usr/local/apache2.4/bin/apachectl -t

Syntax OK

# /usr/local/apache2.4/bin/apachectl graceful


6.


访问日记切割

​
  # vim httpd-vhosts.conf  

CustomLog "logs/123.com-access_log" combined env=!img改为CustomLog "|/usr/local/apache2.4/bin/rotatelogs -l logs/www.111.com-access_%Y%m%d.log 86400" combined env=!im   

         # tar -zxvf php-5.6.30.tar.gz

       # yum install -y libxml2-devel

       # yum install -y openssl-devel

       # yum install -y bzip2 bzip2-devel

       # yum install -y libpng libpng-devel

       # yum install -y freetype freetype-devel

       # yum install -y epel-release

       # yum install -y libmcrypt-devel    //提前安装库文件防止配置时出错

 # ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-libxml-dir--with-gd --with-jpeg-dir --with-png-dir--with-freetype-dir --with-iconv-dir--with-zlib-dir --with-bz2 --with-openssl--with-mcrypt --enable-soap--enable-gd-native-ttf  --enable-mbstring--enable-sockets --enable-exif

# make && make install

# cd /usr/local/src/php-5.6.30

# cp php.ini-production  /usr/local/php/etc/php.ini            //复制配置文件

# cd /usr/local/apache2.4/

# vim conf/httpd.conf     //编辑httpd配置文件

(1)搜索ServerName,把ServerName www.example.com:80前#去掉;

(2)搜索Require,把Require all denied改为Require all granted   //允许所有请求访问

(3)搜索AddType application/x-gzip .gz .tgz,在下面添加AddType application/x-httpd-php .php

(4) 搜索Index,把DirectoryIndex index.html 改为DirectoryIndex index.html index.php

       # /usr/local/apache2.4/bin/apachectl -t   检验配置文件是否正确

       # /usr/local/apache2.4/bin/apachectl start    启动httpd

       # netstat -lnp |grep httpd       //查看是否启动

       # curl localhost          //使用curl命令简单测

  # vim conf/httpd.conf  //编写一个测试脚本,内容如下:

 <?php

echo  “php解析正确”

?>

  # curl localhost/1.php

    “php解析正确”    //显示此信息则PHP解析正确

  # cd /usr/local/apache2.4/conf/

  # vim httpd.conf       //修改主配置文件

     搜索vhosts,把Include conf/extra/httpd-vhosts.conf前#去掉

  # cd /usr/local/apache2.4/conf/extra/

  # cp httpd-vhosts.conf httpd-vhosts.conf-bak     //备份配置文件

# vim httpd-vhosts.conf      //修改配置内容如下:

       <VirtualHost *:80>

    ServerAdmin webmaster@dummy-host.example.com      //指定管理员邮箱

    DocumentRoot "/usr/local/apache2.4/docs/abc.com"         //虚拟主机站点的根目录

    ServerName abc.com             //自定义网站域名

    ServerAlias www.abc.com www.aaa.com     //网站的第二域名     

    ErrorLog "logs/abc.com-error_log"            //站点的错误日志

    CustomLog "logs/abc.com-access_log" common    //站点的访问日志

</VirtualHost>

  # cd /usr/local/apache2.4/

# mkdir docs

# cd docs/

# mkdir gaoshuang.com

# mkdir 111.com         //创建网络文件

# vim gaoshaung.com/index.html

   gaoshuang.com

# vim 111.com/index.html

111.com

        # cd /usr/local/apache2.4/conf/

# cd extra/

# /usr/local/apache2.4/bin/apachectl -t   //测试配置文件

Syntax OK

# /usr/local/apache2.4/bin/apachectl graceful  //重新加载服务

    # cd /usr/local/apache2.4/docs/

# curl -xlocalhost:80 www.gaoshuang.com   

# curl -xlocalhost:80 www.lll.com

      # curl -xlocalhost:80 111.com         //测试链接

     # cd /usr/local/apache2.4/conf/extra/

 # cd /usr/local/apache2.4/conf/extra/

# vim httpd-vhosts.conf  //修改配置文件增加内容如下:

           <Directory /usr/local/apache2.4/docs/gaoshuang.com> //指定认证目录

              AllowOverride AuthConfig     //打开认证开关

  AuthName "gaoshuang.com user auth" //自定义认证的名字

              AuthType Basic       //认证的类型,一般为Basic

              AuthUserFile /usr/local/apache2.4/docs/.htpasswd  //指定密码文件所在位置

              require valid-user    //指定需要认证的用户为全部可用用户

           </Directory>

        # cd /usr/local/apache2.4/docs/gaoshuang.com/

# /usr/local/apache2.4/bin/apachectl -t   //测试配置文件

Syntax OK

# /usr/local/apache2.4/bin/apachectl graceful    //重新加载服务

# /usr/local/apache2.4/bin/thpasswd -cm /usr/local/apache2.4/docs/.htpasswd gaoshuang    //创建用户

# curl -xlocalhost:80 gaoshuang.com -I

# curl -xlocalhost:80 -u gaoshuang:000000 gaoshuang.com -I //测试连接

# cd /usr/local/apache2.4/conf/extra/

# vim httpd-vhosts.conf  //修改配置文件增加内容如下:

      <IfModule mod_rewrite.c> //需要mod_rewrite模块支持

        RewriteEngine on  //打开rewrite功能

        RewriteCond %{HTTP_HOST} !^www.123.com$  //定义rewrite的条件,主机名(>域名)不是www.123.com满足条件

        RewriteRule ^/(.*)$ http://www.123.com/$1 [R=301,L] //定义rewrite规则,当满足上面的条件时,这条规则才会执行

</IfModule>

 # /usr/local/apache2.4/bin/apachectl -t  //测试配置文件

  # mkdir www.111.com 

# cd www.111.com/

  # vim index.html

        www.111.com

# vim 123.php

 <?php

echo "www.111.com/123.php";

?>

要实现跳转,需要rewrite模块的支持,所以查看是否安装该模块。如果没有则还需要一些配置:

# /usr/local/apache2.4/bin/apachectl -M | grep -i rewrite

             //无返回值需修改

# vim /usr/local/apache2.4/conf/httpd.conf

 //搜索rewrite,把LoadModule rewrite_module modules/mod_rewrite.so前面#去掉

# /usr/local/apache2.4/bin/apachectl graceful   //重新加载服务

# /usr/local/apache2.4/bin/apachectl -M | grep -i rewrite //查看是否安装

    # curl -xlocalhost:80 2111.com.cn -I  //验证是否跳转

   # vim httpd-vhosts.conf   //编辑配置文件如下:

CustomLog "logs/gaoshuang.com-access_log" common改为CustomLog "logs/gaoshuang.com-access_log" combined

保存配置文件后,测试语法并重新加载配置:

# /usr/local/apache2.4/bin/apachectl -t

Syntax OK

# /usr/local/apache2.4/bin/apachectl graceful

 # vim httpd-vhosts.conf    //修改配置文件如下:

     增加内容:

 SetEnvIf Request_URI ".*\.gif$" img

    SetEnvIf Request_URI ".*\.jpg$" img

    SetEnvIf Request_URI ".*\.png$" img

    SetEnvIf Request_URI ".*\.bmp$" img

    SetEnvIf Request_URI ".*\.swf$" img

  SetEnvIf Request_URI ".*\.js$" img

    SetEnvIf Request_URI ".*\.css$" img

    CustomLog "logs/123.com-access_log" combined env=!img

在CustomLog "logs/gaoshuang.com-access_log" combined前加#

    

保存配置后,测试配置文件是否正确,没有错误重新加载服务:

# /usr/local/apache2.4/bin/apachectl -t

Syntax OK

# /usr/local/apache2.4/bin/apachectl graceful

# curl -xlocalhost:80 www.111.com/images/linux.png -I   访问图片

# tailf gaoshuang.com-access_log      //查看日志

  CustomLog "logs/123.com-access_log" combined env=!img

 改为CustomLog "|/usr/local/apache2.4/bin/rotatelogs -l logs/www.111.com-access_%Y%m%d.log 86400" combined env=!img

   

存配置后,测试配置文件是否正确,没有错误重新加载服务:

# /usr/local/apache2.4/bin/apachectl -t

Syntax OK

# /usr/local/apache2.4/bin/apachectl graceful

        

        配置验证



 # curl -xlocalhost:80 www.111.com -I

 # ll /usr/local/apache2.4/logs/

#cat/usr/local/apache2.4/logs/www.111.com-access_20210930.log

验证成功

​


7.


静态元素过期时间

在httpd上我们可以控制文件过期时间,配置如下:

         # vim httpd-vhosts.conf  //修改配置文件如下:

        增加内容:

       <IfModule mod_expires.c>

       ExpiresActive on  //打开该功能的开关

       ExpiresByType image/gif  "access plus 1 days"

       ExpiresByType image/jpeg "access plus 24 hours"

       ExpiresByType image/png "access plus 24 hours"

       ExpiresByType text/css "now plus 2 hour"

       ExpiresByType application/x-javascript "now plus 2 hours"

       ExpiresByType application/javascript "now plus 2 hours"

       ExpiresByType application/x-shockwave-flash "now plus 2 hours"

       ExpiresDefault "now plus 0 min"

</IfModule>

CustomLog "logs/gaoshuang.com-access_log" combined前#删掉



保存配置后,测试配置文件是否正确,没有错误重新加载服务:

 # /usr/local/apache2.4/bin/apachectl -t

Syntax OK

# /usr/local/apache2.4/bin/apachectl graceful



(3)配置验证

检查httpd是否加载expires模块:

 # /usr/local/apache2.4/bin/apachectl -M |grep -i expires    //没有输出则说明当前httpd并不支持expires模块,所以需要修改配置文件

# vim /usr/local/apache2.4/conf/httpd.conf              //修改配置文件:

搜索expires,把LoadModule expires_module modules/mod_expires.so前面#删掉

# /usr/local/apache2.4/bin/apachectl -M|grep -i expires

 expires_module (shared)             //正确加载expires模块



进行测试:

# curl -xlocalhost:80 www.111.com/images/linux.png -I


8.


配置防盗链

8.1介绍

防盗链,通俗讲,就是不让别人盗用你网站上的资源。这个资源,通常指的是图片、视频、歌曲、文档等。

8.2配置

配置防盗链先编辑主机配置文件:

  # vim httpd-vhosts.conf      //修改配置文件如下:

     增加内容:

     <Directory /data/wwwroot/www.111.com>

        SetEnvIfNoCase Referer "http://www.111.com" local_ref

        SetEnvIfNoCase Referer "http://111.com" local_ref

        SetEnvIfNoCase Referer "^$" local_ref

        <filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif)">

            Order Allow,Deny

            Allow from env=local_ref

        </filesmatch>

    </Directory>

保存配置后,测试配置文件是否正确,没有错误重新加载服务:

 # /usr/local/apache2.4/bin/apachectl -t

Syntax OK

# /usr/local/apache2.4/bin/apachectl graceful

8.3配置验证

  # curl -e "http://www.douxue.com/123.php" -xlocalhost:80 www.111.com/images/linux.png -I


9.


访问控制-Diretory\FileMatch

9.1介绍

访问控制限制白名单IP,针对文件和目录。

9.2目录配置

先来看看怎么限制IP访问,编辑配置文件:

 # vim httpd-vhosts.conf      //修改配置文件如下:

     增加内容:

       <Directory /usr/local/apache2.4/docs/www.111.com/admin/>

        Order deny,allow

        Deny from all

        Allow from 127.0.0.1

    </Directory>

保存配置后,测试配置文件是否正确,没有错误重新加载服务:

  # /usr/local/apache2.4/bin/apachectl -t

Syntax OK

# /usr/local/apache2.4/bin/apachectl graceful

9.3配置验证

# curl -x192.168.49.133:80 www.111.com/admin/123.php -I

# curl -x127.0.0.1:80 www.111.com/admin/123.php -I

9.4验证成功

9.5针对文件配置

编辑配置文件:

   # vim httpd-vhosts.conf      //修改配置文件如下:

     增加内容:

      <Directory /usr/local/apache2.4/docs/www.111.com>

      <filesMatch admin.php(.*)>

        Order deny,allow

        Deny from all

        Allow from 127.0.0.1

      </filesMatch>

      </Directory>

保存配置后,测试配置文件是否正确,没有错误重新加载服务:

  # /usr/local/apache2.4/bin/apachectl -t

Syntax OK

# /usr/local/apache2.4/bin/apachectl graceful

9.6配置验证

 # curl -x127.0.0.1:80 www.111.com/admin.php -I

 # curl -x192.168.49.133:80 www.111.com/admin.php -I


10.


访问控制-禁止解析PHP

10.1简述

对于使用PHP语言编写的网站,有一些目录是有需求上传文件的。如果网站代码有漏洞,让黑客上传了一个用PHP写的木马,由于网站可以执行PHP程序,最终会让黑客拿到服务器权限。

为了避免这种情况发生,我们需要把能上传文件的目录直接禁止解析PHP代码。

10.2配置

 [root@localhost extra]# vim httpd-vhosts.conf      //修改配置文件如下:

     增加内容:

       <Directory /usr/local/apache2.4/docs/www.111.com/upload>

      php_admin_flag engine off

保存配置后,测试配置文件是否正确,没有错误重新加载服务:

 # /usr/local/apache2.4/bin/apachectl -t

Syntax OK

# /usr/local/apache2.4/bin/apachectl graceful

10.3配置验证

 # curl -x192.168.49.133:80 www.111.com/upload/123.php


11.


访问控制-user_agent

11.1介绍

user_agent

是指用户浏览器端的信息。比如你是用IE的还是Firefox浏览器的。有些网站会根据这个来调整打开网站的类型,如是手机的就打开wap,显示非手机的就打开PC常规页面。

11.2配置

[root@localhost extra]# vim httpd-vhosts.conf      //修改配置文件如下:

     增加内容:

   <IfModule mod_rewrite.c>

        RewriteEngine on

        RewriteCond %{HTTP_USER_AGENT}  .*curl.* [NC,OR]

        RewriteCond %{HTTP_USER_AGENT}  .*baidu.com.* [NC]

        RewriteRule  .*  -  [F]

    </IfModule>

保存配置后,测试配置文件是否正确,没有错误重新加载服务:

 # /usr/local/apache2.4/bin/apachectl -t

Syntax OK

# /usr/local/apache2.4/bin/apachectl graceful

11.3配置验证

​
# curl -x192.168.49.133:80 www.111.com/upload/123.php




三.




任务3 PHP配置




  1. PHP基础配置

查看PHP配置文件得位置

# /usr/local/php/bin/php -i |grep -i "loaded configuration file"

# vim  /usr/local/php/etc/php.ini

搜索disable_functions,编辑如下:

disable_functions=eval,assert,popen,passthru,escapeshellarg,escapeshellcmd,passthru,exec,system,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,1eak,popepassthru,stream_socket_server,popen,proc_open,proc_close

定义date.timezone,减少警告

# vim  /usr/local/php/etc/php.ini

找到date.timezone设置如下:

date.timezone =Asia/Shanghai


  1. 日志相关配置

# vim /usr/local/php/etc/php.ini

搜索log_errors, 改成log_errors=On

搜索error. log,改为error_log = /var/log/php/php_errors.log

搜索error_reporting 改为error_reporting = E ALL & ~E_ NOTICE

搜索display_errors,改为display_errors = Off

配置完php.ini,可以额外配置

 # mkdir /var/log/php     //创建错误日志目录

  #chmod 777 /var/log/php     //增加权限

 #/usr/local/apache2.4/bin/apachectl graceful     //重新加载服务


  1. 配置open_basedir

在php.ini中设置open_basedir:
 # vim /usr/local/php/etc/php.ini

    搜索open_basedir,改成open_ basedir = /tmp:/usr/local/apache2.4/docs/abc.com

 保存配置后,测试配置文件是否正确,没有错误重新加载服务:

# /usr/local/apache2.4/bin/apachectl -t

Syntax OK

# /usr/local/apache2.4/bin/apachectl graceful

# cp /usr/local/apache2.4/htdocs/1.php /data/wwwroot/testdomain.com/

# curl -xlocalhost:80 -I 111.com/1.php


  1. 虚拟主机配置open_basedir

# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf

   增加内容如下:

    CustomLog "|/usr/local/apache2.4/bin/rotatelogs -l logs/123.com-access_%Y%m%d.1og 86400"combined

    php_admin_value open_basedir "/data/wwwroot/testdomain.com/:/tmp/"

    //起作用的是php_admin_value,它定义了php.ini的参数

         保存配置后,测试配置文件是否正确,没有错误重新加载服务:

# /usr/local/apache2.4/bin/apachectl -t

Syntax OK

# /usr/local/apache2.4/bin/apachectl graceful




四.




任务4 PHP 扩展模块安装



​
# /usr/local/php/bin/php -m    //查看PHP加载了哪些模块

      下载 http://pecl.php.net/get/redis-2.2.5.tgz   //下载redis

[root@lamp src]# tar -zxvf redis-2.2.5.tgz

      [root@lamp src]# mv redis-2.2.5 phpredis-develop

      [root@lamp src]# cd phpredis-develop

[root@lamp phpredis-develop]# /usr/local/php/bin/phpize   //目的生成configure文件

# ./configure  --with-php-config=/usr/local/php/bin/php-config

[root@lamp phpredis-develop]# make -j4 && make install//make install时候编译好的就会放在这个目录里

  

[root@lamp phpredis-develop]# vim /usr/local/php/etc/php.ini

extension = redis.so    //增加一行配置(可以放在文件最后一行)

[root@lamp phpredis-develop]# /usr/local/php/bin/php -m |grep redis   //查看是否加载了redis模块

​



版权声明:本文为m0_57928863原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。