【实战】Centos7安装LAMP/LNMP
程序员文章站
2022-03-26 13:24:29
编译安装Apache 2.4.331、卸载系统自带的Apacherpm -qa | grep httpdrpm -e --nodeps 软件包名2、创建软件存放目录及安装开发包组软件mkdir /downloadyum groupinstall "Development tools" -y3、安装apr、apr-util、pcre依赖包yum install apr-devel -y...
编译安装Apache 2.4.33
1、卸载系统自带的Apache
rpm -qa | grep httpd
rpm -e --nodeps 软件包名
2、创建软件存放目录及安装开发包组软件
mkdir /download
yum groupinstall "Development tools" -y
3、安装apr、apr-util、pcre依赖包
yum install apr-devel -y
yum install apr-util-devel -y
yum install pcre-devel -y
yum install openssl-devel -y
4、下载文件
wget http://archive.apache.org/dist/httpd/httpd-2.4.29.tar.gz
5、解压文件
tar -xzf httpd-2.4.29.tar.gz
6、编译与安装
./configure --prefix=/usr/local/apache2 --enable-modules=all --enable-mods-shared=all --enable-so --enable-rewrite
make && make install
7、启动服务
/usr/local/apache2/bin/apachectl start
8、修改域名设置
vim /usr/loacl/apache2/conf/httpd.conf
修改servername 为127.0.0.1:80
9、域名目录
echo "test index" > /usr/local/apache2/htdocs/index.html
10、访问测试
curl localhost
编译安装Mysql 5.7.31
1、下载软件包
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
2、安装开发依赖包
yum groupinstall "Development tools" -y
#卸载依赖
yum remove mariadb-libs
3、安装mysql
#新建一个mysql用户禁止登陆终端
useradd mysql -s /sbin/nologin -M
#创建mysql/data目录
mkdir /mysql/data -p
#给目录mysql所有组mysql所有组
chown -R mysql.mysql /mysql/
chmod -Rf 755 /mysql/
#解压二进制安装包
tar -xzvf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz -C /usr/local
#创建链接文件
ln -s /usr/local/mysql-5.7.31-linux-glibc2.12-x86_64 /usr/local/mysql
cd /usr/local/mysql
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
rm -f /etc/my.cnf
4、初始化
#初始化
./bin/mysqld --initialize --basedir=/usr/local/mysql --datadir=/mysql/data/ --user=mysql
vim /etc/init.d/mysqld
#添加basedir和datadir
5、添加环境变量
echo 'export PATH=$PATH:/usr/local/mysql/bin' >>/etc/profile
source /etc/profile
#pid log文件路径
/mysql/data/localhoast.domain.pid
/mysql/data/localhoast.domain.log
6、修改密码
alter user 'root'@'localhost' IDENTIFIED BY '520521.....dq';
编译安装PHP
1、检查基础环境
# 检查apache环境
ls -ld /usr/local/apache2.4.29
# 检查mysql环境
ls -ld /usr/local/mysql
2、检查apache和mysql是否运行
ps -ef | grep httpd
ps -ef | grep mysqld
lsof -i :80
3、安装php所需的库文件
yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2 libxml2-devel libjpeg-devel
freetype-devel libpng-devel gd-devel curl-devel openssl-devel libxslt-devel -y
4、安装php
# 解压缩
tar -xzvf php-5.5.14.tar.gz
cd php-5.5.14
# 配置编译
./configure \
--prefix=/application/php-5.5.14 \
--with-apx2=/usr/local/apache2.4.29/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 \
--enable-short-tags \
--enable-sockets \
--enable-zend-multibyte \
--enable-soap \
--enable-mbstring \
--enable-static \
--enable-gd-native-ttf \
--with-curl \
--with-xsl \
--enable-ftp \
--with-libxml-dir
make && make install
5、建立软链接
ln -s /application/php-5.5.14 /application/php
6、复制配置文件到安装目录
cp php-5.5.14/php.ini-production /application/php/lib/php.ini
7、配置apache支持php程序
cd /usr/local/apache2.4.29/conf
cp httpd.conf httpd.conf.bak
vim /httpd.conf
#加入以下配置
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
# 修改默认用户
User php
Group php
如不存在,需自行创建
# 修改默认主页类型
<Ifmodule dir_module>
DirectoryIndex index.php index.html
</Ifmodule>
8、重启apache
/usr/local/apache2.4.29/bin/apachectl -t
9、测试php
echo "test" > /usr/local/apache2.4.33/htdocs/index.php
本文地址:https://blog.csdn.net/u014797713/article/details/107475973
推荐阅读
-
阿里云主机一键安装lamp、lnmp环境的shell脚本分享
-
阿里云Linux主机安装WDCP管理面板(包含lamp+lnmp+lanmp环境)
-
LAMP&LNMP自动化安装脚本代码
-
CentOS7编译安装新版LNMP环境
-
CentOS7 LNMP+phpmyadmin环境搭建 第三篇phpmyadmin安装
-
CentOS7 LNMP+phpmyadmin环境搭建 第一篇虚拟机及centos7安装
-
centos7利用yum安装lnmp的教程(linux+nginx+php7.1+mysql5.7)
-
Zabbix安装图文教程(需要LAMP或者LNMP运行环境)
-
阿里云主机一键安装lamp、lnmp环境的shell脚本分享
-
linux LNMP高并发服务编译安装搭建实战