编译安装搭建lamp架构

编译安装搭建lamp架构

编译安装mysql

开始搭建架构最好准备一个新虚拟机,会大大降低踩坑次数
建议配置最新的阿里云yum源

最好开始前直接关闭掉所有防火墙,不用踩防火墙的坑
找到系统内置防火墙selinux的配置文件,确保其运行状态为关闭

grep -i 'selinux='  /etc/selinux/config 
# SELINUX= can take one of these three values:
SELINUX=disabled

永久关闭系统防火墙firewalld
systemctl stop  firewalld
systemctl disable firewalld

安装一些常用的基础环境依赖,能避免后续操作踩坑

yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel net-tools vim -y

yum install cmake make pcre-devel ncurses-devel openssl-devel libcurl-devel -y

yum install libxml2-devel  libjpeg-devel libpng-devel freetype-devel  libcurl-devel wget -y

yum groupinstall "Development tools" -y

yum groupinstall "Desktop Platform Development" -y 

以上软件都安装好后后续操作不会遇见缺少基础依赖而报错的情况


开始编译安装mysql

#注意,这三个软件之间安装会有一定的先后顺序,
mysql和apache之间没有先后顺序,随便先安装哪个都一样
apache和php之间必须先安装apache
mysql和php之间也没有安装的先后顺序


创建一个指定目录,用于下载该软件
mkdir -p /usr/local/software-mysql;
cd /usr/local/software-mysql
wget -c https://repo.huaweicloud.com/mysql/Downloads/MySQL-5.6/mysql-5.6.50.tar.gz


解压缩下载好的源码进入到解压后的目录
tar -zxf mysql-5.6.50.tar.gz 
cd mysql-5.6.50

这个软件包里面是没有configure配置脚本的,需要自己手动创建一个脚本,然后对其进行定制化

cat cmake.sh 
cmake . \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DMYSQL_TCP_PORT=3306 \
-DDEFAULT_CHARSET=utf8mb4 \
-DDEFAULT_COLLATION=utf8mb4_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DMYSQL_USER=mysql

写入以上内容后./cmake.sh 执行该脚本

执行结束后没有看到error相关的就一切正常,如果有可能是配置文件的内容写入错误,根据错误提示去查找问题

对其进行定制化后就可以编译安装该软件了
make && make install
 
 
 安装完成后配置环境变量
 
echo 'export PATH=$PATH:/usr/local/mysql/bin/'  >> /etc/profile
写入后手动读取改文件配置
source /etc/profile

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin/


修改mysql的文件权限,属主,属组

需要先创建一个mysql用户
useradd -r -s /sbin/nologin mysql

chown -R mysql:mysql /usr/local/mysql/

不管有没有旧的数据文件残留,直接一条命令清理掉
mv /etc/my.cnf /etc/my.cnf.bak

使用初始化mysql数据命令操作
进入到mysql的安装目录,找到他的初始化数据,执行如下安装命令
./scripts/mysql_install_db --user=mysql


因为是编译安装,需要手动创建启动脚本
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql


此时使用service命令,会去读取/etc/init.d目录下的脚本文件,启动mysql
service mysql start

此时可以修改mysql的密码,用如下命令,注意语法
# -u -p参数后面不得有空格,是直接跟上用户名或者密码的
# -p 不写密码的话,会让你交互式输入密码
# password 跟上你的新的mysql密码

/usr/local/mysql/bin/mysqladmin -uroot -p   password 'xinxin123'

重置密码后用新密码登录mysql
mysql -uroot -p

编译安装apache依赖

安装前需要安装他的两个关键依赖

先下载其源码包
wget -c http://archive.apache.org/dist/apr/apr-1.5.2.tar.bz2

解压缩,编译安装
tar -xf apr-1.5.2.tar.bz2

 cd apr-1.5.2
 
 需要修改其配置文件的一个参数,不改会报错
 vim configure
29605     RM='$RM -f'

再次执行配置脚本
./configure

编译且安装
make && make install


安装apr-util软件

先下载其源码包
wget -c https://archive.apache.org/dist/apr/apr-util-1.5.4.tar.bz2


解压缩
tar -xf apr-util-1.5.4.tar.bz2
cd apr-util-1.5.4

编译安装,需要指定安装路径
./configure --with-apr=/usr/local/apr/bin/apr-1-config


make && make install


需要在/etc/ld.so.conf这个主配置文件里加上一行,写上让别人要查找库文件的路径
echo "/usr/local/apr/lib/" >> /etc/ld.so.conf

ldconfig      上面加入路径后,就使用此命令让其生效


编译安装httpd

下载该源码
wget -c https://archive.apache.org/dist/httpd/httpd-2.4.37.tar.bz2

解压缩该源码,进入到该目录
tar -xf httpd-2.4.37.tar.bz2
cd httpd-2.4.37

