源码安装lamp

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了源码安装lamp相关的知识,希望对你有一定的参考价值。

在实际环境中我们经常根据自己所处的公司环境进行配置,适合自己公司的配置。下面我们来介绍如何进行编译安装

安装前提

在CentOS7 系统:

关闭iptables
将selinux设置为disabled
apr-1.6.2.tar.gz      
httpd-2.4.27.tar.bz2                
php-7.1.10.tar.xz
apr-util-1.6.0.tar.gz  
mariadb-10.2.8-linux-x86_64.tar.gz  wordpress-4.8.1-zh_CN.tar.gz
安装工具包development tools

注意:这里安装需要按顺序进行的mariadb-->httpd-->php,mariadb和httpd安装顺序没有关系

源码编译httpd服务

在之前的apache博客中讲过为什么要安装apr和apr-util包,如果不懂请查看apache博客。

(1)源码编译安装apr

[[email protected]/usr/local/src]#tar xvf apr-1.6.2.tar.gz[[email protected]/usr/local/src/apr-1.6.2]#./configure --prefix=/app/apr[[email protected]/usr/local/src/apr-1.6.2]#make && make install

(2)源码编译安装apr-util

[[email protected]/usr/local/src]#tar xf apr-util-1.6.0.tar.gz[[email protected] apr-util-1.6.0]# yum install -y expat-devel
[[email protected]/usr/local/src/apr-util-1.6.0]#./configure --prefix=/app/apr-util --with-apr=/app/apr[[email protected]/usr/local/src/apr-util-1.6.0]#make && make install

(3)源码安装httpd

首先确认系统上是否有apache用户,如果没有需要创建

[[email protected]/usr/local/src]#useradd -r -m -d /app/website -s /sbin/nologin apache[[email protected]/usr/local/src]#tar xf httpd-2.4.27.tar.bz2

在编译安装httpd之前需要安装几个依赖包

[[email protected]/usr/local/src/httpd-2.4.27]#yum install -y pcre-devel apr-devel apr-util-devel openssl-devel

[[email protected]/usr/local/src/httpd-2.4.27]#./configure --prefix=/app/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/app/apr/ --with-apr-util=/app/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork

[[email protected]/usr/local/src/httpd-2.4.27]#make -j 4 && make install

(4)设置环境变量

[[email protected]/etc/profile.d]#vim httpd24.sh

export PATH=/app/httpd24/bin:$PATH

[[email protected]/etc/profile.d]#source httpd24.sh

(5)设置man手册位置

[[email protected]/etc]#vim /etc/man_db.conf

23 MANDATORY_MANPATH                       /app/httpd24/man

(6)配置启动脚本

[[email protected]/app/httpd24]#cp bin/apachectl /etc/init.d/httpd24

(7)测试服务是否正常启动

技术分享已经监听80端口说明可以启动

http://192.168.4.60/ 技术分享

二进制安装mariadb

(1)二进制安装mariadb

[[email protected]/usr/local]#useradd -r -m -d /app/mysqldb -s /sbin/nologin mysql[[email protected]/usr/local/src]#tar xf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local/[[email protected]/usr/local]#ln -sv mariadb-10.2.8-linux-x86_64/ mysql

(2)添加环境变量

[[email protected]/etc/profile.d]#vim mysql.sh

    PATH=/usr/local/mysql/bin:$PATH

(3)配置man手册

[[email protected]/usr/local/mysql/bin]#vim /etc/man_db.conf

    24 MANDATORY_MANPATH /usr/local/mysql/man

(4)创建启动脚本

[[email protected]/usr/local/mysql]#cp support-files/mysql.server /etc/init.d/mysqld

[[email protected]/usr/local/mysql]#chkconfig --add mysqld

(5)配置主配置文件

[[email protected]/usr/local/mysql]#mkdir /etc/mysql

[[email protected]/usr/local/mysql]#cp support-files/my-large.cnf /etc/mysql/my.cnf

[[email protected]/usr/local/mysql]#vim /etc/mysql/my.cnf 

    27 [mysqld] 

    28 datadir = /app/mysqldb

(6)创建日志目录

[[email protected]/usr/local/mysql]#mkdir /var/log/mariadb

[[email protected]/usr/local/mysql]#setfacl -Rm u:mysql:rwx /var/log/mariadb/

(7)安装数据库

[[email protected]/usr/local/mysql]#scripts/mysql_install_db --user=mysql --datadir=/app/mysqldb

(8)初始化数据库

[[email protected]~]#mysql_secure_installation 

(9)测试数据库是否安装成功

[[email protected]~]#mysql -u root -p

MariaDB [(none)]> CREATE DATABASE wpdb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON wpdb.* TO ‘joah‘@‘localhost‘ IDENTIFIED BY ‘123456‘;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON wpdb.* TO ‘joah‘@‘127.0.0.1‘ IDENTIFIED BY ‘123456‘;

