最新版本的LAMP搭建

来源:互联网 发布:部落实验室升级数据 编辑:程序博客网 时间:2024/06/05 14:02


一. 环境描述:

   虚拟硬件环境:2cpu, 4G MEM

   系统环境:CentOS6.8

   内核版本:2.6.32-642.el6.x86_64

   安装类型:Minimal Desktop

   apache版本:httpd-2.2.32

   mysql版本:MySQL-server-5.6.35

   PHP版本:php-7.1.4

   libiconv版本:libiconv-1.14

   扩展yum源:epel-release-6-8.noarch.rpm

   安装包目录: /root/pkg

二. 安装依赖包及其他准备工作

   1. 安装epel yum源

    # rpm -ivh epel-release-6-8.noarch.rpm

   2. 安装依赖包: 包括编译工作,软件依赖包

yum install gcc gcc-c++ ntp make imake automake autoconf screen  bash sysstat libicu-devel compat-libstdc++-33 mhash \
mhash-devel gettext gettext-devel libxml2 libxml2-devel curl curl-devel openssl openssl-devel pcre pcre-devel \
libpng libpng-devel libjpeg-turbo libjpeg-turbo-static libjpeg-turbo-devel freetype freetype-devel libxslt-devel \
gd gd-devel zlib zlib-devel libmcrypt libmcrypt-devel libXpm libXpm-devel ncurses ncurses-devel -y
 

   3. 创建组,和用户

     groupadd -g 1000 www >/dev/null 2>&1

     useradd -g 1000 -u 1000 -d /dev/null -s /sbin/nologin www >/dev/null 2>&1   


三. 安装httpd
     
   1. 下载并解压

     cd /root/pkg; wget https://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.2.32.tar.gz

     tar -zxf httpd-2.2.32.tar.gz ; cd httpd-2.2.32

   2. 检查,编译,安装

   (1)检查,配置

# ./configure --prefix=/usr/local/httpd-2.2.32 \
--with-mpm=prefork --enable-rewrite --enable-deflate   \
--disable-userdir --enable-so  --enable-expires \
--enable-headers --with-included-apr  \
--enable-mime-magic --enable-ssl \
--enable-static-support

部分输出如下:


config.status: creating docs/conf/httpd.conf
config.status: creating docs/conf/extra/httpd-autoindex.conf
config.status: creating docs/conf/extra/httpd-dav.conf
config.status: creating docs/conf/extra/httpd-default.conf
config.status: creating docs/conf/extra/httpd-info.conf
config.status: creating docs/conf/extra/httpd-languages.conf
config.status: creating docs/conf/extra/httpd-manual.conf
config.status: creating docs/conf/extra/httpd-mpm.conf
config.status: creating docs/conf/extra/httpd-multilang-errordoc.conf
config.status: creating docs/conf/extra/httpd-ssl.conf
config.status: creating docs/conf/extra/httpd-userdir.conf
config.status: creating docs/conf/extra/httpd-vhosts.conf
config.status: creating include/ap_config_layout.h
config.status: creating support/apxs
config.status: creating support/apachectl
config.status: creating support/dbmmanage
config.status: creating support/envvars-std
config.status: creating support/log_server_status
config.status: creating support/logresolve.pl
config.status: creating support/phf_abuse_log.cgi
config.status: creating support/split-logfile
config.status: creating build/rules.mk
config.status: creating build/pkg/pkginfo
config.status: creating build/config_vars.sh
config.status: creating include/ap_config_auto.h
config.status: executing default commands



  (2)编译
   make -j 2

  (3)安装
   make install


   3. 配置httpd --- 通过脚本

    (1). 创建脚本目录

      mkdir /root/scr; cd /root/scr

    (2) 配置httpd的脚本,生成启动httpd脚本

    [root@lamp7 scr]# vim /root/scr/gen_httpd-2-2-32.sh
#!/bin/bash
#date: 2017-3-7
#desc: general init httpd

