美文网首页
在centos6.9上实现编译安装lamp和wordpress,

在centos6.9上实现编译安装lamp和wordpress,

作者: 六月天的安静 | 来源:发表于2017-08-09 15:44 被阅读33次

需要的软件包有:

httpd-2.4.27.tar.bz2 
apr-1.5.2.tar.bz2
apr-util-1.5.4.tar.bz2   
mariadb-5.5.57-linux-x86_64.tar.gz
php-5.6.31.tar.bz2   
wordpress-4.8-zh_CN.tar.gz
xcache-3.2.0.tar.bz2 

编译前准备工作

1)关闭SElinux:
[root@centos6:~]# vim /etc/selinux/config 
    SELINUX=disabled

2)关闭防火墙:
[root@centos6 ~]# /etc/init.d/iptables  stop
[root@centos6 ~]# chkconfig iptables off
[root@centos6 ~]# chkconfig --list | grep iptables 

3)修改主机名:
[root@centos6 ~]# hostname centos6.9WebServer
[root@centos6 ~]# vim /etc/sysconfig/network
[root@centos6 ~]# HOSTNAME=centos6.9WebServer
[root@centos6 ~]# vim /etc/hosts
127.0.0.1   centos6.9WebServer localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
这一步改完配置文件需要重新启动


4)安装开发包组:
[root@centos6:~]# yum groupinstall "Development Tools" -y

5)安装需要的包组:
[root@centos6:~]#yum install pcre-devel  openssl-devel

6)新建目录存放下载下来的软件包:
[root@centos6:~]# mkdir src
[root@centos6:~]# cd src
把下载下来的包依次用命令rz导入src目录下:
[root@centos6:src]# rz 
用命令ls查看一下导入的包是否缺少:
[root@centos6:src]# ls

1、编译安装httpd-2.4.27

卸载原有apr

[root@centos6:~src]# yum remove -y apr 

解压:

[root@centos6:src]# tar xvf apr-1.5.2.tar.bz2
[root@centos6:src]# tar xvf apr-util-1.5.4.tar.bz2 
[root@centos6:src]# tar xvf httpd-2.4.27.tar.bz2 
[root@centos6:src]# mv apr-1.5.2 httpd-2.4.27/srclib/apr  //将apr的文件放进httpd文件里面一起安装
[root@centos6:src]# mv apr-util-1.5.4 httpd-2.4.27/srclib/apr-util
[root@centos6:src]# cd httpd-2.4.27
[root@centos6:httpd-2.4.27]#./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
[root@centos6:httpd-2.4.27]# make && make install

配置环境变量, 写一个脚本,把httpd、mariadb放进bin下:

[root@centos6:httpd-2.4.27]# cd /app/httpd24
[root@centos6:httpd24]# vim /etc/profile.d/app.sh
      export PATH=/app/httpd24/bin:/usr/local/mysql/bin:$PATH
[root@centos6:httpd24]# . /etc/profile.d/app.sh   //让其配置文件生效

现在我们可以查看一下apachectl这个服务的路径:

[root@centos6:httpd24]# which apachectl
    /app/httpd24/bin/apachectl

我们来检查一下原来的httpd的状态:

[root@centos6:httpd24]# service httpd status

如果httpd是开启状态你可以使用下面这条命令使其停止:

[root@centos6:httpd24]# service httpd stop

拷贝原来httpd的文件后面做服务器脚本文件:

[root@centos6:httpd24]# cp /etc/init.d/httpd /etc/init.d/httpd24

当然到这里如果原来的httpd你不需要了就可以卸载了:

[root@centos6:httpd24]#yum remove httpd -y

接下来我们需要把刚刚复制下来的文件修改一下:

[root@centos6:httpd24]# vim /etc/init.d/httpd24

修改为:



把httpd24 加入到服务项里:

[root@centos6:httpd24]# chkconfig –add httpd24
[root@centos6:httpd24]# chkconfig –list httpd24

启动服务:

[root@centos6:httpd24]# service httpd24 start

查看端口是否打开:

[root@centos6:httpd24]# ss -ntl

现在我们测试一下是否可以访问:

2、二进制安装mariadb-5.5.57

把目录切换到原来装软件包的src目录下:

[root@centos6:httpd24]# cd /root/src
[root@centos6:src]# ls

解压(必须解压到/usr/local/目录下):

