源码搭建LAMP环境
安装apache
下载互联网源,和扩展源wget http://mirrors.aliyun.com/repo/epel-7.repo
mkdir /lamp
cd /lamp
yum -y install gcc gcc-c++ make
yum -y install expat-devel pcre-devel openssl-devel
tar -xf apr-1.7.0.tar.gz
tar -xf apr-util-1.6.1.tar.gz
tar -xf httpd-2.4.46.tar.gz
安装依赖apr
cp -a apr-1.7.0 httpd-2.4.46/srclib/apr
cd /lamp/apr-1.7.0/
./configure --prefix=/usr/local/apr && make && make install
echo $?
#这里尽量慢点,看是否安装成功
安装apr-util
cp -a apr-util-1.6.1 httpd-2.4.46/srclib/apr-util
cd /lamp/apr-util-1.6.1/
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ && make && make install
echo $?
安装httpd
cd /lamp/httpd-2.4.46
./configure --prefix=/usr/local/apache2 --sysconfdir=/usr/local/apache2/etc/ --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util && make -j 2 && make install
#开启自己需要功能和依赖软件
echo $?
#这里简单说下cgi公共网关接口
#--enable-so让apache核心装载DSO{动态编译安装,静态编译安装}比如调用libphp5.so,类似windows下.dll
开启httpd
/usr/local/apache2/bin/apachectl start
netstat -antp | grep :80
访问页面出现it works则正确
php安装
解压 tar -xf php-7.4.11.tar.bz2
cd /lamp/php
yum -y install libxml2-devel curl-devel libjpeg-devel libpng-devel freetype-devel libxslt-devel
yum -y install libmcrypt-devel
yum -y install libxslt-devel
如果没有扩展源下载不了
cd /lamp/php-7.4.11.
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-mcrypt --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-opcache --with-xsl --with-apxs2=/usr/local/apache2/bin/apxs && make -j 2 && make install
**当报错****No package 'sqlite3' found**
安装yum -y install sqlite-devel
**当出现报错****No package 'oniguruma' found**
安装yum -y install oniguruma
yum -y install oniguruma-devel
继续重复上部操作后
会出现以下截图
PHP安装后需要调整相应配置文件和参数才能正常运行
a.生成php配置文件
mkdir /usr/local/php/etc
cp -a /lamp/php-7.4.11/php.ini-production /usr/local/php/etc/php.ini
b.修改Apache配置文件,使其识别*.php文件,并能通过php模块调用php进行页面解析
vim /usr/local/apache2/etc/httpd.conf
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps
重启Apache服务
/usr/local/apache2/bin/apachectl stop
/usr/local/apache2/bin/apachectl start
c.测试php页面是否能正常解析(即apache和php连通性)
vim /usr/local/apache2/htdocs/test.php
<?php
phpinfo();
?>
通过浏览器输入地址访问:http://Apache服务器地址/test.php
如出现以下页面则证明成功
安装mysql
tar -xf mysql-8.0.19-el7-x86_64.tar.gz
cp -a mysql-8.0.19-el7-x86_64 /usr/local/mysql
为MySQL软件创建运行用户,创建为系统用户,并限制此用户登录操作系统
useradd -r -s /sbin/nologin mysql
修改MySQL目录的用户归属
cd /usr/local
chown -R mysql.mysql mysql/
创建mysql数据目录
mkdir -p /data/mysql
修改mysql数据目录权限
chown -R mysql.mysql /data/mysql
配置参数
cp -a /etc/my.cnf /tmp
vim /etc/my.cnf
删除所有,编写以下
[mysqld]
bind-address=0.0.0.0
port=3306 user=mysql
basedir=/usr/local/mysql
datadir=/data/mysql
socket=/tmp/mysql.sock
log-error=/data/mysql/mysql.err
pid-file=/data/mysql/mysql.pid
#character config
character_set_server=utf8mb4
symbolic-links=0
explicit_defaults_for_timestamp=true
进入mysql的bin目录
cd /usr/local/mysql/bin/
初始化
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --datadir=/data/mysql/ --user=mysql --initialize
cd /data/mysql
cat mysql.err
查看初始密码:最后一行
启动MySQL,并更改root 密码
cd /usr/local/mysql/support-files/
cp -a mysql.server /etc/init.d/mysql
利用server命令启动
提示success则成功
使用初始密码登陆
cd /usr/local/mysql/bin
./mysql -u root -p
如果出现以下错误
请yum -y install libncurses*
修改MySQL用户密码,并刷新
alter user ‘root’@‘localhost’ IDENTIFIED BY ‘123456’;
flush privileges;
然后重新登录
创建数据库
进行测试
解压缩typecho文件
cp -a typecho /usr/local/httpd/htdocs/
修改所属chown -R daeman.daeman typecho
修改httpd配置文件
vim /usr/local/httpd/etc/httpd.conf
找到ServerName 去掉注释 后面改为localhost:80
找到index.html后面加上index.php
访问ip地址/typecho安装