#ln -sf /usr/local/httpd-2.2.32 /usr/local/httpd
sed -i 's/User daemon/User www/g' /usr/local/httpd-2.2.32/conf/httpd.conf
sed -i 's/Group daemon/Group www/g' /usr/local/httpd-2.2.32/conf/httpd.conf
sed -i 's@DirectoryIndex index.html@DirectoryIndex index.html index.php index.htm@' /usr/local/httpd-2.2.32/conf/httpd.conf
sed -i '/#ServerName/a ServerName localhost' /usr/local/httpd-2.2.32/conf/httpd.conf

echo 'Include conf/httpd-wdl.conf' >>/usr/local/httpd-2.2.32/conf/httpd.conf

mkdir /usr/local/httpd-2.2.32/init

echo '#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#              HTML files and CGI.
# processname: httpd
# config: /usr/local/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /usr/local/httpd/logs/httpd.pid

# Source function library.
. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi

# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}

# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""

# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.

# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/httpd/bin/apachectl
httpd=${HTTPD-/usr/local/httpd/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/usr/local/httpd/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0

# The semantics of these two functions differ from the way apachectl does
# things -- attempting to start while running is a failure, and shutdown
# when not running is also a failure.  So we just do it the way init scripts
# are expected to behave here.
start() {
        echo -n $"Starting $prog: "
        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch ${lockfile}
        return $RETVAL
}

# When stopping httpd a delay of >10 second is required before SIGKILLing the
# httpd parent; this gives enough time for the httpd parent to SIGKILL any
# errant children.
stop() {
        echo -n $"Stopping $prog: "
        killproc -p ${pidfile} -d 3 $httpd
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
    echo -n $"Reloading $prog: "
    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
        RETVAL=$?
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
    fi
    echo
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  status)
        status -p ${pidfile} $httpd
        RETVAL=$?
        ;;
  restart)
        stop
        start
        ;;
  condrestart)
        if [ -f ${pidfile} ] ; then
                stop
                start
        fi
        ;;
  reload)
        reload
        ;;
  graceful|help|configtest|fullstatus)
        $apachectl $@
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
        exit 1
esac
exit $RETVAL' > /usr/local/httpd-2.2.32/init/httpd
chmod 755 /usr/local/httpd-2.2.32/init/httpd
ln -sf /usr/local/httpd-2.2.32/init/httpd  /etc/init.d/httpd
chkconfig --add httpd
chkconfig --level 35 httpd on

echo 'Timeout 30
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 15
UseCanonicalName Off
ServerTokens Prod
ServerSignature Off
HostnameLookups Off
AddType application/x-httpd-php .php
DirectoryIndex index.html index.php index.htm
<IfModule mpm_worker_module>
    ServerLimit        32
    ThreadLimit        256
    StartServers        12
    MaxClients          2048
    MinSpareThreads      50
    MaxSpareThreads      256
    ThreadsPerChild      256
    MaxRequestsPerChild   0
</IfModule>
<IfModule mpm_prefork_module>
    ServerLimit         1024
    StartServers          5
    MinSpareServers       3
    MaxSpareServers      30
    MaxClients          1024
    MaxRequestsPerChild   0
</IfModule>
<IfModule mpm_itk_module>
    ServerLimit         1024
    StartServers          5
    MinSpareServers       3
    MaxSpareServers      30
    MaxClients          1024
    MaxRequestsPerChild   0
</IfModule>' >/usr/local/httpd-2.2.32/conf/httpd-wdl.conf

==============   脚本结束 ========================

  (3)分配脚本执行权限,并执行脚本

   # chmod +x gen_httpd-2-2-32.sh

   # ./gen_httpd-2-2-32.sh

 
  (4)  添加虚拟主机配置脚本:

   [root@lamp7 scr]# vim add_conf_http2-2-32.sh
#!/bin/bash
#date:2017-3-7
#desc: add vhost and security config


mkdir -pv /home/web/test

echo 'TraceEnable off
ServerSignature Off
ServerTokens Prod' >>/usr/local/httpd-2.2.32/conf/httpd.conf

echo '<VirtualHost *:80>
DocumentRoot /home/web/test
ServerName test.example.cn
ServerAlias test.sample.cn
#php_admin_value open_basedir /home/web/test:/tmp
<IfModule mod_limitipconn.c>
    <Location />
        MaxConnPerIP 20
    </Location>
