centos7.0 lamp mysql_centos7 编译安装lamp php-7.1.0 +mysql-5.7.16 + httpd-2.4.23

本文详细介绍了在CentOS7.0系统上手动编译安装LAMP环境的过程,包括关闭系统防火墙和SElinux,下载并安装MySQL、PHP和Apache的源码包,以及相关依赖。整个流程包括系统限制配置、软件源码安装、编译器和依赖安装、MySQL的编译安装、Apache的编译安装和PHP的编译安装,最后进行PHP配置及HTTPD配置,确保环境正常运行。
摘要由CSDN通过智能技术生成

系统:centos7

软件版本:php-7.1.0 +mysql-boost-5.7.16 + httpd-2.4.23

一、linux 系统限制配置

1、关闭系统防火墙systemctl stop firewalld.service 关闭防火墙

systemctl disable firewalld.service  禁用防火墙

2、关闭SElinuxsed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config

setenforce 0 selinux 立即生效

二、系统安装约定

软件源代码包存放位置:/usr/local/src

源码包编译安装位置:/usr/local/软件名字

三、现在源码安装包

1、下载mysql-boost-5.7.16wget -P /usr/local/src http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-boost-5.7.16.tar.gz

2、下载php-7.1.0wget -P /usr/local/src http://cn2.php.net/distributions/php-7.1.0.tar.gz

3、下载httpd-2.4.23wget -P /usr/local/src http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.23.tar.gz

4、下载 libmemcached-1.0.18wget -P /usr/local/src https://launchpadlibrarian.net/165454254/libmemcached-1.0.18.tar.gz

5、下载apr-util-1.5.4wget -P /usr/local/src http://apache.fayea.com//apr/apr-util-1.5.4.tar.gz

6、下载apr-1.5.2wget -P /usr/local/src http://apache.fayea.com//apr/apr-1.5.2.tar.gz

7、下载/pcre-8.39wget -P /usr/local/src https://nchc.dl.sourceforge.net/project/pcre/pcre/8.39/pcre-8.39.tar.gz

8、下载apr-iconv-1.2.1wget -P /usr/local/src http://apache.fayea.com//apr/apr-iconv-1.2.1.tar.gz

9、下载php-memcachedyum -y install git

cd /usr/local/src

git clone -b php7 https://github.com/php-memcached-dev/php-memcached.git

四、安装编译器及依赖yum -y install epel-release

yum -y install patch gcc gcc-c++  readline-devel zlib-devel libffi-devel \

openssl openssl-devel make autoconf automake libtool bison libxml2 \

libxml2-devel libxslt-devel libyaml-devel  python  python-docutils \

cmake imake expat-devel libaio libaio-devel bzr ncurses-devel wget \

libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel  \

pcre-devel curl-devel libmcrypt libmcrypt-devel uuid-devel

五、安装编译MySQL-5.16

1、生成MySQL编译脚本vim mysql_install.sh#!/bin/bash

#mysql安装脚本

DBDIR='/data/mysql' #mysql 数据路径

MYSQLDIR='/usr/local/mysql' # mysql 安装路径

PASSWD='123456' # MySQL root登陆密码

[ -d $DBDIR ] || mkdir $DBDIR -p

id mysql &> /dev/null

if [ $? -ne 0 ];then

useradd mysql -s /sbin/nologin -M

fi

chown -R mysql:mysql $DBDIR

cd /usr/local/src

tar -xvf mysql-boost-5.7.16.tar.gz

cd mysql-5.7.16

cmake . -DCMAKE_INSTALL_PREFIX=$MYSQLDIR \

-DMYSQL_DATADIR=$DBDIR \

-DSYSCONFDIR=/etc \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_ARCHIVE_STORAGE_ENGINE=1 \

-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DWITH_LIBWRAP=0 \

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \

-DWITH_SSL=system \

-DWITH_ZLIB=system \

