Centos7 編譯安裝搭建LAMP平臺

一、編譯安裝mysql

安裝依賴包與工具

# yum install  -y gcc gcc-c++ ncurses-devel perl 
# yum install  -y cmake

下載mysql安裝包

# wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.62.tar.gz

安裝前準備

# groupadd mysql  
# useradd  -g mysql mysql
# mkdir -p /data/mysql
# chown -R mysql:mysql /data/mysql

編譯安裝mysql

# tar -zxv -f mysql-5.5.62.tar.gz
#cd mysql-5.5.62
#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql
#make && make install 

修改權限

# chown -R mysql.mysql /usr/local/mysql

初始化mysql數據庫

# /usr/local/mysql scripts/mysql_install_db --user=mysql --datadir=/data/mysql

複製mysql服務啓動配置文件和腳本

# cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
# cp support-files/mysql.server /etc/init.d/mysqld
# vi /etc/rc.d/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql

啓動mysql服務

# service mysqld start 
    或者 
#systemctl start mysqld     (完成上述配置後重載系統管理器# systemctl daemon-reload 可直接使用systemctl命令)

檢查登錄

# mysql -uroot -p

二、編譯安裝httpd

準備安裝包

# wget http://mirrors.sohu.com/apache/httpd-2.4.37.tar.gz
# tar -xzf httpd-2.4.37.tar.gz
# cd httpd-2.4.37

安裝依賴包

 # yum install -y pcre* apr*

編譯安裝httpd

# ./configure --prefix=/usr/local/httpd     
# make && make install

編輯啓動文件

# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd

重載系統管理器

# systemctl daemon-reload

啓動服務

# systemctl start httpd

編輯配置文件

# vi /usr/local/httpd/conf/httpd.conf
#  ln -s /usr/local/httpd/conf/httpd.conf /etc/    (配置文件軟連接映射到/etc下面)

測試

# vim /usr/local/httpd/htdocs/index.html 
<html><body><h1>It works!</h1></body></html>
<html><head><h1>Good boy!</h1></head></html>
# systemctl start httpd

三、編譯安裝PHP

準備安裝包

# wget http://mirrors.sohu.com/php/php-7.2.5.tar.gz
# tar -xzf php-7.2.5.tar.gz
# cd php-7.2.5

安裝依賴包

# yum install bzip2-devel.x86_64  openssl* libxml2*

編譯安裝PHP

# ./configure 
    --prefix=/usr/local/php 
    --with-mysqli=mysqlnd                   ##mysql支持
    --with-pdo-mysql=mysqlnd 
    --with-openssl 
    --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/httpd/bin/apxs   ##httpd支持
    --with-config-file-path=/etc        ##php.ini 配置文件路徑
    --with-config-file-scan-dir=/etc/php.d 
    --with-bz2  
    --enable-maintainer-zts

拷貝配置文件(位於解壓的包)

# cp /wh_k/php-7.2.5/php.ini-production /etc/php.ini

配置文件httpd.conf支持php

 # vim /etc/httpd.conf

在 LoadModule php7_module modules/libphp7.so後面添加:

   AddType application/x-httpd-php  .php
   AddType application/x-httpd-php-source  .phps

修改DirectoryIndex index.html爲:

  DirectoryIndex index.php index.html

添加測試頁面

# vim /usr/local/httpd/htdocs/index.php

<?php
    phpinfo();
?>

重啓httpd服務測試

# systemctl restart httpd
http://192.168.61.130/index.php

測試mysql支持

添加mysql用戶

 mysql> grant all on mysql.* to 'mysql'@'localhost' identified by 'redhat';
 mysql> flush privileges;

配置測試頁面

    # vim /usr/local/httpd/htdocs/test.php
  <?php
         $log_in = mysqli_connect('127.0.0.1','mysql','redhat');
                if ($log_in)
                      echo "Success.You are so good!";
                else
                      echo "Failure.You are so bad!";
   ?>

重啓httpd服務測試

# systemctl restart httpd
http://192.168.61.130/test.php
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章