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

猜你喜欢

转载自blog.51cto.com/13689359/2323427
今日推荐