</IfModule>
<IfModule mod_bw.c>
    BandWidthModule On
    ForceBandWidthModule On
    BandWidth all 204800
</IfModule>
<IfModule mod_deflate.c>
    DeflateCompressionLevel 7
    AddOutputFilterByType DEFLATE text/html text/plain text/xml application/x-httpd-php
    AddOutputFilter DEFLATE css js html htm gif jpg png bmp php
</IfModule>
</VirtualHost>
<Directory /home/web/test>
    Options FollowSymLinks
    AllowOverride All
    Allow from all
</Directory>' >>/usr/local/httpd-2.2.32/conf/httpd.conf


============== 脚本结束 ===========================

  (5) 虚拟主机配置脚本授权与执行

    # chmod +x add_conf_http2-2-32.sh
    # ./add_conf_http2-2-32.sh
 
   
  (6)  调整软链接,使用httpd 服务正常启动

   # ln -sf /usr/local/httpd-2.2.32 /usr/local/httpd
   # /etc/init.d/httpd restart   

  (7) 创建测试页并测试WEB站点
 
    # echo "this is test web" > /home/web/test/index.html

    [root@lamp7 scr]# curl http://192.168.197.141
    this is test web
   

  (8) windows主机浏览器测试

    修改C:\Windows\System32\drivers\etc\hosts 添加如下两行:

    192.168.197.141        test.eample.com
    192.168.197.141          test.sample.com

    在windows系统浏览器里输入:

   http://test.example.cn/

   http://test.sample.cn/

   如果显示:this is test web ,则说明WEB站点正常显示静态页面



四. 安装MySQL-5.6.35

   1. 软件包:下载地址:http://ftp.jaist.ac.jp/pub/mysql/Downloads/MySQL-5.6/
 
     MySQL-client-5.6.35-1.el6.x86_64.rpm
     MySQL-devel-5.6.35-1.el6.x86_64.rpm
     MySQL-shared-compat-5.6.35-1.el6.x86_64.rpm     
     MySQL-server-5.6.35-1.el6.x86_64.rpm

   2. 安装MySQL-5.6.35

     # rpm -vih MySQL-client-5.6.35-1.el6.x86_64.rpm MySQL-devel-5.6.35-1.el6.x86_64.rpm MySQL-shared-compat-5.6.35-1.el6.x86_64.rpm
warning: MySQL-client-5.6.35-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:MySQL-shared-compat    ########################################### [ 33%]
   2:MySQL-devel            ########################################### [ 67%]
   3:MySQL-client           ########################################### [100%]
      
     # rpm -e mysql-libs-5.1.73-7.el6.x86_64    #删除冲突包

     # rpm -ivh MySQL-server-5.6.35-1.el6.x86_64.rpm
warning: MySQL-server-5.6.35-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]

     
   3. 查看MySQL-5.6.35默认的密码

     [root@lamp7 ~]# cat .mysql_secret
     # The random password set for the root user at Sun Jun 18 08:40:37 2017 (local time): iLuq5aGprNIXqwud


   4. 增加安全配置:

    (1) 启动MySQL, 确保mysql启动成功,并设置开机启动

        # /etc/init.d/mysql start   
        # chkconfig mysql on


    (2) 启动安全配置脚本:包括重设置密码,删除匿名用户,禁止root远程登录, 删除测试库,重载用户权限表

     [root@lamp7 pkg]# /usr/bin/mysql_secure_installation



NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

You already have a root password set, so you can safely answer 'n'.

Change the root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] Y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] Y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] Y
 ... Success!




All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


Cleaning up...

   

    5. 配置my.cnf

     (1) MySQL-5.6.35默认的my.cnf在/usr/my.cnf 位置,而不是/etc/my.cnf


     (2) 修改默认data路径/var/lib/mysql到指定路径/home/mysqldata

       创建/home/mysqldata,复制mysql数据文件到新路径,并授权

       mkdir -pv /home/mysqldata;cd /var/lib/mysql; cp -rpfv * /home/mysqldata; chown -R mysql.mysql /home/mysqldata

     (3) 修改默认的my.cnf

