Linux初学者学习笔记

20171011 LAMP(二)

2017-10-16  本文已影响9人  哈喽别样
  • CentOS 7.3环境LAMP源码编译安装WordPress
  • CentOS 6.9环境LAMP源码编译安装WordPress(php module模式)
  • CentOS 6.9环境LAMP源码编译安装WordPress(php fpm模式)

一、CentOS 7.3环境LAMP源码编译安装WordPress

(一)环境准备

(二)源码编译安装httpd2.4

yum groupinstall "development tools"
yum install openssl-devel expat-devel pcre-devel
tar xvf apr-1.6.2.tar.gz -C /usr/local/src
tar xvf apr-util-1.6.0.tar.gz  -C /usr/local/src
tar xvf httpd-2.4.27.tar.bz -C /usr/local/src
cd /usr/local/src
cp -r apr-1.6.2 httpd-2.4.27/srclib/apr
cp -r apr-util-1.6.0 httpd-2.4.27/srclib/apr-util
cd httpd-2.4.27/
./configure --prefix=/app/httpd24 --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
make -j 4 && make install
vim /etc/profile.d/lamp.sh
PATH=/app/httpd24/bin/:$PATH
. /etc/profile.d/lamp.sh
apachectl start
ss -ntlp
vim /etc/rc.d/rc.local
/app/httpd24/bin/apachectl start
chmod +x /etc/rc.d/rc.local
vim /etc/man_db.conf
MANDATORY_MANPATH    /app/httpd24/man

(三)二进制安装MariaDB

tar xvf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local
cd /usr/local/
ln -s mariadb-10.2.8-linux-x86_64/ mysql
useradd -r -d /app/mysqldb -s /sbin/nologin mysql -m
cd mysql/
scripts/mysql_install_db  --datadir=/app/mysqldb --user=mysql
mkdir /etc/mysql
cp support-files/my-large.cnf /etc/mysql/my.cnf
vim /etc/mysql/my.cnf
[mysqld]     //添加以下三行
datadir = /app/mysqldb
innodb_file_per_table = ON
skip_name_resolve = ON
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
mkdir /var/log/mariadb
chown mysql /var/log/mariadb/
service mysqld start
ss -ntlp
vim /etc/profile.d/lamp.sh
PATH=/usr/local/mysql/bin:$PATH
source /etc/profile.d/lamp.sh 
mysql_secure_installation

mysql -uroot -p
MariaDB [(none)]> create database wpdb;
MariaDB [(none)]> grant all on wpdb.* to wpadmin@'192.168.136.%' identified by 'centos';
MariaDB [(none)]> grant all on wpdb.* to wpadmin@'127.%' identified by 'centos';
MariaDB [(none)]> grant all on wpdb.* to wpadmin@'localhost' identified by 'centos';

(四)源码编译安装php

yum install libxml2-devel bzip2-devel libmcrypt-devel
tar xvf php-7.1.10.tar.xz -C /usr/local/src/
cd /usr/local/src/php-7.1.10/
./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 --with-apxs2=/app/httpd24/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-maintainer-zts --disable-fileinfo
make -j 4 && make install
cp php.ini-production /etc/php.ini

vim /etc/httpd24/httpd.conf
// 在文件尾部加两行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
// 修改下面行
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

apachectl stop
apachectl start
ss -ntlp

(五)测试php与MariaDB的连接

vim /app/httpd24/htdocs/index.php
<?php
$mysqli=new mysqli("192.168.136.230","wpadmin","centos");
if(mysqli_connect_errno()){
echo "连接数据库失败!";
$mysqli=null;
exit;
}
echo "连接数据库成功!";
$mysqli->close();
phpinfo();
?>

(六)安装配置WordPress

tar -xvf wordpress-4.8.1-zh_CN.tar.gz -C /app/httpd24/htdocs/
cd /app/httpd24/htdocs/
ln -s wordpress/ blog
cd blog/
cp wp-config-sample.php wp-config.php
vim wp-config.php
// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'wpdb');

/** MySQL数据库用户名 */
define('DB_USER', 'wpadmin');

/** MySQL数据库密码 */
define('DB_PASSWORD', 'centos');

/** MySQL主机 */
define('DB_HOST', '192.168.136.230');

二、CentOS 6.9环境LAMP源码编译安装WordPress(php module模式)

(一)环境准备

(二)源码编译安装httpd2.4

