CentOS8 源码编译安装 lamp环境 (apache24 + php7.3 + mysql57)

CentOS8 安装 apache24 + php7.3 + mysql57

前期准备:
close selinux (关闭SELinux)
vi /etc/selinux/config
查找 : SELINUX=enforcing
修改成 : SELINUX=disabled
 

1.apache24 安装

1) install rely (依赖安装)

dnf install -y apr* gcc gcc-c++ pcre-devel zlib-devel redhat-rpm-config

2) download (下载)

wget http://mirror.bit.edu.cn/apache/httpd/httpd-2.4.39.tar.gz

3) unzip (解压并安装)

a) tar xvf httpd-2.4.39.tar.gz >> /dev/null
b) cd httpd-2.4.39
c) ./configure --prefix=/application/apache24 \
--enable-deflate --enable-expires \
--enable-headers --enable-modules=most \
--enable-so --with-mpm=worker \
--enable-rewrite && make -j12 && make install

4) start apache (启动)

/application/apache24/bin/apachectl start


5) open 80 port (添加80端口,防火墙)

a) firewall-cmd --permanent --add-port=80/tcp (添加80端口)
b) firewall-cmd --reload (重启防火墙)

6) 创建apache的进程守护者

useradd -M -s /sbin/nologin apache

参数注解:

./configure 预编译 -> 生成MakeFile文件
--prefix=/application/apache2.4.39 指定apache的安装目录
--enable-deflate 提供对内容的压缩传输编码的支持(html js css) 提高传输速率 生产环境必用的一个参数
--enable-expires 激活允许通过配置文件控制http的 ‘expires’ 和 ‘cache-control’头内容
--enable-headers 提供允许对http请求头的控制 (http1.0 和 1.1)
--enable-modules=most 激活大多数模块
--enable-so 
--with-mpm=worker 工作运行具备的两种模式rworke /prefork
--enable-rewrite 开启url重写

 

2.mysql57安装

1) install rely (安装依赖包)

a. dnf install -y cmake bison ncurses-devel libtirpc-devel
b. rpcsvc-proto
mwget https://github.com/thkukuk/rpcsvc-proto/releases/download/v1.4/rpcsvc-proto-1.4.tar.gz
tar xf rpcsvc-proto-1.4.tar.gz
cd rpcsvc-proto-1.4/
./configure && make -j12 && make install

2) download (下载)

wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.27.tar.gz
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-boost-5.7.27.tar.gz

3) unzip (解压)

tar xf mysql-boost-5.7.27.tar.gz
tar xf mysql-5.7.27.tar.gz
cd mysql-5.7.27

4) 编译并安装 (注意: 编译过程会消耗大量内存,请确保内存足够大, 如果内存不够,去掉参数 -j12 即可)

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DSYSCONFDIR=/usr/local/mysql/etc \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DMYSQL_TCP_PORT=3306 \
-DEFAULT_CHARSET=utf8 \
-DEFAULT_COLLATION=utf8_general_ci \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DWITH_BOOST=./boost && make -j12 && make install

5) create mysql user (创建mysql用户)

useradd -M -s /sbin/nologin mysql

6) init mysql db (初始化数据库, 编写配置文件并且删除centos8系统自带的配置文件)

a) cd /usr/local/mysql
b) 初始化数据库
bin/mysqld --initialize \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data \
--user=mysql 
c) 删除centos8自带的配置文件 (不删除会导致mysql启动失败,除非做相应配置)
rm -rf /etc/my.cnf 
d) vi etc/my.cnf
[mysqld]
user = mysql
port = 3306
bind-address = 0.0.0.0
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /tmp/mysql.sock
pid-file = /usr/local/mysql/mysqld.pid
character-set-server = utf8
collation-server = utf8_general_ci
max_connections = 1024
log-error = /var/log/mysqld.log
default-time_zone = '+8:00'
# skip-grant-tables
e) 修改mysql安装程序的所属者为mysql
chown mysql:mysql -R . 

7) firewall防火墙配置 (此过程不做描述,同apache)

a) firewall-cmd --permanent --add-port=3306/tcp
b) firewall-cmd --reload

8) systemctl工具启动 (此方法不知道为什么apache启动总是失败,如果有知道的小伙伴可以留言告诉我)

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
systemctl daemon-reload
systemctl start mysqld // 启动mysql

9) path环境变量

vi /etc/profile

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

3.php7.3 

1) install rely (安装依赖包)

a. dnf install -y zlib zlib-devel libxml2-devel \
libjpeg libjpeg-devel libpng libpng-devel gd gd-devel \
curl curl-devel libxslt-devel openssl-devel
b. libiconv
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.14.tar.gz
tar xf libiconv-1.14.tar.gz 
cd libiconv-1.14 
./configure --prefix=/usr/local/libiconv
sed -i -e '/gets is a security/d' srclib/stdio.in.h
make && make install

2) download (下载)

wget https://www.php.net/distributions/php-7.3.9.tar.bz2

3) unzip (解压)

tar xf php-7.3.9.tar.bz2
cd php-7.3.9

4) 编译并安装

./configure \
--prefix=/application/php7.3.9 \
--with-apxs2=/application/apache24/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-xmlrpc \
--with-openssl \
--with-zlib \
--with-freetype-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-iconv=/usr/local/libiconv \
--enable-short-tags \
--enable-sockets \
--enable-zend-multibyte \
--enable-soap \
--enable-mbstring \
--enable-static \
--enable-gd-native-ttf \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--enable-mysqlnd-compression-support \
--with-curl \
--with-xsl \
--enable-ftp \
--with-libxml-dir && make -j12 && make install

 

将apache24 和 php7整合

1. cd 到php的编译目录

2. cp php.ini-development php.ini-production /application/php7/lib/
3. cp php.ini-development /application/php7/lib/php.ini 
    2,3 复制生产环境和开发环境,作为备份,再次复制作为修改使用

4. 配置apache

cd /application/apache24/conf
vi httpd.conf
a. url重写
    取掉LoadModule rewrite_module modules/mod_rewrite.so 前面的注释 ‘#’
    修改 AllowOverride none 为All 此版本的apache在最后一个 如下
    
	    AllowOverride All
	    Require all denied
	
b.修改apache的进程守护者
    找到 User 将用户和组的名称改为 创建的apache用户
    User apache
    Group apache
c.添加默认访问index.php作为首页访问 (改为如下内容)
    DirectoryIndex index.php index.html
d.让.php, .html文件可以执行php
    AddType application/x-httpd-php .php .html
6. 配置虚机主机 (后面步骤可不用操作)
a. 取掉 httpd配置文件中 Include conf/extra/httpd-vhosts.conf 前面的注释 ‘#’
b. 配置虚拟主机
vi extra/httpd-vhosts.conf

    ServerName local.text.com
    DocumentRoot /var/www/text/public
    
        Options -Indexes +Includes +FollowSymLinks +MultiViews
        #AllowOverride All
        Require all granted
    

 

    ServerName demo.com
    DocumentRoot /var/www/demo
    
        Options -Indexes +Includes +FollowSymLinks +MultiViews
        #AllowOverride All
        Require all granted
    

5. path环境变量

vi /etc/profile

PATH=$PATH:/opt/lamp/php7.3.9/bin
export PATH

开机自启动

1. cd /etc/rc.d/
2. chmod +x rc.local
3. vi rc.local
添加下面两行
/application/apache24/bin/apachectl start
systemctl start mysqld

你可能感兴趣的:(web,linux,centos)