【实战总结】Centos 7安装部署LAMP环境

编译安装Apache 2.4.33

修改默认yum源

cd /etc/yum/repo.d

wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

mv CentOS-Base.repo CentOS-Base.repo.bak

mv CentOS-Base-163.repo CentOS-Base.repo

1、卸载系统自带的Apache

rpm -qa | grep httpd
rpm -e --nodeps 软件包名

2、创建软件存放目录及安装开发包组软件

yum groupinstall "Development tools" -y

3、安装apr、apr-util、pcre依赖包

yum install apr-devel apr-util-devel pcre-devel openssl-devel -y     

4、下载文件

wget http://archive.apache.org/dist/httpd/httpd-2.4.29.tar.gz

5、解压文件

tar -xzvf 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/local/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 install zlib-devel gcc-c++ ncurses-devel libaio libaio-devel -y
#卸载依赖
yum remove mariadb-libs -y

3、安装mysql

#新建一个mysql用户禁止登陆终端
useradd mysql -s /sbin/nologin -M
#创建mysql/data目录
mkdir /mysql/data -p
#给目录mysql所有组mysql所有组
chown -R mysql.mysql /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

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
/etc/init.d/mysqld start

6、修改密码开启远程访问

alter user 'root'@'localhost' IDENTIFIED BY '520521.....dQ';
use mysql;
update user set Host='%' where User='root';
flush privileges;

编译安装PHP

1、检查基础环境

# 检查apache环境
ls -ld /usr/local/apache2
# 检查mysql环境
ls -ld /usr/local/mysql

2、检查apache和mysql是否运行

ps -ef | grep httpd
ps -ef | grep mysqld
lsof -i :80

3、安装php所需的库文件

yum install gcc zlib libjpeg freetype libpng
gd curl 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=/usr/local/php-5.5.14 \
--with-apxs2=/usr/local/apache2/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-xmlrpc \
--with-openssl \
--with-zlib \
--with-freetype-dir \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--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-libxml2-dir
#如找不到mysql
cd /usr/local/mysql/lib
ln -s libmysqlclient.so.20.3.18 libmysqlclient_r.so

make && make install

5、建立软链接

ln -s /usr/local/php-5.5.14 /usr/local/php

6、复制配置文件到安装目录

cd ..
cp php-5.5.14/php.ini-production /usr/local/php/lib/php.ini

7、配置apache支持php程序

cd /usr/local/apache2/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
#如不存在,需自行创建php用户
useradd php -s /sbin/nologin -M
# 修改默认主页类型
<Ifmodule dir_module>
	DirectoryIndex index.php index.html
</Ifmodule>

8、重启apache

/usr/local/apache2/bin/apachectl -t
/usr/local/apache2/bin/apachectl graceful

9、测试php

echo "" > /usr/local/apache2/htdocs/index.php

你可能感兴趣的:(【Linux操作系统】,【Linux服务配置实战】)