LAMP架构部署及配置
作者:互联网
httpd编译安装
1、关闭防火墙,将安装Apache所需软件包传到/opt目录下
systemctl stop firewalld
systemctl disable firewalld
setenforce 0
cd /opt
tar zxf apr-1.6.2.tar.gz
tar zxf apr-util-1.6.0.tar.gz
tar jxf httpd-2.4.29.tar.bz2
2.移动文件并改名
mv apr-1.6.2 httpd-2.4.29/srclib/apr
mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
3.安装编译器
yum -y install \
gcc \
gcc-c++ \
make \
pcre \
pcre-devel \
expat-devel \
perl
4.编译
./configure \
--prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi
5.安装
make -j4 && make install
6.优化配置文件路径,并把httpd服务的可执行程序文件放入路径环境变量的目录中便于系统识别
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
vi /etc/init.d/httpd
在第一行前插入新行,添加两行内容 :
#chkconfig: 35 85 21 #35级别自动运行 第85个启动 第21个关闭
#description: Apache is a World Wide Web server
chkconfig --add httpd #将httpd加入到SERVICE管理器
vi /usr/local/httpd/conf/httpd.conf
- 注释掉52行,修改第51行
- #51行,监听地址为自己的ip地址
- #197行 ServerName www.xhx.com:80
7.做软连接,使文件可执行
ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/
8.查看语法是否有问题并开启服务
httpd -t
Syntax OK #说明没问题
service httpd start #开启服务
netstat -anpt | grep 80 #查看端口信息
9.网页测试
在网页输入本地IP
cd /usr/local/httpd/htdocs
vim index.html
再次测试
编译安装mysql
1.安装依赖环境
yum -y install \
ncurses \
ncurses-devel \
bison \
cmake
2.创建运行用户
useradd -s /sbin/nologin mysql
3.编译安装
cd /opt
将mysql软件包拖入该目录下进行解压
tar -zxf mysql-boost-5.7.20.tar.gz
cd mysql-5.7.20
编译
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \
-DSYSCONFDIR=/etc \
-DSYSTEMD_PID_DIR=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/usr/local/mysql/data \
-DWITH_BOOST=boost \ -DWITH_SYSTEMD=1
安装
make && make install -j4
4.数据库目录进行权限调整
chown -R mysql:mysql /usr/local/mysql
5.调整配置文件
vi /etc/my.cnf
将文件内容删除重新写入以下内容:
[client]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysql]
port = 3306
default-character-set=utf8
socket = /usr/local/mysql/mysql.sock
[mysqld]
user = mysql
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
port = 3306
character_set_server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket = /usr/local/mysql/mysql.sock server-id = 1
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES
6.设置环境变量
-
echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile
-
echo 'export PATH' >> /etc/profile
7.初始化数据库
cd /usr/local/mysql
bin/mysqld \
--initialize-insecure \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/usr/local/mysql/data
cp usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system
8.数据库开启自启、 关闭、状态
systemctl enable mysqld
systemctl start mysqld
systemctl status mysqld
netstat -anpt | grep 3306
9.设置Mysql密码
ln -s /usr/local/mysql/bin/* /usr/local/bin
mysqladmin -u root -p password
10.登录数据库
mysql -u root -p
PHP编译安装
1.安装环境依赖包
yum -y install \
libjpeg \
libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 \
libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel
2.编译安装
cd /opt
tar -jxf php-7.1.10.tar.bz2
cd php-7.1.10
./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip
make && make install -j4
3.优化把PHP 的可执行程序文件放入路径环境变量的目录中便于系统识别
ln -s /usr/local/php5/bin/* /usr/local/bin/
4.修改Apache配置文件让Apache支持PHP
vim /etc/httpd.conf
255 <IfModule dir_module> 256 DirectoryIndex index.html index.php 257 </IfModule>
#在392行下方插入一下内容,让Apache可以支持.php的网页文件 AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps
5.创建网页文件
vim /usr/local/httpd/htdocs/index.php
6.重启服务
service httpd stop
service httpd start
7.网页测试
http://172.16.10.101/index.php
标签:httpd,enable,架构,部署,--,LAMP,usr,mysql,local 来源: https://www.cnblogs.com/xhx1991874414/p/16345801.html