centOS6.6 编译安装lnmp(PHP 7.0.9+Nginx1.9.9+MySQL5.7.15)

前端之家收集整理的这篇文章主要介绍了centOS6.6 编译安装lnmp(PHP 7.0.9+Nginx1.9.9+MySQL5.7.15)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一、系统约定
代码位置:/usr/local/src

安装位置:/usr/local/软件名字
二、软件下载
(所需软件几乎可以全部从搜狐镜像站http://mirrors.sohu.com/下载,速度快)
1、下载Nginx(目前稳定版)
[root@bogon src]# wget http://nginx.org/download/nginx-1.9.9.tar.gz

2、下载pcre (支持Nginx伪静态)
[xuj@bogon ~]$ wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz

3、下载MysqL
[root@bogon src]# wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.15.tar.gz
http://mirrors.sohu.com/mysql/MySQL-5.7/mysql-5.7.14.tar.gz

4、下载PHP
[root@bogon src]# wget http://mirrors.sohu.com/php/php-7.0.9.tar.gz

5、下载cmake(MysqL编译工具)
[root@bogon src]# wget https://cmake.org/files/v3.6/cmake-3.6.2.tar.gz

6、下载libmcrypt(PHPlibmcrypt模块)
http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz

7、下载GD库安装包

[root@bogon src]# wget https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.1.tar.gz

http://download.csdn.net/download/xujunabc999/9629853 下载完用winscp软件上传

三、安装过程

  1. 安装cmake
    cd /usr/local/src
    tar zxvf cmake-2.8.8.tar.gz
    cd cmake-2.8.8
    ./configure
    make #编译
    make install #安装
  2. 安装MysqL
    如果已经安装MysqL,安装前请先卸载干净
    MysqL卸载教程 http://www.jb51.cc/article/p-mctuvqjf-st.html
    MysqL安装教程 http://www.jb51.cc/article/p-znnrxyah-st.html
  3. 查看是否安装过pcre

    卸载 yum remove pcre
    [root@bogon xuj]# yum remove pcre-devel-7.8-7.el6.i686
    yum remove pcre-7.8-7.el6.i686
    cd /usr/local/src
    mkdir /usr/local/pcre #创建安装目录
    tar zxvf pcre-8.39.tar.gz
    cd pcre-8.39
    ./configure –prefix=/usr/local/pcre #配置
    make
    make install
  4. 安装 Nginx
    cd /usr/local/src
    groupadd www #添加www组
    useradd -g www www -s /bin/false #创建Nginx运行账户www并加入到www组,不允许www用户直接登录系统
    tar zxvf Nginx-1.2.3.tar.gz
    cd Nginx-1.2.3
    ./configure –prefix=/usr/local/Nginx –without-http_memcached_module –user=www –group=www –with-http_stub_status_module –with-openssl=/usr/ –with-pcre=/usr/local/src/pcre-8.39
    注意:–with-pcre=/usr/local/src/pcre-8.39指向的是源码包解压的路径,而不是安装的路径,否则会报错
    make
    make install
    /usr/local/Nginx/sbin/Nginx #启动Nginx
    设置Nginx开启启动
    vi /etc/rc.d/init.d/Nginx #编辑启动文件,下载并拷贝http://download.csdn.net/detail/xujunabc999/9634045内容
    :wq! #保存退出
    chmod 775 /etc/rc.d/init.d/Nginx #赋予文件执行权限
    chkconfig Nginx on #设置开机启动
    /etc/rc.d/init.d/Nginx restart
    service Nginx restart
  5. 安装libmcrypt
    cd /usr/local/src
    tar zxvf libmcrypt-2.5.8.tar.gz #解压
    cd libmcrypt-2.5.8 #进入目录
    ./configure #配置
    make #编译
    make install #安装
  6. 安装gd
    cd /usr/local/src
    tar zxvf libgd-2.1.1.tar.gz #解压
    cd libgd-2.1.1 #进入目录
    yum install libpng libpng-devel libjpeg-turbo libjpeg-turbo-devel freetype freetype-devel gd
    [root@bogon libgd-2.1.1]# ./configure –enable-m4_pattern_allow –prefix=/usr/local/gd –with-jpeg=/usr/lib –with-png=/usr/local –with-xpm=/usr/lib –with-freetype=/usr/local –with-fontconfig=/usr/include/fontconfig #配置
    libpng ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng16/libpng-1.6.25.tar.gz
    libjpeg https://sourceforge.net/projects/libjpeg/files/libjpeg/6b/jpegsrc.v6b.tar.gz
    freetype http://download.savannah.gnu.org/releases/freetype/freetype-2.7.tar.gz
    fontconfig https://www.freedesktop.org/software/fontconfig/release/fontconfig-2.12.1.tar.gz
    make #编译
    make install #安装
  7. cd /usr/local/src
    tar -zvxf PHP-7.0.9.tar.gz
    cd PHP-7.0.9
    mkdir -p /usr/local/PHP7 #建立PHP安装目录
./configure --prefix=/usr/local/PHP7 --with-config-file-path=/usr/local/PHP7/etc --enable-MysqLnd  --with-MysqLi=MysqLnd --with-pdo-MysqL=MysqLnd --with-MysqLi=/usr/local/MysqL/bin/MysqL_config --with-MysqL-sock=/tmp/MysqL.sock --with-gd=/usr/local/gd --with-png-dir=/usr/lib --with-jpeg-dir=/usr/lib --with-freetype-dir=/usr/lib --with-iconv --with-zlib --enable-xml --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization  --enable-mbregex --enable-fpm --enable-mbstring --enable-ftp --enable-gd-native-ttf --with-openssl --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --without-pear --with-gettext --enable-session --with-mcrypt --with-curl  --enable-ctype

可以通过./configure -help查看支持的扩展,目前PHP7的configure的参数没有–with-MysqL参数,只支持–with-MysqLi和–with-pdo-MysqL
安装缺少的组件(若没有提示缺少组件,请忽略),如:

yum install libxml2 
yum install libxml2* -y  
yum install openssl-dev
yum install libcurl3-openssl-dev
yum install openssl-devel.i686
yum install openssl-perl.i686
yum install libcurl-devel.i686
yum install libjpeg-turbo-devel.i686
yum install libpng.i686
yum install libpng-devel.i686
yum install freetype-devel
yum install PHP-gd

make #编译
make install #安装
cp PHP.ini-production /usr/local/PHP7/etc/PHP.ini #复制PHP配置文件到安装目录
rm -rf /etc/PHP.ini #删除系统自带配置文件
ln -s /usr/local/PHP7/etc/PHP.ini /etc/PHP.ini #添加链接
cp /usr/local/PHP7/etc/PHP-fpm.conf.default /usr/local/PHP7/etc/PHP-fpm.conf #拷贝模板文件PHP-fpm配置文件
vi /usr/local/PHP7/etc/PHP-fpm.conf #编辑
user = www #设置PHP-fpm运行账号为www
group = www #设置PHP-fpm运行组为www
pid = run/PHP-fpm.pid #取消前面的分号
设置 PHP-fpm开机启动
cp /usr/local/src/PHP-7.0.9/sapi/fpm/init.d.PHP-fpm /etc/rc.d/init.d/PHP-fpm #拷贝PHP-fpm到启动目录
chmod +x /etc/rc.d/init.d/PHP-fpm #添加执行权限
chkconfig PHP-fpm on #设置开机启动
vi /usr/local/PHP7/etc/PHP.ini #编辑配置文件
找到:disable_functions =
修改为:disable_functions = passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname
列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
找到:;date.timezone =
修改为:date.timezone = PRC #设置时区
找到:expose_PHP = On
修改为:expose_PHP = OFF #禁止显示PHP版本的信息
找到:short_open_tag = Off
修改为:short_open_tag = ON #支持PHP标签

8.配置Nginx支持PHP
vi /usr/local/Nginx/conf/Nginx.conf
修改/usr/local/Nginx/conf/Nginx.conf 配置文件,需做如下修改
user www www; #首行user去掉注释,修改Nginx运行组为www www;必须与/usr/local/PHP7/etc/PHP-fpm.conf中的user,group配置相同,否则PHP运行出错
index index.PHP index.html index.htm; #添加index.PHP

pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.PHP$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

/etc/init.d/Nginx restart #重启Nginx

  1. 安装过程可能的错误
    9.1 出错:CMake Error at cmake/boost.cmake:81 (MESSAGE):
    下载 http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
    ,放到/usr/local/boost目录下,然后在cmake后面加选项-DWITH_BOOST=/usr/local/boost
[root@bogon MysqL-5.7.15]#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/MysqL -DMysqL_DATADIR=/data/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMysqL_TCP_PORT=3306 -DMysqL_USER=MysqL -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost

9.2 出错:Curses library not found. Please install appropriate package

– Could NOT find Curses (missing: CURSES_LIBRARY CURSES_INCLUDE_PATH)
CMake Error at cmake/readline.cmake:83 (MESSAGE):
Curses library not found. Please install appropriate package,

remove CMakeCache.txt and rerun cmake.On Debian/Ubuntu,package name is libncurses5-dev,on Redhat and derivates it is ncurses-devel.
Call Stack (most recent call first):
cmake/readline.cmake:118 (FIND_CURSES)
cmake/readline.cmake:214 (MysqL_USE_BUNDLED_READLINE)
CMakeLists.txt:257 (MysqL_CHECK_READLINE)

– Configuring incomplete,errors occurred!

解决办法:

[root@bogon MysqL-5.7.15]# rm -f CMakeCache.txt
yum -y install ncurses-devel

然后再使用cmake编译就可以了.

9.3 ERROR:. No pool defined at least one pool section must be specified in config file
ERROR: Failed to post process the configuration
ERROR: FPM initialization Failed

solution:
在/usr/local/PHP7/etc/PHP-fpm.d目录下
cp www.conf.default www.conf

参考:
http://www.osyunwei.com/archives/5235.html
http://blog.csdn.net/u014595668/article/details/50188127

原文链接:https://www.f2er.com/centos/380667.html

猜你在找的CentOS相关文章