CentOS7編譯安裝LAMP(CentOS7、httpd-2.4、php-7.1、mariadb-10.2、memcached-3.0.4) 頂 原

安裝環境說明:

(軟件下載地址在文末附錄)

  1. Linux : CentOS Linux release 7.4.1708 (Core)(最小化安裝)
  2. Apache : httpd-2.4.33.tar.bz2
  3. MariaDB : mariadb-10.2.14-linux-x86_64.tar.gz
  4. PHP : php-7.1.17.tar.bz2
  5. libmemcached : libmemcached-1.0.18.tar.gz
  6. php-memcached : memcached-3.0.4.tgz
  7. apr : apr-1.6.3.tar.gz
  8. apr-util : apr-util-1.6.1.tar.gz

安裝的順序:

Apache --> MariaDB --> PHP

1.配置SELinux,防火牆

禁用SELinux
# vim /etc/selinux/config
    SELINUX=disabled

# setenforce 0

配置防火牆放行http和https
# firewall-cmd --permanent --zone=public --add-service=http
# firewall-cmd --permanent --zone=public --add-service=https
# firewall-cmd --reload

2.配置aliyun Yum源

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

3.安裝開發工具組和依賴包

# yum -y groupinstall "development tools" 
# yum -y install pcre pcre-devel-devel openss-devel expat-devel

4.編譯安裝apr-1.4和apr-1.5

最新版的httpd2.4需要依賴apr-1.4以上版本和apr-1.5以上版本

# tar vxf apr-1.6.3.tar.gz
# cd apr-1.6.3
# ./configure --prefix=/usr/local/apr
# make
# make install

# tar vxf apr-util-1.6.1.tar.gz
# cd apr-util-1.6.1
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make
# make install

5.編譯安裝httpd2.4.33

# tar vxf httpd-2.4.33.tar.bz2
編譯httpd之前把上一步解壓出來的apr和apr-util文件複製到httpd-2.4.33/srclib/文件夾下,再進行httpd編譯
# mv apr-1.6.3 httpd-2.4.33/srclib/apr
# mv apr-util-1.6.1 httpd-2.4.33/srclib/apr-util
# cd httpd-2.4.33
# ./configure --prefix=/usr/local/apache --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
# make
# make install

配置以支持chkconfig控制
# cp /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
# vim /etc/rc.d/init.d/httpd
    在第二行加入如下三行(前面的#號不能省略)
    # Comments to support chkconfig on RedHat Linux
    # chkconfig: 35 85 15
    # description: Apache is a World Wide Web server.

# chkconfig --add httpd
# chkconfig httpd on
# systemctl restart httpd
# vim /etc/profile.d/httpd.sh
    export PATH=$PATH:/usr/local/apache/bin
# source /etc/profile.d/httpd.sh
打開 http://192.168.10.10/ 可以看到httpd已經工作

6.編譯安裝Mariadb10.2.14

解壓安裝並指定解壓路徑/usr/local,創建軟連接
 # tar xvf mariadb-10.2.14-linux-x86_64.tar.gz -C /usr/local
# cd /usr/local
# ln -s mariadb-10.2.14-linux-x86_64/ mysql
創建mysql用戶,並指定家目錄。
# mkdir /mysql
# useradd -r -m -s /sbin/nologin -d /mysql/data mysql
生成mysql數據庫
# /usr/local/mysql/scripts/mysql_install_db --datadir=/mysql/data --basedir=/usr/local/mysql --user=mysql

配置mysql的配置文件
# cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf
# vim /etc/my.cnf     ## 在[mysqld]節點下追加如下三行
    [mysqld]
    datadir = /mysql/data
    innodb_file_per_table = ON
    skip_name_resolve = ON

配置以支持chkconfig控制
# cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld
# chkconfig --add mysqld
# chkconfig mysqld on
# systemctl restart mysqld
執行安全初始化數據庫腳本
# /usr/local/mysql/bin/mysql_secure_installation

# vim /etc/profile.d/mysqld.sh
    export PATH=$PATH:/usr/local/mysql/bin:/usr/local/apache/bin
# source /etc/profile.d/mysqld.sh

7.編譯安裝PHP7.1.17

解決依賴
# yum install -y epel-release
# yum -y install php-mcrypt  libmcrypt  libmcrypt-devel libxml2-devel

編譯安裝
# tar xvf php-7.1.17.tar.bz2
# cd php-7.1.17
# ./configure --prefix=/usr/local/php --enable-mysqlnd --with-mysqli=mysqlnd --with-openssl --with-pdo-mysql=mysqlnd --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-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-maintainer-zts --disable-fileinfo
注意: php-7.0以上版本使用 –enable-mysqlnd –with-mysqli=mysqlnd ,原–with-mysql不再支持
# make
# make install

提供php配置文件
# cp php.ini-production /etc/php.ini

編輯apache配置文件httpd.conf,以使apache支持php
# vim /usr/local/apache/conf/httpd.conf
    添加如下兩行
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
    找到如下行並追加index.php 結果如下
    DirectoryIndex index.html index.php

重啓httpd服務以使配置生效
# systemctl restart httpd

測試httpd、mariadb、php是否能夠協同工作
# rm -rf /usr/local/apache/htdocs/index.html
# vim /usr/local/apache/htdocs/index.php
        <?php
            $mysqli=new mysqli("localhost","root","123456");
            if(mysqli_connect_errno()){
                echo "連接數據庫失敗!";
                $mysqli=null;
                exit;
            }
                echo "連接數據庫成功!";
                $mysqli->close();
        ?>
打開http://192.168.10.10/ 能看到"連接數據庫成功!"即可,否則請檢查錯誤。

8.編譯安裝php-memcached擴展

最新版Xcache3.2最高只支持到PHP 5.6,所以PHP7不在支持列表裏,我以這裏我們使用php-memcached來提供緩存功能

編譯安裝libmemcached
# yum -y install cyrus-sasl-devel
# wget  https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
# cd libmemcached-1.0.18
# ./configure --prefix=/usr/local/libmemcached --with-memcached --enable-sasl
# make
# make install

編譯安裝php-memcached
# tar xvf memcached-3.0.4.tgz
# cd memcached-3.0.4
# /usr/local/php/bin/phpize
        Configuring for:
        PHP Api Version:         20160303
        Zend Module Api No:      20160303
        Zend Extension Api No:   320160303
# ./configure --with-php-config=/usr/local/php/bin/php-config  --with-libmemcached-dir=/usr/local/libmemcached --enable-memcached
# make 
# make install
# echo "extension=memcached.so" >> /etc/php.ini
# systemctl restart httpd

附錄:軟件下載地址

  1. CentOS 7.4.1708 : http://mirrors.sohu.com/centos/7/isos/x86_64/CentOS-7-x86_64-DVD-1708.iso
  2. httpd-2.4.33.tar.bz2 : http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.33.tar.bz2
  3. mariadb-10.2.14-linux-x86_64.tar.gz : https://downloads.mariadb.org/interstitial/mariadb-10.2.14/bintar-linux-x86_64/mariadb-10.2.14-linux-x86_64.tar.gz
  4. php-7.1.17.tar.bz2 : http://cn2.php.net/get/php-7.1.17.tar.bz2/from/this/mirror
  5. libmemcached-1.0.18.tar.gz : https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
  6. memcached-3.0.4.tgz : http://pecl.php.net/get/memcached-3.0.4.tgz
  7. apr-1.6.3.tar.gz : http://mirrors.shu.edu.cn/apache//apr/apr-1.6.3.tar.gz
  8. apr-util-1.6.1.tar.gz : http://mirrors.shu.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章