centos7.6部署apache2.4+mysql8.0+php7.3

欢迎转载,但转载时请保留本段文字,并置于文章的顶部 作者:aeccing   本文原文地址https://blog.csdn.net/qq_41823886/article/details/85538484


 

注意:安装前先卸载老版本(mysql一定要卸载)

下载并解压

cd ~
yum -y install gcc-c++ wget bzip2 expat-devel
yum -y install libaio libaio-devel
yum -y install zlib-devel pcre-devel libxml2-devel curl-devel
yum -y install ncurses ncurses-devel openssl ope pcre* openssl* gd-devel*
yum -y install libcurl-devel
yum -y install openssl-devel
yum -y install libxslt-devel
yum -y install libxml2-devel
mkdir /usr/local/download
cd /usr/local/download
wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.37.tar.bz2
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.6.5.tar.bz2
wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.bz2
wget https://sourceforge.net/projects/pcre/files/pcre/8.42/pcre-8.42.tar.bz2
wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
wget https://download.savannah.gnu.org/releases/freetype/freetype-2.9.tar.gz
wget http://www.zlib.net/zlib-1.2.11.tar.gz
wget http://prdownloads.sourceforge.net/libpng/libpng-1.6.36.tar.gz
wget http://www.ijg.org/files/jpegsrc.v9c.tar.gz
wget https://nih.at/libzip/libzip-1.2.0.tar.gz
wget http://am1.php.net/get/php-7.3.0.tar.bz2/from/this/mirror
tar -jxvf httpd-2.4.37.tar.bz2
tar -jxvf apr-1.6.5.tar.bz2
tar -jxvf apr-util-1.6.1.tar.bz2
tar -jxvf pcre-8.42.tar.bz2
tar -xvf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz
tar xf freetype-2.9.tar.gz
tar xf zlib-1.2.11.tar.gz
tar xf libpng-1.6.36.tar.gz
tar xf jpegsrc.v9c.tar.gz
tar -zxvf libzip-1.2.0.tar.gz
tar -xf mirror

cd ~ 

安装apache 

cd /usr/local/download/apr-1.6.5
./configure --prefix=/usr/local/apr
make && make install
cd /usr/local/download/apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
make && make install
cd /usr/local/download/pcre-8.42
./configure --prefix=/usr/local/pcre
make && make install
cd /usr/local/download/httpd-2.4.37
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/
make && make install
cd ~

