摘要:centos7
编译安装lamp
;实现多虚拟主机wordpress
,discuz
;一键编译安装lamp
脚本
centos7 编译安装lamp
源码获取
$ wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.6.3.tar.gz
$ wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
$ wget https://archive.apache.org/dist/httpd/httpd-2.4.33.tar.bz2
$ wget http://mirrors.sohu.com/php/php-7.1.18.tar.bz2
$ wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
$ wget http://download.comsenz.com/DiscuzX/3.3/Discuz_X3.3_SC_UTF8.zip
$ wget ftp://172.20.0.1/pub/Sources/sources/mariadb/mariadb-10.2.15-linux-x86_64.tar.gz
相关依赖安装
#包组依赖
yum groupinstall 'Development Tools'
#httpd依赖
yum install pcre-devel apr-devel apr-util-devel openssl-devel -y
#php依赖
yum install libxml2-devel bzip2-devel libmcrypt-devel -y
编译安装httpd
$ tar xf apr-1.6.3.tar.gz
$ tar xf apr-util-1.6.1.tar.gz
$ tar xf httpd-2.4.33.tar.bz2
$ mv apr-1.6.3 httpd-2.4.33/srclib/apr
$ mv apr-util-1.6.1 httpd-2.4.33/srclib/apr-util/
$ ./configure --prefix=/app/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-included-apr \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
$ make -j4 && make install
mariadb二进制安装
可以参考博主前面mysql博文,数据库的路径规划为/data/mysqld
。
$ id mysql &> /dev/null || useradd -r -d /data/mysqldb -s /sbin/nologin mysql
$ mkdir /data/mysqldb -pv && chown mysql.mysql /data/mysqldb && chmod 770 /data/mysqldb
$ tar xf mariadb-10.2.15-linux-x86_64.tar.gz -C /usr/local
$ cd /usr/local
$ ln -s mariadb-10.2.15-linux-x86_64/ mysql && chown -R root:mysql /usr/local/mysql/
$ cd /usr/local/mysql/
$ scripts/mysql_install_db --datadir=/data/mysqldb --user=mysql
$ cp /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf
$ sed -i '/\[mysqld\]/a\datadir=/data/mysqldb' /etc/my.cnf
$ cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
$ service mysqld start
$ mysql -e 'create database wpdb'
$ mysql -e "grant all on wpdb.* to wpuser@'192.168.1.%' identified by 'centos'"
编译安装fastcgi模式php
$ tar xvf php-7.1.18.tar.bz2
$ cd php-7.1.18/
./configure --prefix=/app/php \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-openssl \
--with-pdo-mysql=mysqlnd \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-sockets \
--enable-fpm \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-maintainer-zts \
--disable-fileinfo
$ cp php.ini-production /etc/php.ini
$ cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
$ chmod +x /etc/init.d/php-fpm
$ cd /app/php/etc
$ cp php-fpm.conf.default php-fpm.conf
$ cp php-fpm.d/www.conf.default php-fpm.d/www.conf
$ vim php-fpm.d/www.conf
user = apache
group = apache
$ service php-fpm start
配置httpd支持php
$ vim /app/httpd24/conf/httpd.conf
#取消下面两行的注释
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
#修改下面行
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
加下面四行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1
安装wrodpress
$ tar xf wordpress-4.9.4-zh_CN.tar.gz
$ mv wordpress/* /app/httpd24/htdocs/
$ cd /app/httpd24/htdocs/
$ cp wp-config-sample.php wp-config.php
$ vim wp-config.php
/** WordPress数据库的名称 */
define('DB_NAME', 'wpdb');
/** MySQL数据库用户名 */
define('DB_USER', 'wpuser');
/** MySQL数据库密码 */
define('DB_PASSWORD', 'centos');
/** MySQL主机 */
define('DB_HOST', '192.168.1.8');
ab压力测试
$ ab -c 10 -n 100 http://192.168.1.8/
This is ApacheBench, Version 2.3 <$Revision: 1826891 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 192.168.1.8 (be patient).....done
Server Software: Apache/2.4.33
Server Hostname: 192.168.1.8
Server Port: 80
Document Path: /
Document Length: 52796 bytes
Concurrency Level: 10
Time taken for tests: 6.137 seconds
Complete requests: 100
Failed requests: 0
Total transferred: 5304400 bytes
HTML transferred: 5279600 bytes
Requests per second: 16.30 [#/sec] (mean)
Time per request: 613.674 [ms] (mean)
Time per request: 61.367 [ms] (mean, across all concurrent requests)
Transfer rate: 844.11 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 1.0 0 10
Processing: 171 579 106.5 579 772
Waiting: 155 567 105.9 564 753
Total: 171 579 106.5 579 772
Percentage of the requests served within a certain time (ms)
50% 579
66% 624
75% 655
80% 664
90% 702
95% 723
98% 759
99% 772
100% 772 (longest request)
You have mail in /var/spool/mail/root
结论:编译安装的php-fpm
的php执行速度的确比yum
一键安装的速度要块。
安装discuz
$ wget http://download.comsenz.com/DiscuzX/3.3/Discuz_X3.3_SC_UTF8.zip
$ unzip Discuz_X3.3_SC_UTF8.zip
$ cd upload/
$ cp -r * /data/www/
$ cd /data/www
$ setfacl -R -m u:apache:rwx /data/www
$ setfacl -R -b /data/www/ #完成discuz设置后取消acl权限。
配置httpd的多虚拟主机
在这之前,必须先把主配置文件的/app/httpd24/conf/httpd.conf,
,前面配置wordpress
时候加的代理去掉,如下
$ vim /app/httpd24/conf/httpd.conf
Include conf/extra/httpd-vhosts.conf #去掉注释。并将这四条注释掉,刚加的
#AddType application/x-httpd-php .php
#AddType application/x-httpd-php-source .phps
#ProxyRequests Off
#ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1
$ vim /app/httpd24/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot "/app/httpd24/htdocs"
ServerName www.blog.com
ErrorLog "logs/blog.com.error_log"
TransferLog "logs/blog.com-access_log"
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1
<directory /app/httpd24/htdocs>
require all granted
</directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/www"
ServerName www.bbs.com
ErrorLog "logs/bbs.com.error_log"
TransferLog "logs/bbs.com-access_log"
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*.php)$ fcgi://127.0.0.1:9000/data/www/$1
<directory /data/www>
require all granted
</directory>
</VirtualHost>
$ apachectl restart
至此,实现了lamp
的多虚拟主机的wordpress
和discuz
的php应用。
一键安装lamp+wordpress+discuz脚本
博主无聊花了一个小时,写了一个编译安装lamp+wordpress+discuz
的脚本。可以供centos6
和centos7
试验,已成功,代码如下,喜欢自取。
$cat lamp.sh
#!/bin/bash
#
#********************************************************************
#Author: LouiseHong
#QQ: 992165098
#Date: 2018-06-03
#FileName: lamp.sh
#URL: http://fenghong.tech/
#Description: The test script
#Copyright (C): 2018 All rights reserved
#********************************************************************
#CentOS release 6.9 (Final)
#kenerl 2.6.32-696.el6.x86_64
#------------------
#soruce
#------------------
# apr-1.6.3
# apr-util-1.6.1
# httpd-2.4.33
# php-7.1.18
# mariadb-10.2.15-linux-x86_64
# wordpress-4.9.4-zh_CN
# Discuz_X3.3_SC_UTF8
function print_info(){
echo '##################show_info##############'
echo '#Author: LouiseHong # '
echo '#QQ: 992165098 # '
echo '#Date: 2018-06-03 # '
echo '#FileName: lamp.sh # '
echo -e '\033[1;31m#URL: http://fenghong.tech/ #\033[0m'
echo '######show install version and app#######'
echo '# apr-1.6.3 #'
echo '# apr-util-1.6.1 #'
echo '# httpd-2.4.33 #'
echo '# php-7.1.18 #'
echo '# mariadb-10.2.15-linux-x86_64 #'
echo '# wordpress-4.9.4-zh_CN #'
echo '# Discuz_X3.3_SC_UTF8 #'
echo '#########################################'
echo -e '\033[1;32m#press any key to start..ctrl+C to break#\033[0m'
echo '#########################################'
}
check() {
if [ $? -eq 0 ];then
echo -e '\033[1;32mOK\033[0m'
else
echo -e '\033[1;31mError\033[0m'
exit
fi
}
#----Dependace Install
function install_dev() {
yum groupinstall 'Development Tools' -y
check
yum install pcre-devel apr-devel apr-util-devel openssl-devel -y
check
yum install libxml2-devel bzip2-devel libmcrypt-devel -y
check
}
#--------------------
#Source Get
function source_wget() {
cd ${dir}
[ -f apr-1.6.3.tar.gz ] || wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.6.3.tar.gz
check
[ -f apr-util-1.6.1.tar.gz ] || wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
check
[ -f httpd-2.4.33.tar.bz2 ] || wget https://archive.apache.org/dist/httpd/httpd-2.4.33.tar.bz2
check
[ -f php-7.1.18.tar.bz2 ] || wget http://mirrors.sohu.com/php/php-7.1.18.tar.bz2
check
[ -f wordpress-4.9.4-zh_CN.tar.gz ] || wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
check
[ -f Discuz_X3.3_SC_UTF8.zip ]|| wget http://download.comsenz.com/DiscuzX/3.3/Discuz_X3.3_SC_UTF8.zip
check
#[ -f mariadb-10.2.15-linux-x86_64.tar.gz ] || wget https://downloads.mariadb.org/f/mariadb-10.2.15/bintar-linux-x86_64/mariadb-10.2.15-linux-x86_64.tar.gz/from/http%3A//mirrors.tuna.tsinghua.edu.cn/mariadb/?serve
[ -f mariadb-10.2.15-linux-x86_64.tar.gz ] || wget ftp://172.20.0.1/pub/Sources/sources/mariadb/mariadb-10.2.15-linux-x86_64.tar.gz
check
}
#--------------------
#-------Install Httpd
function install_httpd() {
cd ${dir}
id apache &> /dev/null || useradd -r -d /app/httpd24 -s /sbin/nologin apache
tar xf apr-1.6.3.tar.gz
tar xf apr-util-1.6.1.tar.gz
tar xf httpd-2.4.33.tar.bz2
mv apr-1.6.3 httpd-2.4.33/srclib/apr
mv apr-util-1.6.1 httpd-2.4.33/srclib/apr-util/
cd httpd-2.4.33/
./configure --prefix=/app/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-included-apr \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
check
make -j $cpus && make install
check
}
#-------Install MariaDB
function install_mariadb() {
cd ${dir}
id mysql &> /dev/null || useradd -r -d /app/mysqldb -s /sbin/nologin mysql
mkdir /app/mysqldb -pv && chown mysql.mysql /app/mysqldb && chmod 770 /app/mysqldb
tar xf mariadb-10.2.15-linux-x86_64.tar.gz -C /usr/local
cd /usr/local
ln -s mariadb-10.2.15-linux-x86_64/ mysql && chown -R root:mysql /usr/local/mysql/
}
function install_mariadb_conf() {
cd /usr/local/mysql/
scripts/mysql_install_db --datadir=/app/mysqldb --user=mysql
check
cp -f /usr/local/mysql/support-files/my-huge.cnf /etc/my.cnf
sed -i '/\[mysqld\]/adatadir=/app/mysqldb' /etc/my.cnf
[ -f /etc/init.d/mysqld ] || cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
}
#-------Install php
function install_php() {
cd ${dir}
tar xf php-7.1.18.tar.bz2
cd php-7.1.18/
./configure --prefix=/app/php \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-openssl \
--with-pdo-mysql=mysqlnd \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-sockets \
--enable-fpm \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-maintainer-zts \
--disable-fileinfo
check
make -j $cpus && make install
check
}
function install_php_conf() {
cd ${dir}/php-7.1.18/
cp -f php.ini-production /etc/php.ini
cp -f sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
cp /app/php/etc/php-fpm.conf.default /app/php/etc/php-fpm.conf
cp /app/php/etc/php-fpm.d/www.conf.default /app/php/etc/php-fpm.d/www.conf
sed -i 's/nobody/apache/g' /app/php/etc/php-fpm.d/www.conf
}
#--------install_wordpress
function install_wordpress_conf() {
cd ${dir}
tar xf wordpress-4.9.4-zh_CN.tar.gz
check
mv wordpress/* /app/httpd24/htdocs/
cd /app/httpd24/htdocs/
chown -R apache.apache *
cp wp-config-sample.php wp-config.php
sed -i "s/database_name_here/wpdb/" wp-config.php
sed -i "s/username_here/wpuser/" wp-config.php
sed -i "s/password_here/centos/" wp-config.php
}
function install_discuz_conf() {
[ -d /app/www ] || mkdir /app/www -pv
cd ${dir}
unzip Discuz_X3.3_SC_UTF8.zip
check
cp -r upload/* /app/www/
}
function install_httpd_conf() {
sed -i '$aInclude conf/extra/httpd-test.conf' /app/httpd24/conf/httpd.conf
sed -i 's/daemon/apache/g' /app/httpd24/conf/httpd.conf
cat >> /app/httpd24/conf/extra/httpd-test.conf <<-EOF
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
<VirtualHost *:80>
DocumentRoot "/app/httpd24/htdocs"
ServerName www.blog.com
ErrorLog "logs/blog.com.error_log"
TransferLog "logs/blog.com-access_log"
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/\$1
<directory /app/httpd24/htdocs>
require all granted
</directory>
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/app/www"
ServerName www.bbs.com
ErrorLog "logs/bbs.com.error_log"
TransferLog "logs/bbs.com-access_log"
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*.php)$ fcgi://127.0.0.1:9000/app/www/\$1
<directory /app/www>
require all granted
</directory>
</VirtualHost>
EOF
check
sed -i '$a/app/httpd24/bin/apachectl start' /etc/rc.d/rc.local
}
function install_lamp(){
[ -d ${dir} ] || mkdir ${dir} -pv &> /dev/null
install_dev
source_wget
install_httpd
install_mariadb
install_mariadb_conf
install_php
install_php_conf
install_wordpress_conf
install_discuz_conf
install_httpd_conf
/app/httpd24/bin/apachectl restart
service php-fpm restart
service mysqld restart
/usr/local/mysql/bin/mysql -e 'create database IF NOT EXISTS wpdb'
/usr/local/mysql/bin/mysql -e "grant all on wpdb.* to wpuser@'localhost' identified by 'centos'"
echo "PATH=/app/php/bin:/app/php/sbin:/app/httpd24/bin:/usr/local/mysql/bin:$PATH" > /etc/profile.d/lamp.sh
chkconfig --add mysqld
chkconfig --add php-fpm
}
test_lamp(){
cat >> /app/httpd24/htdocs/test.php <<-EOF
<?php
\$dsn='mysql:host=127.0.0.1;dbname=mysql';
\$username='root';
\$passwd='';
\$dbh=new PDO(\$dsn,\$username,\$passwd);
var_dump(\$dbh);
?>
EOF
curl 127.0.0.1/test.php |grep -q PDO && echo -e "\033[32mLAMP Test Completed, Is Working!\033[0m" || echo -e "\033[31mSorry, Test failed, Please check!\033[0m"
}
cpus=`cat /proc/cpuinfo |grep processor|wc -l`
dir='/app/sours'
trap 'exit' 2
clear
print_info 2>&1 | tee -a ${dir}/install.log
read -p ''
install_lamp 2>&1 | tee -a ${dir}/install.log
test_lamp
运行./lamp
完成后,试验端口是否开启。访问http://localhost/
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message
httpd not running, trying to start
httpd not running, trying to start
Gracefully shutting down php-fpm warning, no pid file found - php-fpm is not running ?
Starting php-fpm done
ERROR! MariaDB server PID file could not be found!
Starting MariaDB180623 20:37:04 mysqld_safe Logging to '/app/mysqldb/localhost.localdomain.err'.
.180623 20:37:04 mysqld_safe Starting mysqld daemon with databases from /app/mysqldb
.. SUCCESS!
$ss -ntl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 127.0.0.1:9000 *:*
LISTEN 0 80 :::3306 :::*
LISTEN 0 128 :::80