zoukankan      html  css  js  c++  java
  • linux下PHP7环境搭建

    LAMP环境版本

    • 操作系统:Centos 7
    • Mysql:5.7.11
    • Apache:2.4.18
    • PHP:7.0.4
     
     

    安装Mysql

     
     
     

    为mysql创建专属帐号

    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. shell> groupadd mysql  
    2. shell> useradd -r -g mysql -s /bin/false mysql  
     

    源码编译安装

    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. shell> tar zxvf mysql-5.7.11.tar.gz  
    2. shell> cd mysql-5.7.11  
    3. shell> cmake .  
    4. shell> make  
    5. shell> make install  

    安装后设置

    注意:从Mysql5.7开始,mysql默认安装后不再是空密码,而是生成一个随机密码,除非初始化时指定--initialize-insecure。
    所有用户拥有对于MySQL默认安装test数据库的访问权限(即使没有授予权限)为了安全考虑5.7版本中不在有test数据库。
    更为重要的是,MySQL 5.7版本提供了更为简单SSL安全访问配置,并且默认连接就采用SSL的加密方式
     
    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. shell> cd /usr/local/mysql  
    2. shell> chown -R mysql .  #修改目录所有者为mysql  
    3. shell> chgrp -R mysql .  #修改目录所属组为mysql  
    4. shell> bin/mysqld --initialize-insecure --user=mysql --datadir=/data/mysql  #初始化mysql,初始化为空,数据库存放目录指定为/data/mysql  
    5. shell> bin/mysql_ssl_rsa_setup #启动ssl加密方式连接  
    6. shell> chown -R root .   #修改目录所有者为root  
    7. shell> chown -R mysql /data/mysql  #修改数据库目录所有者为mysql  

    安装mysql服务

    只需要将mysql安装目录下的mysql.server复制过去就OK了。
    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. shell> cp support-files/mysql.server /etc/init.d/mysql.server  
    2. shell> service mysql start   #启动服务  


    安装Apache

     
     
     

    源码编译安装

     
    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. shell> ./configure --prefix=/usr/local/apahche   
    2. --enable-so #动态共享对象,可实现模块动态生效   
    3. --enable-rewrite #启用Rewrite功能   
    4. --enable-ssl #支持SSL/TLS,可以实现https访问   
    5. --enable-deflate #支持压缩   
    6. shell> make  
    7. shell> make install  


    apache的启动与关闭

     
    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. shell> /usr/local/apache/bin/apachectl start    #启动  
    2. shell> /usr/local/apache/bin/apachectl stop     #停止  
    3. shell> /usr/local/apache/bin/apachectl restart  #重启  

    将apache添加到Linux的服务并设置自启动

     
    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. shell> cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd   #设置为系统服务  
    2. shell> ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/S80httpd   #在启动级别3中自启动  
    3. shell> service httpd restart   #通过服务来重启apache  
     

    运行测试页面

     
    在客户端浏览器上输入服务器的IP地址,看是否能正常打开网页。
     
     
     

    常见问题

    • configure: error: APR not found.
      解决方法: 安装对应依赖库
      [plain] view plain copy
       
       在CODE上查看代码片派生到我的代码片
      1. shell> yum install apr apr-util-devel  
    • configure: error: pcre-config for libpcre not found.
      解决方法:安装对应依赖库
      [plain] view plain copy
       
       在CODE上查看代码片派生到我的代码片
      1. yum install pcre pcre-devel  
    • 启动apache时报:AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.44.13.173. Set the 'ServerName' directive globally to suppress this message
      解决方法:修改配置文件httpd.conf设置ServerName localhost:80
     

    安装PHP

     
     

    安装依赖库

     
    • zlib
       
      [plain] view plain copy
       
       在CODE上查看代码片派生到我的代码片
      1. shell> tar xf zlib.1.2.8.tar.gz  
      2. shell> cd zlib.1.2.8  
      3. shell> ./configure  
      4. shell> make test  
      5. shell> make install  
    • GD库
       
      libpng
      [plain] view plain copy
       
       在CODE上查看代码片派生到我的代码片
      1. shell> tar xf libpng-1.6.21  
      2. shell> cd libpng-1.6.21  
      3. shell> ./configure --prefix=/usr/local/libpng  
      4. shell> make  
      5. shell> make check  
      6. shell> make install  
      jpeg
      [php] view plain copy
       
       在CODE上查看代码片派生到我的代码片
      1. shell> tar xf jpegsrc.v9.tar.gz  
      2. shell> cd jpeg-9  
      3. shell> ./configure --prefix=/usr/local/libjpeg  
      4. shell> make  
      5. shell> make install  
    • libcurl-devel
      [plain] view plain copy
       
       在CODE上查看代码片派生到我的代码片
      1. yum install libcurl-devel  
    • openssl-devel
      [plain] view plain copy
       
       在CODE上查看代码片派生到我的代码片
      1. yum install openssl-devel  


    • libxslt-devel
      [plain] view plain copy
       
       在CODE上查看代码片派生到我的代码片
      1. yum install libxslt-devel  


    • libxml2-devel
      [plain] view plain copy
       
       在CODE上查看代码片派生到我的代码片
      1. yum install libxml2-devel  


    • freetype 字体操作库
      [plain] view plain copy
       
       在CODE上查看代码片派生到我的代码片
      1. shell> tar xf freetype-2.6.3.tar.bz2  
      2. shell> sh autogen.sh  
      3. shell> ./configure --prefix=/usr/local/freetype  
      4. shell> make  
      5. shell> make install  


    编译安装PHP

    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. ./configure --prefix=/usr/local/php   
    2.  --with-apxs2=/usr/local/apache/bin/apxs   
    3.  --with-curl   
    4.  --with-freetype-dir=/usr/local/freetype   
    5.  --with-gd   
    6.  --with-gettext   
    7.  --with-iconv-dir   
    8.  --with-mysqli   
    9.  --with-openssl   
    10.  --with-pcre-regex   
    11.  --with-pdo-mysql   
    12.  --with-pdo-sqlite   
    13.  --with-pear   
    14.  --with-png-dir=/usr/local/libpng   
    15.  --with-jpeg-dir=/usr/local/libjpeg   
    16.  --with-xsl   
    17.  --with-zlib   
    18.  --enable-fpm   
    19.  --enable-bcmath   
    20.  --enable-libxml   
    21.  --enable-inline-optimization   
    22.  --enable-gd-native-ttf   
    23.  --enable-mbregex   
    24.  --enable-mbstring   
    25.  --enable-opcache   
    26.  --enable-pcntl   
    27.  --enable-shmop   
    28.  --enable-soap   
    29.  --enable-sockets   
    30.  --enable-sysvsem   
    31.  --enable-xml   
    32.  --enable-zip  
    33. (./configure  '--prefix=/usr/local/php' '--with-freetype-dir=/usr/local/freetype' '--with-gd' '--with-gettext' '--with-iconv-dir' '--with-mysqli' '--with-openssl' '--with-pcre-regex' '--with-pdo-mysql' '--with-pdo-sqlite' '--with-pear' '--with-png-dir=/usr/local/libpng' '--with-jpeg-dir=/usr/local/libjpeg' '--with-xsl' '--with-zlib' '--enable-fpm' '--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-xml' '--enable-zip' '--with-curl=/usr/local/curl')指定curl为openssl
    34.   
    35. shell> make  
    36. shell> make install  
     
    Apache与PHP的关联
    PHP安装成功后会在apache的modules目录下生成一个libphp.so动态库文件,在apache的配置文件httpd.conf里自动增加一行
    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. LoadModule php7_module        modules/libphp7.so  
     
    在Apache的配置文件httpd.conf的<IfModule mime_module></IfModule>块里增加一行
    [plain] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. AddType application/x-httpd-php .php  
    在网站要目录/usr/local/htdocs里增加一个index.php测试文件内容如下:
    [php] view plain copy
     
     在CODE上查看代码片派生到我的代码片
    1. <?php  
    2. phpinfo();  
    然后我们运行此文件,如果输出了phpinfo信息,证明我们安装成功。
  • 相关阅读:
    快速开发一个自己的微信小程序
    ES6系列汇总
    数组、Set对象的互相转换
    CORS 跨域
    模板引擎之hogan.js
    Flex 布局语法教程
    ES6 Javascript 实用开发技巧
    几种知名开源富文本编辑器对比
    python 字符串的一些操作
    python os模块一些常用操作
  • 原文地址:https://www.cnblogs.com/grimm/p/5643801.html
Copyright © 2011-2022 走看看