LAMP 编译安装

LAMP 编译安装



LAMP 编译安装


Apache 编译安装
    # yum install zlib-devel expat-devel openssl-devel pcre-devel gcc gcc++    // expat-devel开发库
    # groupadd apache
    # useradd -g apache apache -s /sbin/nologin
    # tar zxf apr-1.7.0.tar.gz
    # cd apr-1.7.0
    # ./configure --prefix=/usr/local/apr
    # make && make install
    # tar zxf apr-util-1.6.1.tar.gz
    # cd apr-util-1.6.1
    # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr       // 需要依赖apr包
    # make && make install
    # tar zxf httpd-2.4.41.tar.gz
    # cd httpd-2.4.41
    # ./configure --prefix=/usr/local/apache --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
    # make && make install                    // 如需要修改主配置文件目录 需加 --sysconf=/etc/httpd
    # /usr/local/apache/bin/apachectl -t      // 检测语法
    # vim /usr/local/apache/conf/httpd.conf   // 编译安装的主配置文件 位置
        ServerName localhost:80               // 添加此行 localhost为主机名 否则会有警告httpd: Could not reliably determine the 
    # /usr/local/apache/bin/apachectl start   //                        ↑ server's fully qualified domain name
    # ss -tnl                                 // 80端口被监控
    # ./apachectl stop
    # vim /etc/init.d/httpd                   // 创建启动脚本
        #!/bin/bash
        # chkconfig: 12345 80 90
        function start_http()
        {
        /usr/local/apache/bin/apachectl  start
        }
        function stop_http()
        {
         /usr/local/apache/bin/apachectl  stop
        }
        case "$1" in
        start)
            start_http
        ;;  
        stop)
            stop_http
        ;;  
        restart)
            stop_http
            start_http
        ;;
        *)
            echo "Usage : start | stop | restart"
        ;;
        esac
    # chmod +x /etc/init.d/httpd
    # chkconfig --add httpd
    # chkconfig httpd on
    # systemctl restart httpd
    # ss -tnl
    # cat /usr/local/apache/build/config.nice      // 查看编译安装时候的参数


PHP 编译安装                           在 php-7.3.11   php-5.6.16 中测试成功
  ❶ PHP以Apache模块的形式安装
    # yum install openssl-devel libxml2-devel bzip2-devel libmcrypt-devel libmcrypt php-mcrypt mcrypt
    # tar xzf php-7.3.11.tar
    # cd php-7.3.11
    # ./configure --prefix=/usr/local/php --with-pdo-mysql --with-openssl --with-mysqli --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt  --with-bz2   
    # make -j4                                  // 以上为编译安装的Aapche  对于yum安装的  见 注解01
    # make install
    # cp /data/soft/php-7.3.11/php.ini-production /etc/php.ini   // 在安装包里拷贝php的配置文件
    # vim /usr/local/apache/conf/httpd.conf                      // 主配置文件 编译安装的目录
        DocumentRoot "/data/www/www.teo1.com"        // 站点目录  中心主机只有一个站点使用 多个站点注释掉 使用虚拟机 详见虚拟机
        AddType application/x-httpd-php .php         // 开启Aapche对php的支持   在全局 添加即可
        AddType application/x-httpd-php-source .phps // 开启Aapche对php的支持
        <Directory "/data/www/www.teo1.com">         // 对/data/www/www.teo1.com/目录的一个权限的设置 指设置web目录的属性
            Options FollowSymLinks                   // Options使用哪些特性  Indexes FollowSymLinks等 见注释1
            AllowOverride None              // 表示禁止用户对目录配置文件(.htaccess进行修改)重载 普通站点不建议开启 All 为允许
            Require all granted             // 允许所有访问   如果要拒绝 详见注解1
        </Directory>
        <IfModule dir_module>
            DirectoryIndex index.php        // 修改主页文件
        </IfModule>
    # vim /data/www/www.teo1.com/index.php  // 创建php测试文件  访问测试
        <?php
           phpinfo();
        ?>
    # /usr/local/apache/bin/apachectl restart
    # ss -tnl
    # vim /data/www/www.teo1.com/index.php     // 创建php访问数据库测试 对于php7.2/3  php5.6
        <?php
            $servername = "127.0.0.1";
            $username = "root";                // 在Mariadb10.4.10中 不能使用root 需要创建测试账户 注解01
            $password = "123456";

            $conn = new mysqli($servername, $username, $password);
            if ($conn->connect_error) {
                die("连接失败: " . $conn->connect_error);
            }

            $sql = "CREATE DATABASE teoDB";
            if ($conn->query($sql) === TRUE) {
                echo "数据库创建成功";
            } else {
                echo "Error creating database: " . $conn->error;
            }

            $conn->close();
        ?>


