准备软件版本:
apr-1.5.2.tar.bz2 apr-util-1.5.4.tar.bz2 httpd-2.4.27.tar.bz2 mariadb-5.5.57-linux-x86_64.tar.gz (二进制) php-5.6.31.tar.bz2 xcache-3.2.0.tar.gz wordpress-4.8-zh_CN.tar.gz
一. 源码编译安装 httpd2.4
1.准备编译环境安装
yum groupinstall "development tools" -y yum install openssl-devel expat-devel pcre-devel -y
2.准备安装包及文件
tar xf apr-1.5.2.tar.bz2 tar xf apr-util-1.5.4.tar.bz2 tar xvf httpd-2.4.27.tar.bz2 cp -r apr-1.5.2 httpd-2.4.27/srclib/apr cp -r apr-util-1.5.4 httpd-2.4.27/srclib/apr-util cd httpd-2.4.27/
3.开始编译安装
./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
4.配置httpd管理命令路径
vim /etc/profile.d/lamp.sh PATH=/app/httpd24/bin/:$PATH . /etc/profile.d/lamp.sh
5.配置服务脚本并启动
cp /etc/init.d/httpd /etc/init.d/httpd24 #如没有httpd可从其他主机拷贝过来 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
二. 二进制安装及配置 mariadb
1.二进制安装mariadb
yum remove mysql -y #centos6默认安装mysql并创建了用户名,安装较新版mariadb避免冲突要卸载mysql 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 chown -R root:mysql mysql/ cd mysql/ scripts/mysql_install_db --datadir=/app/mysqldb --user=mysql #创建数据库文件
2.配置 mariadb 配置文件
mkdir /etc/mysql cp support-files/my-large.cnf /etc/mysql/my.cnf vim /etc/mysql/my.cnf #在[mysqld]下添加如下三条配置 [mysqld] datadir = /app/mysqldb innodb_file_per_table = ON skip_name_resolve = ON
3.配置服务脚本并启动
cp support-files/mysql.server /etc/init.d/mysqld chkconfig --add mysqld chkconfig --list
4.配置日志文件
touch /var/log/mysqld.log chown mysql /var/log/mysqld.log service mysqld start
5.配置命令路径
vi /etc/profile.d/lamp.sh PATH=/usr/local/mysql/bin/:/app/http24/bin:$PATH . /etc/profile.d/lamp.sh
6.安全初始化及创建用户、数据库文件
mysql_secure_installation mysql -uroot -pcentos create database wpdb; grant all on wpdb.* to wpuser@'%' identified by 'centos';
三. 编译安装 PHP 及配置
1.编译前准备
yum install libxml2-devel bzip2-devel libmcrypt-devel(在epepl源) tar xvf php-5.6.31.tar.xz cd php-5.6.31
2.开始编译
./configure \ --prefix=/app/php5 \ --with-mysql=/usr/local/mysql \ --with-openssl \ --with-mysqli=/usr/local/mysql/bin/mysql_config \ --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/php5 \ --with-config-file-scan-dir=/etc/php5.d \ --with-bz2 make -j 4 && make install
3.配置命令路径
vi /etc/profile.d/lamp.sh PATH=/app/php5/bin:/app/httpd24/bin/:/usr/local/mysql/bin/:$PATH . /etc/profile.d/lamp.sh
4.准备配置文件及服务脚本文件
mkdir /etc/php5/ cp php.ini-production /etc/php5/php.ini 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 cd /app/php5/etc cp php-fpm.conf.default php-fpm.conf
5.编辑httpd相关配置参数
vim /etc/httpd24/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 httpd24 restart
6.编辑主页文件测试数据库是否连接
vim /app/httpd24/htdocs/index.php <html><body><h1>It works!</h1></body></html> <?php $mysqli=new mysqli("localhost","root","centos"); if(mysqli_connect_errno()){ echo "连接数据库失败!"; $mysqli=null; exit; } echo "连接数据库成功!"; $mysqli->close(); $conn = mysql_connect('localhost','root','centos'); if ($conn) echo "OK"; else echo "Failure"; mysql_close(); phpinfo(); ?>
四. 配置WordPress
1.安装
tar xvf wordpress-4.8.1-zh_CN.tar.gz -C /app/httpd24/htdocs cd /app/httpd24/htdocs mv wordpress/ blog/ cd /app/httpd24/htdocs/blog/ cp wp-config-sample.php wp-config.php
2.编辑配置文件
vim wp-config.php define('DB_NAME', 'wpdb'); /** MySQL数据库用户名 */ define('DB_USER', 'wpuser'); /** MySQL数据库密码 */ define('DB_PASSWORD', 'centos'); /** MySQL主机 */ define('DB_HOST', 'localhost');
3.登录主机测试
http://websrv/blog #配置用户信息 测试性能 ab -c 10 -n 100 http://websrv/blog/
五. 编译xcache 实现Php加速
1.编译安装准备
tar xvf xcache-3.2.0.tar.bz2 cd xcache-3.2.0 phpize #生成configure文件
2.编译安装
./configure --enable-xcache --with-php-config=/app/php/bin/php-config make && make install
3.编辑配置文件
mkdir /etc/php.d/ cp xcache.ini /etc/php.d/ vim /etc/php.d/xcache.ini extension = /app/php/lib/php/extensions/no-debug-non-zts-20131226/xcache.so service php-fpm restart
4.测试性能
ab -c 10 -n 100 http://websrv/blog/