Experimental catalog:
A, LAMP architecture concepts
Second, the structure of the installation and configuration LAMP
2-1 manually compile and install the http service
2-2 manually compile and install mysql database
2-3 manually compile and install PHP Tools
Third, the installation Discuz Forum (open forum)
Fourth, small welfare
A, LAMP architecture concepts
LAMP refers to a set of commonly used together to run dynamic Web sites or servers free software name acronyms:
- L inux, operating system
- A pache, web server
- M ariaDB or M ySQL, database management system (or database server)
- P the HP, P ERL or P ython, scripting languages
It is the most mature of a - kind of enterprise web application mode, provides dynamic Web sites and applications development environment.
The experiments required for all services source packages have been uploaded to a network disk, you can copy their own use (both open-source software)
Links: https://pan.baidu.com/s/1H_k-1lXH4Pjkrsl2EN4CNA extraction code: r0pi
Second, the structure of the installation and configuration LAMP
2-1 manually compile and install the http service
Use mount.cifs
the entire software directory is mounted directly to Linux or entire directories can be copied into Linux. (The experiment mount point / mnt / directory)
Install Apache Service
Three packages needed to extract the Apache service
[root@localhost ~]#cd /mnt
[root@localhost mnt]# tar xf apr-1.6.2.tar.gz -C /opt //将压缩包解压到opt目录下
[root@localhost mnt]# tar xf apr-util-1.6.0.tar.gz -C /opt
[root@localhost mnt]# tar xf httpd-2.4.29.tar.gz -C /opt
The apr, apr-util two plug into the designated location of the httpd
[root@localhost mnt]# mv apr-1.6.2 httpd-2.4.29/srclib/apr
[root@localhost mnt]# mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
After all the moves, the environment required to start the installation package (\ as shown with a line)
[root@localhost mnt]# yum -y install \
gcc \
gcc-c++ \
make \
pcre-devel \
expat-devel \
perl
among them,
gcc, gcc-c ++: c c ++ language and compiler
make: Compilation Tools
pcre, pcre-devel: development pcre language compiler
expat-devel: the new website is able to parse xml file format
After installation is complete, move into the http package to "configure" file manually compiled (it must always be within the package !!)
[root@localhost mnt]# cd httpd-2.4.29
[root@localhost httpd-2.4.29]# ./configure \
--prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi
[root@localhost httpd-2.4.29]# make && make install //编译并进行安装(需要等待一定时间)
among them:
--prefix: back custom installation path
--enable-so: open the core module
--enable-rewrite: Rewrite feature is turned on
--enable-charset-lite: turn on character set support
--enable-cgi: Open Common Gateway Interface (CGJ as a coding format)
When finished, start adding startup scripts, easy to open and close the system to better control service, and feels that she added to httpd SERVICE manager.
[root@localhost httpd-2.4.29]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
//添加启动脚本
[root@localhost httpd-2.4.29]# chkconfig --add httpd //将httpd加入到SERVICE管理器
Apache then enters the service profile, according to the modification of FIG.
Finally, we can start with the profile related documents for administrative purposes to do a soft link (can not), turn off the firewall, and start the Apache service
[root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/conf/httpd.conf /etc/
[root@localhost httpd-2.4.29]# ln -s /usr/local/httpd/bin/* /usr/local/bin/
[root@localhost httpd-2.4.29]# systemctl stop firewalld.service
[root@localhost httpd-2.4.29]# setenforce 0
[root@localhost httpd-2.4.29]# service httpd start
2-2 manually compile and install mysql database
Mysql database installation
[root@localhost ~]# yum install -y ncurses-devel autoconf cmake //安转环境包以及cmake编译器
[root@localhost ~]# cd /mnt/
[root@localhost mnt]# tar xzvf mysql-5.6.26.tar.gz -C /opt //对mysql源码包进行解压
Of source package to be compiled (\ to newline)
[root@localhost mnt]# cd /opt/mysql-5.6.26
[root@localhost mysql-5.6.26]# cmake \ //对源码包进行编译
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DSYSCONFIDIR=/etc \
-DMYSQL_DATADIR=/home/mysql/ \
-DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock
[root@localhost mysql-5.6.26]# make && make install //编译安装
among them,
-DCMAKE_INSTALL_PREFIX = / usr / local / mysql: database installation directory specified
-DDEFAULT_CHARSET = utf8: specify the character set
-DDEFAULT_COLLATION = utf8_general_ci: Specifies the default character set
-DEXTRA_CHARSETS = all: Specifies the extended character set
-DSYSCONFIDIR = / etc: Specifies the configuration file directory
-DMYSQL_DATADIR = / home / mysql /: Specifies the data files and the database
-DMYSQL_UNIX_ADDR = / home / mysql / mysql.sock: definition of sock file
MySQL Configuration
[root@localhost mysql-5.6.26]# cp support-files/my-default.cnf /etc/my.cnf
[root@localhost mysql-5.6.26]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.6.26]# chmod 755 /etc/init.d/mysqld //授予执行权限
[root@localhost mysql-5.6.26]# chkconfig --add /etc/init.d/mysqld //将数据库服务添加到管理器中
[root@localhost mysql-5.6.26]# chkconfig mysqld --level 35 on //开启数据库的3,5运行级别
[root@localhost mysql-5.6.26]# echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile //启用数据库命令到系统环境变量
[root@localhost mysql-5.6.26]# source /etc/profile //启用系统环境变量
[root@localhost mysql-5.6.26]# echo $PATH //查看系统环境变量
[root@localhost mysql-5.6.26]# useradd -s /sbin/nologin mysql //创建mysql程序用户,禁止用于登录
[root@localhost mysql-5.6.26]# chown -R mysql:mysql /usr/local/mysql/ //给/usr/local/mysql/目录下所有用户提权
[root@localhost mysql-5.6.26]# /usr/local/mysql/scripts/mysql_install_db \
--user=mysql \
--ldata=/var/lib/mysql \
--basedir=/usr/local/mysql \
--datadir=/home/mysql //初始化数据库,并指定用户数据信息到指定目录
[root@localhost mysql-5.6.26]# vim /etc/init.d/mysqld //编辑数据库配置文件
basedir=/usr/local/mysql //指定数据库自身安装路径
datadir=/home/mysql //指定指定数据库存放位置
Open the database, and set the password
[root@localhost mysql-5.6.26]# service mysqld start
[root@localhost mysql-5.6.26]# mysqladmin -u root -p password "123123" //给root账号设置密码
2-3 manually compile and install PHP Tools
Installation environment package, and extract the source package
[root@localhost mysql-5.6.26]# cd /mnt/
[root@localhost mnt]# yum -y install \
gd \
libpng \
libpng-devel \
pcre \
pcre-devel \
libxml2-devel \
libjpeg-devel
[root@localhost mnt]# tar xjvf php-5.6.11.tar.bz2 -C /opt
among them,
gd: image processing tools
libxml2-devel: analytical support, label language
libjpeg-devel: support jpg image format
Compile and install PHP Tools
[root@localhost mnt]# cd /opt/php-5.6.11
[root@localhost php-5.6.11]# ./configure \
--prefix=/usr/local/php5 \
--with-gd \
--with-zlib \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-config-file-path=/usr/local/php5 \
--enable-mbstring
[root@localhost php-5.6.11]# make && make install
[root@localhost php-5.6.11]# cp php.ini-development /usr/local/php5/php.ini //对初始化文件进行覆盖,注意路径
[root@localhost php-5.6.11]# ln -s /usr/local/php5/bin/* /usr/local/bin/ //建立PHP命令软链接
[root@localhost php-5.6.11]# ln -s /usr/local/php5/sbin/* /usr/local/sbin/
among them,
--prefix = / usr / local / php5: PHP tool mounting path specified
--with-gd: gd library, a patterning process for
--with-zlib: library
--with-apxs2 = / usr / local / httpd / bin / apxs: apache used to provide functional modules
--with-mysql = / usr / local / mysql: Installed associated database
--with-config-file-path = / usr / local / php5: PHP configuration associated
--enable-mbstring: loading a functional module
Modify the apache configuration file, and build PHP Home
[root@localhost php-5.6.11]# vim /etc/httpd.conf
按G定位末行,添加
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
搜索DirectoryIndex,更改为
DirectoryIndex index.php index.html
wq保存退出
[root@localhost php-5.6.11]# vim /usr/local/httpd/htdocs/index.php //PHP主页
按i进行添加
<?php
phpinfo();
?>
wq保存退出
[root@localhost php-5.6.11]# service httpd restart //重启httpd服务
Verify PHP pages
In the browser, enter the 192.168.116.131/index.php
following pages can appear deemed successful
Third, the installation Discuz Forum (open forum)
Source Forum will unpack and place to http site
[root@localhost php-5.6.11]# cd /mnt
[root@localhost mnt]# unzip Discuz_X2.5_SC_UTF8.zip -d /opt/Discuz
[root@localhost mnt]# cp -r /opt/Discuz/upload/ /usr/local/httpd/htdocs/bbs //放置于http站点中
Bbs related to the establishment of a database, and set the administrator password
[root@localhost mnt]# mysql -u root -p //进入MySQL数据库,密码为之前设定的
mysql> create database bbs; //在数据库中创建名为bbs的子数据库
mysql> GRANT all ON bbs.* TO 'zhy'@'%' IDENTIFIED BY '123123'; //对zhy用户进行提权,并设定密码为123123
mysql> flush privileges; //刷新数据库
mysql> quit
[root@localhost mnt]# cd /usr/local/httpd/htdocs/bbs/ //进入bbs目录
[root@localhost bbs]# chown -R daemon ./config/
[root@localhost bbs]# chown -R daemon ./data/
[root@localhost bbs]# chown -R daemon ./uc_client/data/cache/
[root@localhost bbs]# chown -R daemon ./uc_server/data/
//为各程序用户提升权限
Forum installation complete
In the browser input 192.168.116.131/bbs
, you can enter the installation process
and then to complete the installation.
Fourth, the small text at the end welfare
Can see here, there did not feel bored? Is there a key can be fully automated, free installation process interaction?
The answer of course is yes!
Shell scripts are as follows:
#!/bin/bash
#一键自动构建LAMP架构(请使用source执行或者使用.命令执行)
#数据库默认密码为123123
#远程挂载
df -hT | grep -o "cifs"
if [ $? -ne 0 ];then
echo "Start mount"
yum install expect -y
read -p "请输入提供硬盘主机IP:" gongip
/usr/bin/expect <<-EOF
spawn mount.cifs //$gongip/LAMP-C7 /mnt/
expect {
"Password*"
{send "\r"}
}
expect eof
EOF
fi
#安装apache服务
cd /mnt/
tar zxf apr-1.6.2.tar.gz -C /opt
tar zxf apr-util-1.6.0.tar.gz -C /opt/
tar jxf httpd-2.4.29.tar.bz2 -C /opt/
cd /opt/
mv apr-1.6.2/ httpd-2.4.29/srclib/apr
mv apr-util-1.6.0/ httpd-2.4.29/srclib/apr-util
yum -y install gcc \
gcc-c++ \
make \
pcre-devel \
expat-devel \
perl
cd /opt/httpd-2.4.29/
./configure --prefix=/usr/local/httpd \
--enable-so \
--enable-rewrite \
--enable-charset-lite \
--enable-cgi
make && make install
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
sed -i -e '2a# chkconfig: 35 85 21\n# description: Apache is a World Wide Web server' /etc/init.d/httpd
chkconfig --add httpd
sed -i -e '197d' -e '196aServerName www.kgc.com:80' /usr/local/httpd/conf/httpd.conf
ip=`ifconfig ens33 | awk 'NR==2{print $2}'`
sed -i -e '52s/^/#/' -e '51d' -e "50aListen $ip:80" /usr/local/httpd/conf/httpd.conf
ln -s /usr/local/httpd/conf/httpd.conf /etc/
ln -s /usr/local/httpd/bin/* /usr/local/bin/
systemctl stop firewalld.service
setenforce 0
service httpd start
netstat -ntuap | grep httpd
if [ $? -eq 0 ];then
echo Apache服务启动
else
echo 启动失败
exit 1
fi
#安装mysql服务
echo "================================="
echo "安装mysql数据库,请稍后。。。"
sleep 3
yum install -y ncurses-devel autoconf cmake
cd /mnt/
tar zxf mysql-5.6.26.tar.gz -C /opt/
cd /opt/mysql-5.6.26
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DEXTRA_CHARSETS=all \
-DSYSCONFIDIR=/etc \
-DMYSQL_DATADIR=/home/mysql/ \
-DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock
echo "进行编译安装,要很久,请稍后。。。"
make && make install
cp support-files/my-default.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add /etc/init.d/mysqld
chkconfig --level 235 mysqld on
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
echo $PATH | grep -o "mysql"
if [ $? -eq 0 ];then
echo "添加成功"
else
echo "失败"
exit 1
fi
useradd -s /sbin/nologin mysql
chown -R mysql:mysql /usr/local/mysql/
/usr/local/mysql/scripts/mysql_install_db \
--user=mysql \
--ldata=/var/lib/mysql \
--basedir=/usr/local/mysql \
--datadir=/home/mysql
sed -i -e '47d' -e '46d' -e '45abasedir=/usr/local/mysql\ndatadir=/home/mysql' /etc/init.d/mysqld
service mysqld start
netstat -ntuap | grep mysqld
if [ $? -eq 0 ];then
echo Mysql数据库启动
else
echo 启动失败
exit 1
fi
/usr/bin/expect <<EOF
spawn mysqladmin -u root -p password 123123
expect {
"Enter*"
{send "\r"}
}
expect eof
EOF
#安装PHP工具
yum install -y gd \
libpng \
libpng-devel \
pcre \
pcre-devel \
libxml2-devel \
libjpeg-devel
cd ~
tar jxf /mnt/php-5.6.11.tar.bz2 -C /opt/
cd /opt/php-5.6.11
./configure \
--prefix=/usr/local/php5 \
--with-gd \
--with-zlib \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-mysql=/usr/local/mysql \
--with-config-file-path=/usr/local/php5 \
--enable-mbstring
make && make install
cp -p php.ini-development /usr/local/php5/php.ini
ln -s /usr/local/php5/bin/* /usr/local/bin/
sed -i '393a AddType application/x-httpd-php .php\n AddType application/x-httpd-php-source .phps' /usr/local/httpd/conf/httpd.conf
sed -i -e '256d' -e '255aDirectoryIndex index.html index.php' /usr/local/httpd/conf/httpd.conf
cat > /usr/local/httpd/htdocs/index.php <<-EOF
<?php
phpinfo();
?>
EOF
service httpd stop
service httpd start
rm -rf /opt/*
umount /mnt
echo "LAMP架构完成。脚本执行结束~~~~"