注:
    php 编译参数 需要替换
        --with-apxs2=/usr/local/apache/bin/apxs           // 以 模块 方式进行安装   编译 安装的 httpd  使用此项
        --with-apxs2=/usr/bin/apxs                        // 以 模块 方式进行安装  yum 安装的 httpd 使用此项
        --enable-maintainer-zts                           // 以 apache 开启 evert或work 模块 上面代码为
        --with-mysql                                      // 如果是 CentOS6 使用此项
        --enable-fpm                                      // 以 fpm 方式进行安装    使用此项
        --disable-fileinfo                                // 1G以下内存要使用此命令编译 不然要报错  上面未添加

        --with-pdo-mysql=/usr/local/mysql                 // 以 编译 安装的 mysql 使用此项 但是实际测试可以不用
        --with-mysqli=/usr/local/mysql/bin/mysql_config   // 以 编译 安装的 mysql 使用此项 但是实际测试可以不用


  ❷ PHP以Apache模块的形式安装
    # yum install openssl-devel libxml2-devel bzip2-devel libmcrypt-devel libmcrypt php-mcrypt mcrypt
    # tar xzf php-7.3.11.tar
    # cd php-7.3.11
    # ./configure --prefix=/usr/local/php --with-pdo-mysql --with-openssl --with-mysqli --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt  --with-bz2  --with-bz2   
    # make -j4                                  // --enable-fpm 开启了fpm  关闭了 apxs2
    # make install
    # cp /data/soft/php-7.3.11/php.ini-production /etc/php.ini                                // 在安装包里拷贝php的配置文件
    # cp /usr/local/php/etc/php-fpm.conf.default  /usr/local/php/etc/php-fpm.conf             // 为php-fpm 提供主配置文件
    # cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf  // 为php-fpm 提供页面配置文件
    # cp /data/soft/php-7.3.11/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm               // 提供php-fpm 启动文件
    # chomd +x /etc/rc.d/init.d/php-fpm
    # chmod +x /etc/rc.d/init.d/php-fpm
    # chkconfig --add php-fpm
    # chkconfig php-fpm on
    # vim /usr/local/php/etc/php-fpm.conf
        pid = /usr/local/php/var/run/php-fpm.pid        // 修改pid文件位置
    # systemctl restart php-fpm                         // 127.0.0.1:9000 被监听    至此php安装完成
    # vim /usr/local/apache/conf/httpd.conf
        DocumentRoot "/data/www/www.teo1.com"
        AddType application/x-httpd-php .php            // 在虚拟主机中设置也一样 加以下三项
        AddType application/x-httpd-php-source .phps
        ProxyRequests Off                               // 需要 关闭正向代理
        ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/www/www.teo1.com/$1  // 把所有.php代理到fcgi接口 跟站点目录
        <Directory "/data/www/www.teo1.com">
            Options FollowSymLinks
            AllowOverride None
            Require all granted
        </Directory>
        <IfModule dir_module>
            DirectoryIndex index.php             // 修改主页文件
        </IfModule>
    # vim /data/www/www.teo1.com/index.php       // 创建php测试文件  访问测试
        <?php
           phpinfo();
        ?>
    # /usr/local/apache/bin/apachectl restart
    # ss -tnl
    # vim /data/www/www.teo1.com/index.php       // 创建php访问数据库测试 对于php7.2/3  php5.6
        <?php
            $servername = "127.0.0.1";
            $username = "root";                  // 在Mariadb10.4.10中 不能使用root 需要创建测试账户 注解01
            $password = "123456";

            $conn = new mysqli($servername, $username, $password);
            if ($conn->connect_error) {
                die("连接失败: " . $conn->connect_error);
            }

            $sql = "CREATE DATABASE teoDB";
            if ($conn->query($sql) === TRUE) {
                echo "数据库创建成功";
            } else {
                echo "Error creating database: " . $conn->error;
            }

            $conn->close();
        ?>