[root@wangxlTEST40 usr]# vim my.cnf
[root@wangxlTEST40 usr]# cat /usr/my.cnf
# The following options will be passed to all MySQL clients
# [client]
# #password       = your_password
# port            = 3306
# socket          = /home/new_database/mysql/mysql.sock
#
# # Here follows entries for some specific programs
#
# # The MySQL server

[mysqld]
port            = 3306
socket          = /home/mysqldata/mysql.sock
datadir = /home/mysqldata
pid-file = /home/mysqldata/mysqlhost.pid
default-storage-engine=INNODB
character_set_server=utf8
expire_logs_days = 10

key_buffer_size = 4G
max_allowed_packet = 1000M
table_open_cache = 64
sort_buffer_size = 32M
read_buffer_size = 16M
read_rnd_buffer_size = 64M
myisam_max_sort_file_size=50G
myisam_sort_buffer_size = 738M
thread_cache_size = 8
max_connections=2000
max_connect_errors = 500
tmp_table_size=369M
query_cache_size= 512M
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 8
lower_case_table_names=1

innodb_additional_mem_pool_size=256M
innodb_flush_log_at_trx_commit=1
innodb_log_buffer_size=4M
innodb_buffer_pool_size=3G
innodb_doublewrite=0
innodb_log_file_size = 500M
innodb_thread_concurrency=8
innodb_lock_wait_timeout=10
log-bin=mysql-bin
binlog-format=mixed
server-id       = 1
#mysql5.6 已经放弃此变量
#max_long_data_size = 16M

[mysqldump]
quick
max_allowed_packet = 500M

[mysql]
no-auto-rehash
[myisamchk]
key_buffer_size = 20M
sort_buffer_size = 20M
read_buffer = 2M
write_buffer = 2M

[mysqlhotcopy]
interactive-timeout=600
                     
[mysqld_safe]
log-error=/var/log/mysql.err.log

+++++++++++++++++ my.cnf 结束   ++++++++++++++++++++++++

/etc/init.d/mysql restart



五. 编译安装libiconv-1.14

  1. libiconv组件安装好了可以让我们php支持iconv函数了,这个函数的作用就是字符编码强制转换了,

     如果不编译安装libiconv-1.14,编译php-7.1.4时会报错


  2. 下载libiconv-1.14.tar.gz

    cd /root/pkg; wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

  3. 解压并进入解压后的目录

    tar zxf libiconv-1.14.tar.gz ;cd libiconv-1.14

  4. 检查,配置,编译,安装

   ./configure --prefix=/usr/local/libiconv

   部分输出如下:

     configure: creating ./config.status
     config.status: creating Makefile
     config.status: executing libtool commands

   ========= 输出结束 ==========
   
   make -j 2          #-j 2 表示用两个核来编译

   make install

 
   注意:编译php7.1.14 带上 --with-iconv-dir=/usr/local/libiconv


  5. 检查安装是否成功

   # ll /usr/local/ |grep libiconv
drwxr-xr-x   6 root root 4096 6月  18 16:22 libiconv


六. 安装配置 PHP-7.1.4

   1. 下载: PHP-7.1.4

     cd /root/pkg; wget http://cn.php.net/distributions/php-7.1.4.tar.gz

   2. 解压并进入解压后的目录

    tar -zxf php-7.1.4.tar.gz ; cd php-7.1.4


   3. 检查,配置,编译,安装

  (1)检查,配置