[root@centos6:src]# tar xf mariadb-10.2.7-linux-x86_64.tar.gz  -C /usr/local/

进入解压数据库的文件夹:

[root@centos6:src]# cd /usr/local/

建立软连接(必须名字为mysql):

[root@centos6:local]#ln -s mariadb-10.2.7-linux-x86_64/ mysql

检查是否存在旧版本,若有删除之:

[root@centos6:local]# rpm -qa "mysql*"

删除:

[root@centos6:local]#yum remove "mysql*"

检查一下系统是否有mysql这个用户(我这里已经有了):

[root@centos6:local]# id mysql

准备存放数据库的路径:

[root@centos6:local]# mkdir /app/mysqldb 

改变所有者,所属组:

[root@centos6:local]# chown mysql.mysql /app/mysqldb 

如果没有mysql用户可以用下面的命令创建mysql用户并指定家目录::

[root@centos6:local]# useradd –r  -m –s /sbin/nlogin –d /app/mysqldb  mysql

运行生成数据库的脚本:

[root@centos6:local]# cd mysql
[root@centos6:mysql]# scripts/mysql_install_db --datadir=/app/mysqldb --user=mysql

创建配置目录:

[root@centos6:mysql]# mkdir /etc/mysql/

复制自带的配置模板:

[root@centos6:mysql]# cp support-files/my-large.cnf /etc/mysql/my.cnf

修改模板:

[root@centos6:mysql]# vim /etc/mysql/my.cnf

[mysqld]下面加三行:
  datadir = /app/mysqldb
  innodb_file_per_table = on
  skip_name_resolve = on

复制启动服务模板:

[root@centos6:mysql]# cp support-files/mysql.server  /etc/init.d/mysqld

加入启动项:

[root@centos6:mysql]#chkconfig --add mysqld

查看启动项:

[root@centos6:mysql]# chkconfig --list mysqld

启动服务:

[root@centos6:mysql]# service mysqld start

启动失败,原因缺少日志文件:

创建日志文件:

[root@centos6:mysql]# touch /var/log/mysqld.log
[root@centos6:mysql]# chown mysql /var/log/mysqld.log

然后我们再重新启动服务:

[root@centos6:mysql]# service mysqld start

确认服务启动成功:

[root@centos6:mysql]# ss -ntl

执行mariadb自带的脚本配置安全选项:

[root@centos6:mysql]# mysql_secure_installation

.......
Reload privilege tables now? [Y/n] y

上面数据库已经编译完成,因为我们需要搭建wordpress,需要给wordpress创建对应的数据库和用户:

创建wordpress使用的数据库和用户及用户权限:

[root@centos6:mysql]#mysql -uroot -pmagedu -e "create database blogdb; grant all on blogdb.* to wpuser@'localhost' identified by 'magedu';"
blogdb:这是我们创建的数据库名称。
wpuser:这是我们创建的用户。
blogdb.* :wpuser对数据库blogdb有所有的权限。
localhost:主机。
by 'magedu':by后面跟的是用户wpuser的密码,记住和上面“-u”后面跟的root用户的密码是两回事,只不过我在这里把密码设一样了。

我们在这里使用“-e”选项就不需要进入数据库交互式的执行了,直接在命令行创建数据库以及用户及用户的权限。

测试验证登录成功:

[root@centos6:mysql]# mysql -uwpuser  -pmagedu

如果你不用上面的方法创建wordpress使用的数据库和用户及用户权限,可以使用下面的方法:

用root用户登入mysql:
[root@centos6:mysql]# mysql -uroot -p这里写root的密码

登入成功后创建数据库:
MariaDB [(none)]>  create database blogdb;

创建新的用户和密码并分配权限:
MariaDB [(none)]> grant all on blogdb.* to 新的用户名@'192.168.247.%' identified by  "新的用户名的密码"; 

然后用命令exit退出数据库,用下面这条命令测试验证是否成功:

[root@centos6:mysql]# mysql -u新的用户名  -p新的用户名的密码

3、编译安装php

安装需要的包:

[root@centos6:mysql]# cd
[root@centos6:~]# yum -y install bzip2-devel  libxml2-devel libmcrypt-devel
注意:libmcrypt-devel在epel源里

解压:

[root@centos6:~]# cd src
[root@centos6:src]# tar xvf php-5.6.31.tar.bz2

自定义一些模块的设置:

[root@centos6:src]# cd php-5.6.31
[root@centos6:php-5.6.31]# ./configure --prefix=/app/php --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 --with-apxs2=/app/httpd24/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d  --with-bz2


说明:
./configure 
--prefix=/app/php  php的安装目录
--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  支持文档xml
--enable-xml
--enable-sockets  socket通信
--with-apxs2=/app/httpd24/bin/apxs  将php编译成apache的模块
--with-mcrypt 
--with-config-file-path=/etc  php配置文件路径
--with-config-file-scan-dir=/etc/php.d 也可以作为php配置文件的路径
--with-bz2  

--enable-maintainer-zts  用于支持worker和event模块,如果prefork不需要

编译安装:

[root@centos6:php-5.6.31]# make -j 4 && make install

复制一份配置文件去修改:

[root@centos6:php-5.6.31]# cp php.ini-production /etc/php.ini

4、配置httpd2.4支持php

进入配置文件:

[root@centos6:php-5.6.31]#vim /app/httpd24/conf/httpd.conf

添加的内容:

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    找到上面两行下面添加下面两行
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
     
     修改:
    <IfModule dir_module>
    DirectoryIndex index.php index.html
    </IfModule>

重启服务:

[root@centos6:php-5.6.31]# service httpd24 restart

或者用下面的命令重启服务:

[root@centos6:php-5.6.31]# apachectl stop
[root@centos6:php-5.6.31]# apachectl start

5、 测试访问

[root@centos6:php-5.6.31]# vim /app/httpd24/htdocs/index.php

<?php
$conn=mysql_connect('127.0.0.1','root','magedu');
if($conn)
    echo "OK";
else
    echo "Not OK";
mysql_close();
phpinfo();
?>

在浏览器上测试成功:


6、安装wordpress

切换目录到src目录下:

[root@centos6:php-5.6.31]# cd /root/src

解压:

[root@centos6:src]# tar xvf  wordpress-4.8-zh_CN.tar.gz

把WordPress移动到apache目录下并更名blog:

[root@centos6:src]# mv wordpress /app/httpd24/htdocs/blog/

进入blog:

[root@centos6:src]# cd /app/httpd24/htdocs/blog/

复制一份模板配置文件来修改(指定链接数据库的信息):

[root@centos6:blog]# cp wp-config-sample.php  wp-config.php
[root@centos6:blog]# vim wp-config.php

    define('DB_NAME', 'blogdb');
    define('DB_USER', 'wpuser');
    define('DB_PASSWORD', 'magedu');
    define('DB_HOST', 'localhost');

修改的结果实图如下:


测试成功:

7、 测试性能

博客搭建好了我们现在测试一下它的性能

[root@centos6:~]# ab -c 10 -n 100 http://192.168.8.130/blog/

由上图可以看到性能不是很好,下面我们来为其做一下加速

8、编译安装xcache

切换到src目录下:

[root@centos6:~]# cd /root/src

解压:

[root@centos6:src]# tar xf xcache-3.2.0.tar.bz2

生成编译环境.configure脚本:

[root@centos6:src]# cd  xcache-3.2.0
[root@centos6: xcache-3.2.0]# /app/php/bin/phpize

编译安装:

[root@centos6: xcache-3.2.0]# ./configure --enable-xcache  --with-php-config=/app/php/bin/php-config

[root@centos6: xcache-3.2.0]# make && make install

注意最后结果的一行目录放的是生成模块文件:
[root@centos6: xcache-3.2.0]# ls  /app/php/lib/php/extensions/no-debug-non-zts-20131226/xcache.so


[root@centos6: xcache-3.2.0]# mkdir /etc/php.d/ 
[root@centos6: xcache-3.2.0]# cp  xcache.ini  /etc/php.d/
[root@centos6: xcache-3.2.0]# vim /etc/php.d/xcache.ini

修改:
    extension = /app/php/lib/php/extensions/no-debug-non-zts-20131226/xcache.so

重启服务:

[root@centos6: xcache-3.2.0]# service httpd24 restart
[root@centos6: xcache-3.2.0]# ss -ntl

访问一下看是否已有XCache模块:

9、测试性能

[root@centos6:~]# ab -c 20 -n 200 http://192.168.8.130/blog/

我们可以看到做完加速提高了好几倍。

相关文章

网友评论

      本文标题:在centos6.9上实现编译安装lamp和wordpress,

      本文链接:https://www.haomeiwen.com/subject/eifzlxtx.html