Mysql 编译安装                  // 已测试 Mysql 5.6.47  Mariadb 5.5     Mariadb 10.4.10 会报错先看注释01解决
    # rpm -qa | grep mariadb
    # rpm -qa | grep mysql
    # yum remove mariadb-libs.x86_64
    # yum install openssl-devel libxml2-devel bzip2-devel libmcrypt-devel libmcrypt php-mcrypt mcrypt
    # yum install libarchive-devel boost boost-devel lsof wget gcc gcc-c++ make cmake perl kernel-headers kernel-devel pcre-devel
    # yum install libaio libaio-devel bison bison-devel zlib-devel openssl openssl-devel ncurses ncurses-devel libcurl-devel
    # mkdir -p /data/soft
    # cd /data/soft
    # tar zxf mysql-5.6.47.tar.gz
    # groupadd mysql
    # useradd -g mysql mysql -s /sbin/nologin
    # mkdir -p /data/mysqldb/{3306,innodb,mysql-bin,logs,run,relay-bin}
    # chown -R mysql:mysql /data/mysqldb
    # cd mysql-5.6.47
    # cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/data/mysqldb/run/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_MYISAM_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DMYSQL_DATADIR=/data/mysqldb
    # make
    # make install
    # chown -R root:mysql /usr/local/mysql
    # mkdir /etc/mysql                       // 复制进去my.cnf
    # vim /etc/profile.d/mysql.sh
        export PATH=/usr/local/mysql/bin:$PATH
    # source /etc/profile
    # /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysqldb/3306
    # cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
    # chkconfig --add mysqld
    # chkconfig mysqld on
    # systemctl restart mysqld
    # vim /usr/local/mysql/bin/mysql_secure_installation  // 安全初始化 修改了mysql.sock路径 会提示找不到路径 需要修改此文件
        write_file($config,
            ...
            ...
            "connect-expired-password",                  // 此项去掉 ")" 改成","
            "socket=/data/mysqldb/run/mysql.sock");      // 大概在157行 插入此语句即可
        }
    # mysql                    // 如果提示找不到mysql.sock 可以用-S指明路径 # mysql -S /data/mysqldb/run/mysql.sock
        mysql> use mysql
        mysql> select user,host,password from user;
    # /usr/local/mysql/bin/mysql_secure_installation // 设置密码y 删除匿名用户y 禁止root远程登录n 删除测试数据库y 重载授权表y


 注:

    ❶ 编译安装Mariadb 10.4.10时 会报错的解决方法
        ① 在创建初始数据库时候 /usr/local/mysql/scripts/mysql_install_db --user=mysql  ... ...
                报错 chown: cannot access ‘/auth_pam_tool_dir’: No such file or directory
            # vim /usr/local/mysql/scripts/mysql_install_db                   // 修改此文件
                #chown $user "$pamtooldir/auth_pam_tool_dir" && \             // 大概483行  注释掉即可
                #chmod 0700 "$pamtooldir/auth_pam_tool_dir"                   // 大概484行  注释掉即可
                #chown 0 "$pamtooldir/auth_pam_tool_dir/auth_pam_tool" && \   // 大概493行  注释掉即可
                #chmod 04755 "$pamtooldir/auth_pam_tool_dir/auth_pam_tool"    // 解决此会报下面的错误

        ② 在创建初始数据库时候 /usr/local/mysql/scripts/mysql_install_db --user=mysql  ... ...
                报错 Can't read from messagefile '/usr/local/mysql/share/english/errmsg.sys' // ↓ 在原始包中复制出来即可
            # cp /data/soft/mariadb-10.4.10/sql/share/english/errmsg.sys /usr/local/mysql/share/english/errmsg.sys

        ③ 关于 Mariadb 10.4.10中 php连接测试说明
            # mysql      \\ 由于此版本root用户随便可以登录 使用root账户不好使 因此创建一个测试账户 用于验证PHP连接数据库
                MariaDB [(none)]> grant all privileges on *.* to haha@'%' identified by '123456';
                MariaDB [(none)]> show databases;                      // 查看是否自动创建teodb 所有都可以用此验证

    ❷ mysql源码下载地址
        源码下载地址   https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.47.tar.gz
        二进制下载地址 https://cdn.mysql.com//Downloads/MySQL-5.6/mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
        下载官方网站   https://dev.mysql.com/downloads/mysql/5.6.html









Teo

8条评论

Greta 发布于05:26 - 2021年2月18日

I take pleasure in, cause I discovered exactly what I
used to be having a look for. You have ended my 4 day lengthy hunt!
God Bless you man. Have a nice day. Bye

my web site download rufus.exe for windows 7

preston whorley 发布于09:12 - 2020年12月27日

Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

gary opalicki 发布于06:40 - 2020年12月26日

You made some nice points there. I looked on the internet for the subject matter and found most individuals will agree with your site.

sena angrisano 发布于00:57 - 2020年12月25日

Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

catrice callington 发布于13:46 - 2020年12月24日

Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

newton rappenecker 发布于11:31 - 2020年12月24日

You made some nice points there. I looked on the internet for the subject matter and found most individuals will agree with your site.

teddy begun 发布于11:31 - 2020年12月24日

Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

charlie kinzle 发布于08:21 - 2020年12月24日

Hello! I could have sworn I’ve been to this blog before but after browsing through some of the post I realized it’s new to me. Anyways, I’m definitely happy I found it and I’ll be book-marking and checking back frequently!

You must be logged in to post a comment