yum groupinstall "development tools"
yum install openssl-devel expat-devel pcre-devel
tar xvf apr-1.6.2.tar.gz -C /usr/local/src
tar xvf apr-util-1.6.0.tar.gz  -C /usr/local/src
tar xvf httpd-2.4.27.tar.bz -C /usr/local/src
cd /usr/local/src
cp -r apr-1.6.2 httpd-2.4.27/srclib/apr
cp -r apr-util-1.6.0 httpd-2.4.27/srclib/apr-util
cd httpd-2.4.27/
./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
make -j 4 && make install
vim /etc/profile.d/lamp.sh
PATH=/app/httpd24/bin/:$PATH
. /etc/profile.d/lamp.sh
scp /etc/init.d/httpd  192.168.136.129:/etc/init.d/httpd24    //从其他主机复制脚本进行修改
vim /etc/init.d/httpd24
apachectl=/app/httpd24/bin/apachectl
httpd=${HTTPD-/app/httpd24/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/app/httpd24/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}

chkconfig --add httpd24
chkconfig --list httpd24
service httpd24 start
ss -ntlp
vim /etc/man.config
MANPATH /app/httpd24/man

(三)二进制安装MariaDB

tar xvf mariadb-5.5.57-linux-x86_64.tar.gz -C /usr/local
cd /usr/local/
ln -s mariadb-5.5.57-linux-x86_64/ mysql
useradd -r -d /app/mysqldb -s /sbin/nologin mysql -m
cd mysql/
scripts/mysql_install_db  --datadir=/app/mysqldb --user=mysql
mkdir /etc/mysql
cp support-files/my-large.cnf /etc/mysql/my.cnf
vim /etc/mysql/my.cnf
[mysqld]     //添加以下三行
datadir = /app/mysqldb
innodb_file_per_table = ON
skip_name_resolve = ON
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
touch /var/log/mysqld.log
chown mysql /var/log/mysqld.log
service mysqld start
ss -ntlp
vim /etc/profile.d/lamp.sh
PATH=/usr/local/mysql/bin:$PATH
source /etc/profile.d/lamp.sh 
mysql_secure_installation

mysql -uroot -p
MariaDB [(none)]> create database wpdb;
MariaDB [(none)]> grant all on wpdb.* to wpadmin@'192.168.136.%' identified by 'centos';
MariaDB [(none)]> grant all on wpdb.* to wpadmin@'127.%' identified by 'centos';
MariaDB [(none)]> grant all on wpdb.* to wpadmin@'localhost' identified by 'centos';

(四)源码编译安装php

yum install libxml2-devel bzip2-devel libmcrypt-devel
tar xvf php-5.6.4.tar.xz -C /usr/local/src/
cd /usr/local/src/php-5.6.4/
./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 --with-apxs2=/app/httpd24/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-maintainer-zts --disable-fileinfo
make -j 4 && make install
vim /etc/profile.d/lamp.sh
PATH=/app/php/bin:/app/httpd24/bin:$PATH
source /etc/profile.d/lamp.sh
cp php.ini-production /etc/php.ini

vim /app/httpd24/conf/httpd.conf
// 在文件尾部加两行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
// 修改下面行
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

service httpd24 restart
ss -ntlp

(五)测试php与MariaDB的连接

vim /app/httpd24/htdocs/index.php
<?php
$mysqli=new mysqli("192.168.136.229","wpadmin","centos");
if(mysqli_connect_errno()){
echo "连接数据库失败!";
$mysqli=null;
exit;
}
echo "连接数据库成功!";
$mysqli->close();
phpinfo();
?>

(六)安装配置WordPress

tar -xvf wordpress-4.8.1-zh_CN.tar.gz -C /app/httpd24/htdocs/
cd /app/httpd24/htdocs/
ln -s wordpress/ blog
cd blog/
cp wp-config-sample.php wp-config.php
vim wp-config.php
// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'wpdb');

/** MySQL数据库用户名 */
define('DB_USER', 'wpadmin');

/** MySQL数据库密码 */
define('DB_PASSWORD', 'centos');

/** MySQL主机 */
define('DB_HOST', '192.168.136.229');

(七)编译安装xcache

tar xvf xcache-3.2.0.tar.bz2 -C /usr/local/src
cd /usr/local/src/xcache-3.2.0/
phpize     //生成configure文件
./configure  --enable-xcache --with-php-config=/app/php/bin/php-config
make && make install
mkdir /etc/php.d
cp xcache.ini /etc/php.d/
vim /etc/php.d/xcache.ini
extension = /app/php/lib/php/extensions/no-debug-zts-20131226/xcache.so

service httpd24 restart

三、CentOS 6.9环境LAMP源码编译安装WordPress(php fpm模式)

(一)环境准备

(二)源码编译安装httpd2.4