//修改apache配置文件 httpd.conf
/usr/local/apache/bin/httpd -V    查看httpd.conf文件所在位置
vi /usr/local/apache/conf/httpd.conf  ( #ServerName www.example.com:80(194行) 后面加 ServerName localhost:80 ) 

//开启apache
/usr/local/apache/bin/apachectl start

//防火墙开启80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload

安装mysql 

cd ~
mkdir /data
mv /usr/local/download/mysql-8.0.13-linux-glibc2.12-x86_64 /data/mysql8
useradd -s /sbin/nologin -M mysql
mv /etc/my.cnf /etc/my.cnf.bak
cd /data/mysql8

配置my.cnf 

vi /data/mysql8/my.cnf

复制下面内容
[mysqld]
port = 3306
basedir = /data/mysql8
datadir = /data/mysql8/data
max_connections = 1024
character-set-server = UTF8MB4
default-storage-engine = INNODB
server_id = 1
socket = /data/mysql8/mysql.sock
pid-file = /data/mysql8/mysql.pid
slow_query_log = 1
slow_query_log_file = /data/mysql8/log/mysql-slow.log
long_query_time = 10
log-error = /data/mysql8/log/mysql-err.log
log-bin = /data/mysql8/log/mysql-bin
user = mysql
default_authentication_plugin = mysql_native_password
sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  
[mysql]
default-character-set = UTF8MB4
  
[client]
port = 3306
socket = /data/mysql8/mysql.sock
default-character-set = UTF8MB4 

ln -s /data/mysql8/my.cnf /etc/my.cnf
mkdir /data/mysql8/log
mkdir /data/mysql8/data
chown -R mysql.mysql /data/mysql8
chmod 755 /data/mysql8 -R


/data/mysql8/bin/mysqld --initialize --user=mysql --basedir=/data/mysql8 --datadir=/data/mysql8/data      有临时密码(推荐)
/data/mysql8/bin/mysqld --initialize-insecure --user=mysql --basedir=/data/mysql8 --datadir=/data/mysql8/data    无密码

配置mysql文件 

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

vi /etc/init.d/mysql
//修改46,47行的basedir和datadir
basedir= /data/mysql8
datadir= /data/mysql8/data
//修改63-82行,把路径改成自已的mysql安装路径
mysqld_pid_file_path=
if test -z "$basedir"
then
  basedir=/data/mysql8
  bindir=/data/mysql8/bin
  if test -z "$datadir"
  then
    datadir=/data/mysql8/data
  fi
  sbindir=/data/mysql8/bin
  libexecdir=/data/mysql8/bin
else
  bindir="$basedir/bin"
  if test -z "$datadir"
  then
    datadir="$basedir/data"
  fi
  sbindir="$basedir/sbin"
  libexecdir="$basedir/libexec"
fi

//启动mysql
service mysql start

添加环境变量
vi /etc/profile
添加如下内容:
export PATH=$PATH:/data/mysql8/bin
使配置生效
source /etc/profile

//登录检查mysql

mysql -u root -p
若前面选择无密码:mysql -u root --skip-password

查看临时密码 less /data/mysql8/log/mysql-err.log
若前面选择有密码:mysql -u root -p

修改密码
方法1mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
方法2mysql>ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
flush privileges;

创建可远程连接的用户
create user '用户名'@'主机' identified with mysql_native_password by '密码';
grant all privileges on *.* to '用户名'@'主机';
flush privileges;

 

安装PHP 


cd /usr/local/download/zlib-1.2.11
./configure --prefix=/usr/local/zlib
make test
make install
cd /usr/local/download/libpng-1.6.36
./configure --prefix=/usr/local/libpng
make
make check
make install
cd /usr/local/download/jpeg-9c
./configure --prefix=/usr/local/libjpeg
make && make install
cd /usr/local/download/freetype-2.9
./configure --prefix=/usr/local/freetype
make && make install
cd /usr/local/download/libzip-1.2.0
./configure
make && make install
cp /usr/local/lib/libzip/include/zipconf.h /usr/local/include/zipconf.h
cd /usr/local/download/php-7.3.0
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-pdo-mysql --with-mysqli --with-zlib=/usr/local/zlib --with-freetype-dir=/usr/local/freetype --with-png-dir=/usr/local/libpng --with-jpeg-dir=/usr/local/libjpeg --with-curl --with-gd --with-gettext --with-iconv-dir --with-openssl --with-pcre-regex --with-pdo-sqlite --with-pear --with-xsl --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
cp /usr/local/download/php-7.3.0/php.ini-development /usr/local/php/php.ini
cd ~

如果想从新配置PHP只需重复./configure...  make && make install步骤

检查PHP
vi /usr/local/apache/conf/httpd.conf
查看有无(153行):LoadModule php7_module        modules/libphp7.so

在Apache的配置文件httpd.conf的块里增加一行(367行)

AddType application/x-httpd-php .php

php连接mysql
编辑php.ini(1166行)添加:mysqli.default_socket = /data/mysql8/mysql.sock
vi /usr/local/php/php.ini

运行apache
/usr/local/apache/bin/apachectl restart

添加php文件并输入 vi /usr/local/apache/htdocs/info.php

测试数据库连接
vi /usr/local/apache/htdocs/testConnectDatanase.php
$link = mysqli_connect("localhost","root","111111","mysql");
if($link){echo "successful connection";}else{echo "connection failed";}

你可能感兴趣的:(LAMP部署)