可以直接执行如下参数,也可以写成一个脚本执行
./configure \
--enable-modules=all \
--enable-mods-shared=all \
--enable-so \
--enable-rewrite \
--with-pcre \
--enable-ssl \
--with-mpm=prefork \
--with-apr=/usr/local/apr/bin/apr-1-config \
--with-apr-util=/usr/local/apr/bin/apu-1-config

执行完毕后编译且安装
 make && make install
 
 查看该目录下生成如下数据就是正确安装了
  ls /usr/local/apache2/
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  man  manual  modules

编译安装php

下载该源码
wget -c https://museum.php.net/php7/php-7.2.17.tar.xz

解压缩,进入该目录
tar -xf php-7.2.17.tar.xz
cd php-7.2.17

在该目录下创建一个脚本文件
vim configure.sh
写入如下内容
./configure \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysqli \
--with-pdo-mysql \
--with-zlib \
--with-curl \
--enable-zip \
--with-gd \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--enable-opcache \
--enable-mbstring \
--enable-mbregex \
--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-calendar \
--enable-bcmath

对该脚本提权后执行该脚本
chmod +x configure_php.sh

./configure_php.sh

执行无误后编译且安装
make && make install

测试apache是否支持php

需要先修改apache的配置文件,让他支持php

159 LoadModule negotiation_module modules/mod_negotiation.so 去掉这一行的注释
482 Include conf/extra/httpd-languages.conf 打开此选项,扩展配置文件就生效了

添加以下两行意思是以.php结尾的文件都认为是php程序文件,注意两句话的.php前面都是有一个空格的
也就是长这样
166 LoadModule php7_module        modules/libphp7.so
167 AddHandler php7-script .php
168 AddType text/html .php


添加一个默认的网站首页,添加为php的文件
263 #
264 # DirectoryIndex: sets the file that Apache will serve if a directory
265 # is requested.
266 #
267 <IfModule dir_module>
268     DirectoryIndex index.php index.html
269 </IfModule>

关于网站默认的首页html文件,存放的目录路径,由以下参数控制
230 # DocumentRoot: The directory out of which you will serve your
231 # documents. By default, all requests are taken from this directory, but
232 # symbolic links and aliases may be used to point to other locations.
233 #
234 DocumentRoot "/usr/local/apache2/htdocs"
235 <Directory "/usr/local/apache2/htdocs">

修改apache的子配置文件,优先支持中文,需要做如下两步操作

vim /usr/local/apache2/conf/extra/httpd-languages.conf
 19 DefaultLanguage zh-CN

 75 # Just list the languages in decreasing order of preference. We have
 76 # more or less alphabetized them here. You probably want to change this.
 77 #
 78 LanguagePriority zh-CN en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv tr zh-CN zh-TW
 
 测试apache是否支持php
 
 进入apache网页根目录,创建一个php文件,查看是否执行
[root@lamp-241 htdocs]# pwd
/usr/local/apache2/htdocs

 cat index.php
<?php
    phpinfo();
?>



拷贝apache默认提供的一个脚本即可,就是启动apache的命令
cp /usr/local/apache2/bin/apachectl /etc/init.d/apache

service apache start


访问自己的ip,能够在网页上显示phpinfo界面表示以上操作正常,一个基础的lamp架构就搭建起来了

部署web应用

下载源码
wget -c https://cn.wordpress.org/wordpress-4.7.3-zh_CN.tar.gz


创建目录,保存wordpress的代码
以及解压缩源码,全部拷贝到该目录中
mkdir -p /www/yuchao-blog
tar -zxf wordpress-4.7.3-zh_CN.tar.gz
cp -a wordpress/* /www/yuchao-blog/

更改源码属主,属组
chown -R daemon.daemon /www/yuchao-blog/

准备网站上线发布(给apache添加一个新配置文件,专门发布我们这个wordpress)虚拟主机
vim /usr/local/apache2/conf/httpd.conf

492 # Virtual hosts
493 Include conf/extra/httpd-vhosts.conf


修改该虚拟主机配置文件,添加关于wordpress的配置信息

vim /usr/local/apache2/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>
    DocumentRoot "/www/yuchao-blog"
    ServerName yuchao-wordpress.cc
    ErrorLog "logs/blog-error_log"
    CustomLog "logs/blog-access_log" common
</VirtualHost>


配置数据库,用于存放博客数据
 mysql -uroot -p
 
创建存储博客的数据库boke_blog
mysql> create database boke_blog default charset utf8;
Query OK, 1 row affected (0.16 sec)

修改apache配置,添加可访问权限
修改这里Require all denied        默认拒绝所有,改为Require all granted
212 #
213 # Deny access to the entirety of your server's filesystem. You must
214 # explicitly permit access to web content directories in other
215 # <Directory> blocks below.
216 #
217 <Directory />
218     AllowOverride none
219     Require all granted
220 </Directory>


以上操作全部正常完成后即可进入到网页中安装该博客页面

posted @ 2022-04-02 21:41  刘条缝  阅读(63)  评论(0)    收藏  举报