#./configure --prefix=/usr/local/php-7.1.4 \
 --with-apxs2=/usr/local/httpd-2.2.32/bin/apxs \
 --with-config-file-path=/usr/local/php-7.1.4/etc \
 --with-curl \
 --with-freetype-dir \
 --with-gd \
 --with-jpeg-dir \
 --with-gettext \
 --with-kerberos \
 --with-libdir=lib64 \
 --with-libxml-dir \
 --with-openssl \
 --with-mcrypt \
 --with-mhash \
 --with-pcre-regex \
 --with-mysqli=mysqlnd \
 --with-pdo-mysql=mysqlnd \
 --with-pdo-sqlite \
 --with-pear \
 --with-png-dir \
 --with-xmlrpc \
 --with-xsl \
 --with-zlib \
 --with-iconv-dir=/usr/local/libiconv \
 --enable-mysqlnd \
 --enable-bcmath \
 --enable-libxml \
 --enable-inline-optimization \
 --enable-gd-native-ttf \
 --enable-mbregex \
 --enable-mbstring \
 --enable-opcache \
 --enable-pcntl \
 --enable-shmop \
 --enable-soap \
 --enable-sockets \
 --enable-sysvsem \
 --enable-intl \
 --enable-exif \
 --enable-xml \
 --enable-ftp \
 --enable-zip \
 --without-pear \
 --disable-phar

部分输出如下:

###############   省略部分输出 ###################

Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating main/php_config.h
config.status: executing default commands

###############  输出结束 ###################


 (2) 编译php-7.1.4
  make -j 2

Build complete.
Don't forget to run 'make test'.

 (3) 安装php-7.1.4

  make install

  执行结果输出如下:

