LAMP部署手动档
LAMP =linux + apache +mysql + php
来吧,在阿里云上弄个自己的wordpress。这里用apache作为服务器
这篇是适合于线上环境的手动安装版,全程自行定制,编译安装,费时费力,经过反复演练整套下来要2-3个小时,还得指望不需要排错。稍后有时间会重新制作个适合测试环境的一键安装版。
由于是写给自己用的,所有操作步骤只给出简易注释,并没有说的通俗易懂。一步一步都真实有效,不存在copy。
所有的软件都选取相对较新的版本。
1.必须先装mysql5.6 //5.6,5.5,5.7的安装配置方式完全不一样,此处只适用于5.6
mysql编译安装伤不起,运行了四个小时后说内存不足,进程被杀死。所以下面是二进制安装方式,只是rpm包太过巨大,下载耗费时间。
下载的安装包和软件统一放置在/opt目录下存留
cd /opt && wget http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.6/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz //下载软件包
tar zxvf mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz //解压
mv mysql-5.6.46-linux-glibc2.12-x86_64 mysql5.6 //改名
mv mysql5.6 /usr/local && ln -s mysql5.6 mysql //挪到安装目录且做个软链,这个软链非常有必要!
mkdir -p /usr/local/mysql/data //建立数据目录
id mysql //查看用户存在不,若不存在则$?=1 这里最好用完整的判断语句
groupadd -r mysql //添加mysql用户组
useradd -g mysql -r -d /usr/local/mysql/data mysql //添加Mysql用户
mv /etc/my.cnf /etc/my.cnf.back_up //备份文件
cd /usr/local/mysql/support-files
cp my-default.cnf /etc/my.cnf //拷贝主配置文件
cp mysql.server /etc/init.d/mysqld //拷贝启动脚本,然后修改
vi /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
cd /usr/local/mysql && chown -R mysql:mysql . //更改文件目录权限
cd /usr/local/mysql/scripts && yum -y install autoconf //如果不装autoconf,会报错
./mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data //重要的一环,数据库初始化
echo "export PATH=/usr/local/mysql/bin:$PATH" >> /etc/profile
source /etc/profile
vim /etc/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
systemctl start mysqld
netstat -tunlp | grep 3306
chkconfig --add mysqld //可能会添加不成功
mysql //第一次无需密码就直接进去了
delete from mysql.user where user='';
delete from mysql.user where host='::1';
select user,host from mysql.user;
use mysql;
update user set password=password("abc123xyz") where user="root";
flush privileges;
select User,Password,Host from mysql.user\G
exit; //退出
mysql -uroot -p //重新登录看密码生效了不?
systemctl stop mysqld //停止服务
netstat -tunlp | grep 3306 // 看停止了没?
systemctl start mysqld //重启服务
netstat -tunlp | grep 3306 //检查启动成功了没
===========================================================
2.再来装个Apache! 需要apr库的支持
检查编译环境
yum install -y libxml2-devel pcre-devel openssl-devel expat-devel && yum -y groupinstall "Development Tools"
下载必要软件,包括apr,apr-util,
cd /opt && wget https://mirrors.cnnic.cn/apache/apr/apr-1.7.0.tar.gz
wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
wget https://mirrors.cnnic.cn/apache/httpd/httpd-2.4.38.tar.gz
统统解压
tar xf apr-1.7.0.tar.gz && tar apr-util-1.6.1.tar.gz && tar xf httpd-2.4.38.tar.gz
cd apr-1.7.0 && ./configure --prefix=/usr/local/apr && make && make install //安装apr1.7
cd apr-util-1.6.1 && ./configure --prefix=/usr/local/apr-util --with apr=/usr/local/apr && make && make install //安装apr-util
./configure --prefix=/usr/local/apache2.4 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
make && make install //安装apache,耗费时间30分钟左右
提供SysV服务脚本/etc/rc.d/init.d/httpd,内容如下
#!/bin/bash
# httpd Startup script for the Apache HTTP Server
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
RETVAL=$?
echo $"not reloading due to configuration syntax error"
failure $"not reloading $httpd due to configuration syntax error"
else
killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f ${pidfile} ] ; then
stop
start
fi
;;
reload)
reload
;;
graceful|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit 1
esac
exit $RETVAL
而后为此脚本赋予执行权限:
chmod +x /etc/rc.d/init.d/httpd
加入服务列表:
chkconfig --add httpd
centos 环境中管理服务的方式:
systemctl (restart|staus|reload|stop|stat) httpd.service
查看apache工作模式:
/usr/local/apache/bin/apachectl -M
最后,测试安装成功了没?
修改配置后,检查语法是否正确
/usr/local/apache/bin/apachectl -t
平滑重启
/usr/local/apache/bin/apachectl graceful
===========================================================
3. 安装PHP 7.3
因为PHP编译时需要mysql和apache的支持,所以放在了最后
wget https://www.php.net/distributions/php-7.3.2.tar.gz //选择7.3版本
./configure --prefix=/usr/local/php7 --with-config-file-path=/usr/local/php7/etc --with-apxs2=/usr/local/apache2.4/bin/apxs --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --with-mhash --enable-bcmath
make && make install //
不支持 --with-mcrypt,手动编译安装
cp /opt/php-7.3.2/php.ini-production /usr/local/php7/etc/php.ini //拷贝配置文件,很重要!
/usr/local/apache2.4/bin/apachectl -M //查看模块是否加载
vi /usr/local/apache2.4/conf/httpd.conf //如果5和7 共存会有冲突,必须注销一个
#LoadModule rewrite_module modules/mod_rewrite.so
#LoadModule php5_module modules/libphp5.so
LoadModule php7_module modules/libphp7.so
===========================================================
4.稍为繁复的整合过程
修改配置文档
vim /usr/local/apache2.4/conf/httpd.conf
ServerName www.example.com:80 搜索关键字 example.com:80,取消注释
将Require all deny 改成 all granted,搜索关键字Require all
<Directory />
AllowOverride none Require all granted
</Directory>
增加一行AddType application/x-httpd-php .php ,搜索关键字AddType application
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
增加索引页index.php,增加 index.php,搜索关键字是DirectoryIndex
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
/usr/local/apache2.4/bin/apachectl -t //检查语法是否正确
/usr/local/apache2.4/bin/apachectl graceful //重新加载配置文件
touch /usr/local/apache2.4/htdocs/test.php
echo "<?php phpinfo();?>"> /usr/local/apache2.4/htdocs/test.php //编写测试文件
ip addr /查看本机地址
http://ip/test.php //测试访问效果
==========================================================
5.实战之发布wordpress
实践应用来了!在这一步,遇上了无数个坑。
1.首先重连数据库时遇上了28000错误,我的密码明明没错,为什么不让我连接?检查了一切权限都没有问题,排查了很久发现是2个ECS上设置的密码不一样,的的确确是密码错了,白费时间。
2.其次,phpinfo页面也没有mysql信息,连个错误提示都不给!编辑php.ini,取消mysqli相关的所有注释!
3.把wordpress放入/usr/local/apache2.4/htdocs/目录下,访问时连接不了数据库。这个问题很好解决,手动编辑wordpress/wp-config.php,手动指定连接的主机名,用户名,密码,数据库(需要自己create一个),然后重启apache。请在安装页面复制保存下wordpress给你分配的密钥!比如,曾经有个就是1mF3c*UMyLD5(uv^Xr ,脑子绝对记不住的!

浙公网安备 33010602011771号