-DWITH_BOOST=/usr/local/src/mysql-5.7.16/boost/boost_1_59_0 \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci

if [ $? != 0 ];then

echo "cmake error!"

exit 1

fi

make && make install

if [ $? -ne 0 ];then

echo "install mysql is failed!" && /bin/false

fi

sleep 2

chown -R mysql:mysql $MYSQLDIR

chown -R root:root $MYSQLDIR

cp $MYSQLDIR/support-files/my-default.cnf /etc/my.cnf

echo export PATH=$PATH:$MYSQLDIR/bin:$MYSQLDIR/lib >>/etc/profile

source /etc/profile

cat >>  /etc/my.cnf <

character_set_server = utf8

basedir = $MYSQLDIR

datadir = $DBDIR

port = 3306

server_id = 1

socket = /tmp/mysql.sock

explicit_defaults_for_timestamp=true

EOF

sed -i 's/sql_mode=.*/sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER/g' /etc/my.cnf

source /etc/profile

sleep 5

cd $MYSQLDIR

cp support-files/mysql.server /etc/init.d/mysqld

chmod 700 /etc/init.d/mysqld

mysql_ssl_rsa_setup

rm -rf /data/mysql

mysqld --initialize --user=mysql

if [ $? -ne 0 ];then

echo "install mysql is failed!" && /bin/false

fi

#/etc/init.d/mysqld stop

mysqld_safe --user=mysql --skip-grant-tables --skip-networking &

sleep 5

echo "update user set authentication_string=Password('$PASSWD') where user='root'; flush privileges;" | mysql mysql

echo "set password=Password('$PASSWD'); flush privileges;" | mysql -u root -p$PASSWD --connect-expired-password

sleep 5

echo "GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY '$PASSWD'; FLUSH PRIVILEGES; " | mysql -u root -p$PASSWD

/etc/init.d/mysqld restart

if [ $? -ne 0 ];then

echo "install mysql is failed!" && /bin/false

fi

IDSO=`cat /etc/ld.so.conf| grep /usr/local/lib64 | wc -l `

if [ $IDSO -eq 0 ];then

echo "/usr/local/lib64" >> /etc/ld.so.conf

ldconfig

fi

chkconfig mysqld on

2、给mysql_install.sh  可执行权限chmod +x mysql_install.sh

3、编译安装MySQL./mysql_install.sh

六、编译安装httpd-2.4.23 及依赖

1、安装apr-1.5.2cd /usr/local/src

解压apr-1.5.2.tar.gz

tar -zxvf apr-1.5.2.tar.gz

cd apr-1.5.2

修改configure 不修改编译会报错

sed -i 's/$RM "$cfgfile"/#$RM "$cfgfile"/g' ./configure

编译 apr-1.5.2

./configure --prefix=/usr/local/apr

make && make install

2、安装apr-iconv-1.2.1cd /usr/local/src

解压 apr-iconv-1.2.1.tar.gz

tar -zxvf apr-iconv-1.2.1.tar.gz

编译

cd apr-iconv-1.2.1

./configure --prefix=/usr/local/apr-iconv \

--with-apr=/usr/local/apr

make && make install

3、安装apr-util-1.5.4cd /usr/local/src

解压apr-util-1.5.4.tar.gz

tar -zxvf apr-util-1.5.4.tar.gz

编译

cd apr-util-1.5.4

./configure --prefix=/usr/local/apr-util \

--with-apr=/usr/local/apr \

--with-apr-iconv=/usr/local/apr-iconv/bin/apriconv

make && make install

4、安装pcre-8.39cd /usr/local/src

解压pcre-8.39.tar.gz

tar -xvf pcre-8.39.tar.gz

cd /usr/local/src/pcre-8.39

编译

./configure  --prefix=/usr/local/pcre

make && make install

5、安装httpd-2.4.23创建 apache

useradd  apache -s /sbin/nologin -M

cd /usr/local/src