[root@lamp7 php-7.1.4]# make install
Installing PHP SAPI module:       apache2handler
/usr/local/httpd-2.2.32/build/instdso.sh SH_LIBTOOL='/usr/local/httpd-2.2.32/build/libtool' libphp7.la /usr/local/httpd-2.2.32/modules
/usr/local/httpd-2.2.32/build/libtool --mode=install cp libphp7.la /usr/local/httpd-2.2.32/modules/
libtool: install: cp .libs/libphp7.so /usr/local/httpd-2.2.32/modules/libphp7.so
libtool: install: cp .libs/libphp7.lai /usr/local/httpd-2.2.32/modules/libphp7.la
libtool: warning: remember to run 'libtool --finish /root/pkg/php-7.1.4/libs'
chmod 755 /usr/local/httpd-2.2.32/modules/libphp7.so
[activating module `php7' in /usr/local/httpd-2.2.32/conf/httpd.conf]
Installing shared extensions:     /usr/local/php-7.1.4/lib/php/extensions/no-debug-non-zts-20160303/
Installing PHP CLI binary:        /usr/local/php-7.1.4/bin/
Installing PHP CLI man page:      /usr/local/php-7.1.4/php/man/man1/
Installing phpdbg binary:         /usr/local/php-7.1.4/bin/
Installing phpdbg man page:       /usr/local/php-7.1.4/php/man/man1/
Installing PHP CGI binary:        /usr/local/php-7.1.4/bin/
Installing PHP CGI man page:      /usr/local/php-7.1.4/php/man/man1/
Installing build environment:     /usr/local/php-7.1.4/lib/php/build/
Installing header files:          /usr/local/php-7.1.4/include/php/
Installing helper programs:       /usr/local/php-7.1.4/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php-7.1.4/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PDO headers:           /usr/local/php-7.1.4/include/php/ext/pdo/


 (4) 手动创建配置文件目录etc

mkdir  /usr/local/php-7.1.4/etc


 (5) 修改php-7.1.4的配置文件php.ini


cp -v /root/pkg/php-7.1.4/php.ini-production /usr/local/php-7.1.4/etc/php.ini
sed -i 's@^short_open_tag = Off@short_open_tag = On@' /usr/local/php-7.1.4/etc/php.ini
sed -i 's@^;date.timezone =@date.timezone = Asia/Shanghai@' /usr/local/php-7.1.4/etc/php.ini
sed -i 's@^upload_max_filesize = 2M@upload_max_filesize = 100M@' /usr/local/php-7.1.4/etc/php.ini
sed -i 's@^post_max_size = 8M@post_max_size = 200M@' /usr/local/php-7.1.4/etc/php.ini
sed -i 's@^max_execution_time = 30@max_execution_time = 1800@' /usr/local/php-7.1.4/etc/php.ini
sed -i 's@^expose_php = On@expose_php = Off@' /usr/local/php-7.1.4/etc/php.ini
sed -i 's@^session.cookie_httponly =@session.cookie_httponly = 1@' /usr/local/php-7.1.4/etc/php.ini
sed -i 's@^memory_limit = 128M@memory_limit = 1024M@' /usr/local/php-7.1.4/etc/php.ini
sed -i 's@^max_input_time = 60@max_input_time = 1800@' /usr/local/php-7.1.4/etc/php.ini
sed -i 's@enable_dl = Off@enable_dl = On@' /usr/local/php-7.1.4/etc/php.ini
sed -i 's@max_file_uploads = 20@max_file_uploads = 150@' /usr/local/php-7.1.4/etc/php.ini
sed -i 's@log_errors = On@log_errors = Off@' /usr/local/php-7.1.4/etc/php.ini


对以上条目的解释:

 1. 时区: date.timezone = Asia/Shanghai

  2. 上传文件尺寸限制:upload_max_filesize = 64M
 
  3.  post尺寸: post_max_size = 64M

  4.  最大执行时间: max_execution_time = 300

  5.  内存限制: memory_limit = 512M

  6.  expose_php = Off        #不在响应头中显示PHP版本信息

  7.  session.cookie_httponly = 1    

      #意思是:httponly设置为true则只能通过http操纵cookie,这样防止了javascript等脚本语言对cookie做修改,帮助我们有效的防止XSS攻击.设置其值为1或者TRUE,来开启全局的Cookie的HttpOnly属性

  8. max_input_time = 1800

  9. log_errors = Off

  10. enable_dl = On | Off  默认值:Off, 允许用户在运行时加载PHP扩展,即在脚本运行期间加载。

  11. max_file_uploads = 150    #Maximum number of files that can be uploaded via a single request

  12. disable_functions = phpinfo   禁用phpinfo


  4. 编译soap模块,安装,配置

   (1) 检测soap

    cd /root/pkg/php-7.1.4/ext/soap    #注意: 之后的编译,安装操作都在/root/pkg/php-7.1.4/ext/soap

    [root@lamp7 soap]#  /usr/local/php-7.1.4/bin/phpize
    Configuring for:
    PHP Api Version:         20160303
    Zend Module Api No:      20160303
    Zend Extension Api No:   320160303

   (2) 配置,编译,安装soap

    ./configure -with-php-config=/usr/local/php-7.1.4/bin/php-config --enable-soap
    
    部分输出如下:

    ###############   省略部分输出 ###################
 
    creating libtool
    appending configuration tag "CXX" to libtool
    configure: creating ./config.status
    config.status: creating config.h

    ###############  输出结束 ###################
 
    make -j 2

    [root@lamp7 soap]# make install
    Installing shared extensions:     /usr/local/php-7.1.4/lib/php/extensions/no-debug-non-zts-20160303/

  (3) 配置文件php.inij加入soap配置项


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

  在第739行加入

extension_dir="/usr/local/php-7.1.4/lib/php/extensions/no-debug-non-zts-20160303/"
extension = "soap.so"

 
  (4) 重启httpd 使php.ini生效

    因为php是apache里的一个模块:

   [root@lamp7 modules]# ls /usr/local/httpd-2.2.32/modules/
   httpd.exp  libphp7.so

   /etc/init.d/httpd restart


   5. 测试lamp页面

  vim /home/web/test/phpinfo.php

<?php phpinfo();?>

  在浏览器输入:http://192.168.197.141/phpinfo.php


七. 故障汇总

1. 故障报错1及解决:

mysql 启动报错

[root@lamp7 usr]# /etc/init.d/mysql restart
MySQL server PID file could not be found!                  [失败]
Starting MySQL.rm: 无法删除"/home/mysqldata/mysql.sock": 权限不够
rm: 无法删除"/home/mysqldata/mysqlhost.pid": 权限不够
.The server quit without updating PID file (/home/mysqldata[失败]host.pid).


mysql 报错日志

/usr/sbin/mysqld: File './mysql-bin.index' not found (Errcode: 13 - Permission denied)
2017-06-18 15:40:38 7084 [ERROR] Aborting

2017-06-18 15:40:38 7084 [Note] Binlog end
2017-06-18 15:40:38 7084 [Note] /usr/sbin/mysqld: Shutdown complete


解决:关闭selinux, 然后重启后正常启动mysql服务

sed -i s/SELINUX=enforcing/SELINUX=disabled/ /etc/selinux/config

开始怀疑是my.cnf参数设置不当造成,因为测试的虚拟机实际是1G内存,而my.cnf里的参数是按照4G内存设计的

主要怀疑 /usr/my.cnf 下的这两项

innodb_buffer_pool_size=3G
key_buffer_size = 4G

实际上在1G内存的系统里,my.cnf设计为4G内存,仍然可正常启动


2. 故障报错2: 编译php-7.1.4 时用make -j 4 导致编译出错

   解决: php-7.1.4 不要用多核编译 ,如make -j 4 会报错,可以用make -j 2 或者make


3. httpd报500错误

特别注意:httpd.conf里没有下面这句,会报500错误

AddType application/x-httpd-php .php


4. 编译安装后,php网站无法上传jpg图片, 报unsupport type jpg
 

  原因:配置php-7.l.4时,没有配置项: ./configure  --with-jpeg-dir

  解决:重新配置php-7.l.4时, 加上--with-jpeg-dir


5. PHP网站报错:Unable to connect to the Database: This driver is unsupported in PHP 7, please use the MySQLi or PDO MySQL driver instead.

  原因是:php7 不再支持--with-mysql选项

  解决: 重新编译配置项: configure --with-mysqli --with-pdo-mysql 改为 configure --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd


6. 编译安装php-7.1.4后, 在/usr/local/httpd-2.2.32/modules/里没找到libphp7.so

   解决: 在configure php7时加上 --with-apxs2=/usr/local/httpd-2.2.32/bin/apxs

   再编译安装php-7.1.4后,在/usr/local/httpd-2.2.32/modules/里找到libphp7.so

7. 编译 php-7.1.4 时, make -j 2 遇到如下错误:

 
/root/pkg/php-7.1.4/ext/xmlrpc/libxmlrpc/encodings.c:74: undefined reference to `libiconv_open'
/root/pkg/php-7.1.4/ext/xmlrpc/libxmlrpc/encodings.c:82: undefined reference to `libiconv'
/root/pkg/php-7.1.4/ext/xmlrpc/libxmlrpc/encodings.c:102: undefined reference to `libiconv_close'
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] 错误 1

  解决方案1: 在centos6.5 环境: 编译 php-7.1.4的命令:make -j 2 ZEND_EXTRA_LIBS='-liconv'

  解决方案2: 在centos6.8 环境:make -j 2 ZEND_EXTRA_LIBS='-liconv' 无效

       报错如下:

/usr/bin/ld: cannot find -liconv
collect2: ld returned 1 exit status
make: *** [libphp7.la] 错误 1
make: *** 正在等待未完成的任务....
/usr/bin/ld: cannot find -liconv
collect2: ld returned 1 exit status
make: *** [sapi/cli/php] 错误 1

   根本解决是安装libiconv-1.14.tar.gz

libiconv组件安装好了可以让我们php支持iconv函数了,这个函数的作用就是字符编码强制转换了

wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz

tar zxf libiconv-1.14.tar.gz

cd libiconv-1.14

./configure --prefix=/usr/local/libiconv

make -j 2

make install

重新编译php7.1.4 带上 --with-iconv-dir=/usr/local/libiconv

未报错

Build complete.
Don't forget to run 'make test'.

8. PEAR报错:package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.


  PEAR package的作用: Pear库几乎涵盖了使用PHP可以操作任何方面, 当你希望快捷高效开发基于PHP网站和WEB应用的时候,Pear库将能为你提供意想不到帮助

./configure php-7.1.4 加上这两项,--without-pear  --disable-phar, 再make, make install


9. phpinfo()函数报错:

   浏览http://192.168.197.141/phpinfo.php时页面显示Loaded Configuration File(none)

   原因是phpinfo()找不到 php7的配置文件php.ini位置

   解决:configure  --with-config-file-path=/usr/local/php-7.1.4/etc

        否则,配置文件的路径会被放到这里/usr/local/php-7.1.4/lib,且无php.ini







原创粉丝点击