yum groupinstall "development tools"
yum install openssl-devel expat-devel pcre-devel
tar xvf apr-1.6.2.tar.gz -C /usr/local/src
tar xvf apr-util-1.6.0.tar.gz  -C /usr/local/src
tar xvf httpd-2.4.27.tar.bz -C /usr/local/src
cd /usr/local/src
cp -r apr-1.6.2 httpd-2.4.27/srclib/apr
cp -r apr-util-1.6.0 httpd-2.4.27/srclib/apr-util
cd httpd-2.4.27/
./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-rewrite --with-zlib --with-pcre --with-included-apr --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork
make -j 4 && make install
vim /etc/profile.d/lamp.sh
PATH=/app/httpd24/bin/:$PATH
. /etc/profile.d/lamp.sh
scp /etc/init.d/httpd  192.168.136.129:/etc/init.d/httpd24    //从其他主机复制脚本进行修改
vim /etc/init.d/httpd24
apachectl=/app/httpd24/bin/apachectl
httpd=${HTTPD-/app/httpd24/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/app/httpd24/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}

chkconfig --add httpd24
chkconfig --list httpd24
service httpd24 start
ss -ntlp
vim /etc/man.config
MANPATH /app/httpd24/man

(三)二进制安装MariaDB

tar xvf mariadb-5.5.57-linux-x86_64.tar.gz -C /usr/local
cd /usr/local/
ln -s mariadb-5.5.57-linux-x86_64/ mysql
useradd -r -d /app/mysqldb -s /sbin/nologin mysql -m
cd mysql/
scripts/mysql_install_db  --datadir=/app/mysqldb --user=mysql
mkdir /etc/mysql
cp support-files/my-large.cnf /etc/mysql/my.cnf
vim /etc/mysql/my.cnf
[mysqld]     //添加以下三行
datadir = /app/mysqldb
innodb_file_per_table = ON
skip_name_resolve = ON
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
touch /var/log/mysqld.log
chown mysql /var/log/mysqld.log
service mysqld start
ss -ntlp
vim /etc/profile.d/lamp.sh
PATH=/usr/local/mysql/bin:$PATH
source /etc/profile.d/lamp.sh 
mysql_secure_installation

mysql -uroot -p
MariaDB [(none)]> create database wpdb;
MariaDB [(none)]> grant all on wpdb.* to wpadmin@'192.168.136.%' identified by 'centos';
MariaDB [(none)]> grant all on wpdb.* to wpadmin@'127.%' identified by 'centos';
MariaDB [(none)]> grant all on wpdb.* to wpadmin@'localhost' identified by 'centos';

(四)源码编译安装php

yum install libxml2-devel bzip2-devel libmcrypt-devel
tar xvf php-5.6.4.tar.xz -C /usr/local/src/
cd /usr/local/src/php-5.6.4/
./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-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --enable-maintainer-zts --disable-fileinfo
make -j 4 && make install
vim /etc/profile.d/lamp.sh
PATH=/app/php/bin:/app/httpd24/bin:$PATH
source /etc/profile.d/lamp.sh
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig --list php-fpm

cp php.ini-production /etc/php.ini
cd /app/php/etc/
cp php-fpm.conf.default php-fpm.conf

vim /app/httpd24/conf/httpd.conf
// 取消两行的注释
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
// 在文件尾部加两行
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
// 修改下面行
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

service php-fpm start
service httpd24 restart
ss -ntlp

(五)测试php与MariaDB的连接

vim /app/httpd24/htdocs/index.php
<?php
$mysqli=new mysqli("192.168.136.229","wpadmin","centos");
if(mysqli_connect_errno()){
echo "连接数据库失败!";
$mysqli=null;
exit;
}
echo "连接数据库成功!";
$mysqli->close();
phpinfo();
?>

(六)安装配置WordPress

tar -xvf wordpress-4.8.1-zh_CN.tar.gz -C /app/httpd24/htdocs/
cd /app/httpd24/htdocs/
ln -s wordpress/ blog
cd blog/
cp wp-config-sample.php wp-config.php
vim wp-config.php
// ** MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/** WordPress数据库的名称 */
define('DB_NAME', 'wpdb');

/** MySQL数据库用户名 */
define('DB_USER', 'wpadmin');

/** MySQL数据库密码 */
define('DB_PASSWORD', 'centos');

/** MySQL主机 */
define('DB_HOST', '192.168.136.229');

(七)编译安装xcache

tar xvf xcache-3.2.0.tar.bz2 -C /usr/local/src
cd /usr/local/src/xcache-3.2.0/
phpize     //生成configure文件
./configure  --enable-xcache --with-php-config=/app/php/bin/php-config
make && make install
mkdir /etc/php.d
cp xcache.ini /etc/php.d/
vim /etc/php.d/xcache.ini
extension = /app/php/lib/php/extensions/no-debug-zts-20131226/xcache.so

service php-fpm restart

由此看到:在php_fpm模式下,使用xcache加速效率提升非常明显

上一篇下一篇

猜你喜欢

热点阅读