CentOS 7下源码编译配置 Apache2.4+MySQL5.6+PHP7.1

yum -y installmake gcc-c++ cmake bison-devel  ncurses-devel gcc\
autoconf automake zlib* fiex* libxml* libmcrypt* libtool-ltdl-devel*

下载mysql5.6

wget  
tarxvf mysql-5.6.16.tar.gz 
cd mysql-5.6.16 

编译源码:

新建下目录:

mkdir /usr/local/mysql 
mkdir /data/mysql/data 

配置一些信息:

cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\
-DMYSQL_DATADIR=/data/mysql/data\
-DSYSCONFDIR=/etc\
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_MEMORY_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysql/mysql.sock \
-DMYSQL_TCP_PORT=3306 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DEXTRA_CHARSETS=all \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci

看到最后输出:Build files have been written to:xxxxxxx证明编译成功

编译源码:

make && make install(备注:编译时间比较慢,耐心等待...)

修改文件权限:

groupadd mysql
useradd -r -g mysql mysql
cd /usr/local/mysql
chown -R mysql:mysql .
scripts/mysql_install_db --user=mysql --ldata=/data/mysql/data
chown -R root .
chown -R mysql data

设置配置文件:

vim /etc/my.cnf

配置如下:

[client]
port=3306
socket=/tmp/mysql.sock

[mysqld]
port=3306
bind-address=127.0.0.1
basedir=/usr/local/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

############# default settings ################
# time zone
default-time-zone = system
character-set-server = utf8
default-storage-engine = InnoDB

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

启动Mysql:

cd /usr/local/mysql/support-files
./mysql.server start

设置开机启动:

chkconfig --add mysql
##有的系统需要下面的
chkconfig --level 345 mysql on

文件目录

/data/mysql/data  //存储数据表目录

/etc/my.cnf    //mysql 配置文件

/usr/local/mysql  //mysql安装目录

/usr/local/mysql/bin/mysql -u 账户 -p 密码  //登录到mysql

/usr/local/mysql/support-files/mysql.server start|stop|restart  //启动暂停重启

2:安装Apache:

这里选用Apache2.4版本。

Apache2.4依赖包:

apr-1.46.tar.gz    下载:wget

apr-util-1.5.1.tar.gz  下载:wget

pcre-8.32.tar.gz    下载:wget https://ftp.pcre.org/pub/pcre/pcre-8.32.tar.gz

apache2.4 下载:wget

安装apr:

#tar -zxvf apr-1.46.tar.gz
#cd apr-1.46
#./configure --prefix=/usr/local/apr
#make
#make install

安装apr-util:

#tar -zxvf apr-util-1.5.1.tar.gz
#cd apr-util-1.5.1
#./configure --with-apr=/usr/local/apr
#make
#make install

安装pcre:

#tar -zxvf pcre-8.32.tar.gz
#cd  pcre-8.32
#./configure --prefix=/usr/local/pcre(此处出现configure: error: You need a C++ compiler for C++ support
#sudo apt-get install g++)
#make
#make install

安装apache2.4:

#tar -zxvf httpd-2.4.4.tar.gz
#cd httpd-2.4.4
#./configure --prefix=/usr/local/apache --enable-so --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr/ --with-pcre=/usr/local/pcre/
#make
#make install

配置文件:

vim /usr/local/apache/conf/httpd.conf
在“#ServerName :80”下面添加一行如下:
ServerName localhost:80

启动服务:

usr/local/apache/bin/apachectl start

浏览器输入localhost,显示"It works!"

(注:实体机不能访问虚拟机web服务器,可以输入 /sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT(将此处的80改为自己的web服务器的端口号))

3:安装PHP7:

php-7.1.2.tar.gz:下载:wget

安装php:

#tar zxvf php-7.1.2.tar.gz
#cd php-7.1.2
#./configure --prefix=/usr/local/php7 \
 --with-apxs2=/usr/local/apache2/bin/apxs \
 --with-curl \
 --with-freetype-dir \
 --with-gd \
 --with-gettext \
 --with-iconv-dir \
 --with-kerberos \
 --with-libdir=lib64 \
 --with-libxml-dir \
 --with-mysqli \
 --with-openssl \
 --with-pcre-regex \
 --with-pdo-mysql \
 --with-pdo-sqlite \
 --with-pear \
 --with-png-dir \
 --with-xmlrpc \
 --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
#make
#make install

最后到php的解压目录复制一下php的配置文件

#cp php.ini-development /usr/local/php/lib/php.ini 

重启Apache服务,然后写一个简单的检测文件吧。

<?php
    phpinfo();
?>

把PHP加入环境变量

#vim /etc/profile

在文件末尾加上如下两行代码

PATH=$PATH:/usr/local/php7/bin 
export PATH

然后执行命令 #source /etc/profile 或执行点命令 #./profile 使其修改生效,执行完可通过 #echo $PATH命令查看是否添加成功

更多Apache相关教程见以下内容

CentOS6.8编译安装Apache2.4.25、MySQL5.7.16、PHP5.6.29 

CentOS 6.6下安装Apache 2.2.31

Apache 配置多站点访问及二级域名配置 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/df4f4fbab05c5471156d85bc3140950f.html