源码安装php

(1)解压缩并编译安装

[[email protected]/usr/local/src/php-7.1.10]#yum install -y libxml2-devel bzip2-devel libmcrypt-devel

[[email protected]/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[[email protected]/usr/local/src/php-7.1.10]#make && make install(2)配置主配置文件

[[email protected]/usr/local/src/php-7.1.10]#cp php.ini-production /etc/php.ini

(3)修改/etc/httpd/conf/httpd.conf

259 <IfModule dir_module>
260     DirectoryIndex index.php index.html
261 </IfModule>

512 AddType Application/x-httpd-php .php
513 AddType Application/x-httpd-php-source .phps

(4)测试能否与httpd连接成功

[[email protected]/app/httpd24/htdocs]#vim index.php

  1 <?php
 2         phpinfo();
 3 ?>

(5)测试是否能否可以和mariadb连接成功

[[email protected]/app/httpd24/htdocs]#vim index.php

<?php
$mysqli=new mysqli("localhost","root","centos");
if(mysqli_connect_errno()){
       echo "连接数据库失败!";
       $mysqli=null;
       exit;
}
       echo "连接数据库成功!";
       $mysqli->close();
       phpinfo();
?>

安装wordpress

(1)解压缩

[[email protected]/usr/local/src]#tar xf wordpress-4.8.tar.gz -C /app/httpd24/htdocs

(2)配置主配置文件

[[email protected]/app/httpd24/htdocs/wordpress]#cp wp-config-sample.php wp-config.php[[email protected]/app/httpd24/htdocs/wordpress]#vim wp-config.php

 23 define(‘DB_NAME‘, ‘wpdb‘);
24
25 /** MySQL database username */
26 define(‘DB_USER‘, ‘joah‘);
27
28 /** MySQL database password */
29 define(‘DB_PASSWORD‘, ‘123456‘);
30
31 /** MySQL hostname */
32 define(‘DB_HOST‘, ‘localhost‘);

http://192.168.4.59/wordpress/wp-admin/setup-config.php

测试其性能如何

[[email protected]/app/httpd24/htdocs/wordpress]#ab -c 10 -n 100 http://192.168.4.60/wordpress/

HTML transferred:       5209700 bytes
Requests per second:    25.25 [#/sec] (mean)    #在没有加速器性能还不错
Time per request:       396.061 [ms] (mean)

CentOS 6 源码编译

安装前环境准备 apr-1.6.2.tar.gz 
httpd-2.4.27.tar.bz2 
php-5.6.31.tar.xz 
xcache-3.2.0.tar.bz2 apr-util-1.6.0.tar.gz
mariadb-5.5.57-linux-x86_64.tar.gz wordpress-4.8.1-zh_CN.tar.gz

二进制安装mariadb

(1)二进制安装mariadb

[[email protected]/usr/local]#useradd -r -m -d /app/mysqldb -s /sbin/nologin mysql

[[email protected]/usr/local/src]#tar xf mariadb-10.2.8-linux-x86_64.tar.gz -C /usr/local/

[[email protected]/usr/local]#ln -sv mariadb-10.2.8-linux-x86_64/ mysql

(2)添加环境变量

[[email protected]/etc/profile.d]#vim mysql.sh

    PATH=/usr/local/mysql/bin:$PATH

(3)配置man手册

[[email protected]/usr/local/mysql/bin]#vim /etc/man_db.conf

    24 MANDATORY_MANPATH /usr/local/mysql/man

(4)创建启动脚本

[[email protected]/usr/local/mysql]#cp support-files/mysql.server /etc/init.d/mysqld

[[email protected]/usr/local/mysql]#chkconfig --add mysqld

(5)配置主配置文件

[[email protected]/usr/local/mysql]#mkdir /etc/mysql

[[email protected]/usr/local/mysql]#cp support-files/my-large.cnf /etc/mysql/my.cnf

[[email protected]/usr/local/mysql]#vim /etc/mysql/my.cnf

    27 [mysqld] 

    28 datadir = /app/mysqldb

(6)创建日志目录

[[email protected] mysql]# touch /var/log/mysqld.log

(7)安装数据库

[[email protected]/usr/local/mysql]#scripts/mysql_install_db --user=mysql --datadir=/app/mysqldb

(8)初始化数据库

[[email protected]~]#mysql_secure_installation

(9)测试数据库是否安装成功

[[email protected]~]#mysql -u root -p

MariaDB [(none)]> CREATE DATABASE wpdb;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON wpdb.* TO ‘joah‘@‘localhost‘ IDENTIFIED BY ‘123456‘;
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> GRANT ALL ON wpdb.* TO ‘joah‘@‘127.0.0.1‘ IDENTIFIED BY ‘123456‘;

编译安装httpd服务

(1)解压缩httpd源码包

[[email protected] httpd-2.4.27]# yum install -y apr-devel apr-util-devel openssl-devel pcre-devel

[[email protected] httpd-2.4.27]# tar xf apr-1.6.2.tar.gz

[[email protected] httpd-2.4.27]# tar xf apr-util-1.6.0.tar.gz

[[email protected] httpd-2.4.27]# mv apr-1.6.2 httpd-2.4.27/srclib/

[[email protected] httpd-2.4.27]# mv apr-util-1.6.0 httpd-2.4.27/srclib/apr-util

[[email protected] 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

[[email protected] httpd-2.4.27]# make && make install

(2)配置环境变量

[[email protected] httpd24]# vim /etc/profile.d/httpd24.sh

    PATH=/app/httpd24/bin:$PATH 

(3)配置启动脚本

[[email protected] httpd24]# cp /etc/init.d/httpd /etc/init.d/httpd24

[[email protected] httpd24]# vim /etc/init.d/httpd24

apachectl=/app/httpd24/bin/apachectl
httpd=${HTTPD-/app/httpd24/bin/apachectl}
prog=httpd
pidfile=${PIDFILE-/app/httd24/logshttpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}

(4)测试是否配置成功

[[email protected] httpd24]# service httpd24 start

编译安装php

安装方式一:基于php模块安装

(1)解压缩并编译安装

[[email protected] php-5.6.4]#yum install libxml2-devel bzip2-devel libmcrypt-devel

[[email protected] 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-png-dir --with-jpeg-dir --with-freetype-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

[[email protected] php-5.6.4]# make && make install

(2)配置主配置文件

[[email protected] php-5.6.31]# cp php.ini-production /etc/php.ini

(3)在httpd.conf中配置

259 <IfModule dir_module>
260     DirectoryIndex index.php index.html
261 </IfModule>

512 AddType Application/x-httpd-php .php
513 AddType Application/x-httpd-php-source .phps

接下的步骤和CentOS 7中的配置类似,请参考上述配置。

(4)配置环境变量

[[email protected] php]# vim /etc/profile.d/php.sh

PATH=/app/php/bin:$PATH

[[email protected] php]# source /etc/profile.d/php.sh

(5)测试是否可以与apache通信

[[email protected] htdocs]# vim index.php

?>

(6)测试是否可以与mysql通信

<?php
       $msyqli=new mysqli("192.168.4.132","root","123456");
       if(mysqli_connect_errno()){
               echo "failure";
               $mysqli=null;
               exit;
       }
               echo "ok";
               $mysqli->close;
               phpinfo();
?>

(7)安装wordpress

步骤和CentOS7安装一样可以参考

(8)源码编译安装加速器

[[email protected] xcache-3.2.0]# phpize #生成configure

[[email protected] xcache-3.2.0]# ./configure --enable-xcache --with-php-config=/app/php/bin/php-config

[[email protected] xcache-3.2.0]# make && make install

安装方式二:基于php-fpm模块安装

[[email protected] php-5.6.31]# ./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[[email protected] php-5.6.31]# make && make install

(2)准备启动脚本文件

[[email protected] php-5.6.31]# cp sapi/fpm/init.d.php-fpm.in /etc/rc.d/init.d/php-fpm

[[email protected] php-5.6.31]# chmod +x /etc/rc.d/init.d/php-fpm

[[email protected] php-5.6.31]# chkconfig --add php-fpm

(3)配置环境变量

[[email protected] php-5.6.31]# vim /etc/profile.d/php-fpm.sh

[[email protected] php-5.6.31]# source /etc/profile.d/php-fpm.sh

(4)创建主配置文件

[[email protected] etc]# mkdir /etc/php5

[[email protected] etc]# cp /usr/local/src/php-5.6.31/php.ini-production /etc/php5/php.ini

(5)准备服务配置文件

[[email protected] etc]# cp php-fpm.conf.default php-fpm.conf

(6)编辑/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

(7)启动php-fpm服务

[[email protected] etc]# service php-fpm start

(8)测试是否可以与mysql和httpd连接成功

http://192.168.4.132/

(9)安装wordpress

安装过程和CentOS 7中安装一样,可以参考上述过程

(10)测试性能如何

Requests per second:    579.84 [#/sec] (mean)
Time per request:       17.246 [ms] (mean)
Time per request:       1.725 [ms] (mean, across all concurrent requests)
Transfer rate:          37900.46 [Kbytes/sec] received



本文出自 “Joah” 博客,请务必保留此出处http://merit.blog.51cto.com/10757694/1973795

以上是关于源码安装lamp的主要内容,如果未能解决你的问题,请参考以下文章

lamp源码安装出错及解决方案

LAMP源码安装

详解LAMP源码编译安装

LAMP环境官方最新源码编译安装

ubuntu下源码安装LAMP及Laravel

源码安装LAMP架构!