解压httpd-2.4.23.tar.gz

tar -zxvf httpd-2.4.23.tar.gz

编译

cd httpd-2.4.23

./configure --with-apr=/usr/local/apr \

--with-apr-util=/usr/local/apr-util \

--with-pcre=/usr/local/pcre \

--prefix=/usr/local/apache  \

--sysconfdir=/etc/httpd \

--enable-so  \

--enable-ssl \

--enable-cgi \

--enable-rewrite \

--with-zlib  \

--with-pcre  \

--with-mpm=prefork \

--enable-modules=most \

--enable-mpms-shared=all

make && make install

创建配置文件夹

mkdir -p /usr/local/apache/conf.d

给web页面存放目录apache用户读写权限

chown -R apache:apache /usr/local/apache/htdocs/

七、安装php

1、安装php-7.1.0cd /usr/local/src

解压php-7.1.0.tar.gz

tar -xzvf php-7.1.0.tar.gz

编译

cd ./php-7.1.0

./configure \

--prefix=/usr/local/php7 \

--exec-prefix=/usr/local/php7 \

--with-config-file-path=/usr/local/php7/etc \

--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 \

--with-zlib-dir \

--with-mhash \

--with-mcrypt \

--with-openssl-dir \

--with-jpeg-dir \

--with-apxs2=/usr/local/apache/bin/apxs \ #apache安装路径

--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

# --enable-gd-jis-conv \ #php画图中文会出现乱码

make && make install

2、安装libmemcached-1.0.18cd /usr/local/src

解压libmemcached-1.0.18.tar.gz

tar -zxvf libmemcached-1.0.18.tar.gz

编译

cd ./libmemcached-1.0.18

./configure --prefix=/usr/local/libmemcached

make && make install

3、安装php-memcachedcd /usr/local/src/php-memcached

生成编译配置

/usr/local/php7/bin/phpize

编译

./configure --with-libmemcached-dir=/usr/local/libmemcached \

--with-php-config=/usr/local/php7/bin/php-config \

--disable-memcached-sasl

make && make install

编译完成记录生成的路径

Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/

八、配置PHP及HTTPDcd /usr/local/src/php-7.1.0

cp php.ini-production /usr/local/php7/etc/php.ini

cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf

cp /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php-fpm.d/www.conf

配置PHP时区

cat >> /usr/local/php7/etc/php.ini<

soap.wsdl_cache_enabled=1

max_input_time = 600

max_execution_time = 300

date.timezone = Asia/Shanghai

post_max_size = 32M

memory_limit = 128M

mbstring.func_overload = 1

extension=/usr/local/php7/lib/php/extensions/no-debug-non-zts-20160303/memcached.so

EOF

配置httpd 端口

sed -i 's/#ServerName www.example.com:80/ServerName localhost:80/g' /etc/httpd/httpd.conf

配置http支持php

cat >> /etc/httpd/httpd.conf <

SetHandler application/x-httpd-php

EOF

sed -i 's/DirectoryIndex.*/DirectoryIndex index.php  index.html/g' /etc/httpd/httpd.conf

sed -i "s/User daemon/User apache/g"  /etc/httpd/httpd.conf

sed -i "s/Group daemon/Group apache/g"  /etc/httpd/httpd.conf

拷贝http启动脚本

cp -rf /usr/local/apache/bin/apachectl /etc/init.d/httpd

chmod +x /etc/init.d/httpd

让启动脚本可以添加为系统开机启动

sed -i "2 a#chkconfig: 2345 10 90" /etc/init.d/httpd

sed -i "3 a#description: Activates/Deactivates Apache Web Server" /etc/init.d/httpd

设置开机启动

chkconfig httpd on

生成php测试页

cat >/usr/local/apache/htdocs/index.php <

phpinfo();

?>

EOF

启动httpd

service httpd start

2f0bb09fc7d1e6c20c925a3e4912a663.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值