LAMP编译安装

一、介绍

L指的是Linux
A是Apache
M为Mysql或者Mariadb
P为Php,Pyton或者perl
WEB资源类型: 
        静态资源:原始形式与响应内容一致
        动态资源:原始形式通常为程序文件,需要在服务器端执 
web服务器通过发起请求的后缀来判断,如果是静态的资源就由web服务器自行处理,到磁盘上找到数据后构建相应报文,然后发送给客户端。

如果是动态这时web服务器会将请求转发给php。这里分为两种情况:
一种为php以模块的方式集成在httpd中,httpd通过cgi协议和php模块连接。这中间的过程就是httpd服务针对每个有客户端请求生成一个进程,然后进程生成一个cgi子进程,子进程负责和后边的php模块的连接,php模块执行程序,如果需要用到数据,就会作为客户端通过mysql协议连接mysql数据库服务端,获取数据并处理,处理完成后的数据成为静态的资源,再通过httpd服务传给客户端浏览器。
另一种情况如果是php会安装一个名为php-fpm的单独的服务,httpd转发请求时服务就相当于是php-fpm的客户端,通过FastCgi协议和php-fpm服务端连接。之后的步骤就和上面一样了。

CGI:Common Gateway Interface 可以让一个客户端,从网页浏览器通过http服务器向执行在 网络服务器上的程序传输数据;CGI描述了客户端和服务器程 序之间传输的一种标准 

LAMP编译安装

二、编译安装过程

环境如下:
系统:centos7.4
mairadb:通用二进制格式,mariadb-10.2.14
httpd:编译安装,httpd-2.4.29 
php5:编译安装,php-7.1.7
phpMyAdmin:安装phpMyAdmin-4.8.0.1-all-languages 
Xcache:编译安装xcache-3.2.0
php5.4依赖于mariadb-devel包 
顺序:httpd--mariadb-->php

1、安装依赖的工具包组

yum -y groupinstall "Development tools"
yum -y install pcre-devel openssl-devel
./configure 之后有提示未装的包,根据提示yum安装即可。

 2、准备软件包

 APR(Apache portable Run-time libraries,Apache可移植运行库)的目的如其名称一样,主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库。在早期 的Apache版本中,应用程序本身必须能够处理各种具体操作系统平台的细节,并针对不同的平台调用不同的处理函数。

随着Apache的进一步开 发,Apache组织决定将这些通用的函数独立出来并发展成为一个新的项目。这样,APR的开发就从Apache中独立出来,Apache仅仅是使用 APR而已。目前APR主要还是由Apache使用,不过由于APR的较好的移植性,因此一些需要进行移植的C程序也开始使用APR,开源项目比如 Flood 

[root@localhost ~/src]$ls
apr-1.6.2.tar.gz       mariadb-10.2.14-linux-x86_64.tar.gz  xcache-3.2.0.tar.gz
apr-util-1.6.0.tar.gz  php-7.1.17.tar.bz2
httpd-2.4.29.tar.bz2   wordpress-4.9.4-zh_CN.tar.gz

3、开始编译httpd.2.4.29

mv apr-1.6.2 httpd-2.4.29/srclib/apr
mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
此步骤可省略编译apache时再设置路径--with-included-apr
mkdir /app/httpd2429
/configure --prefix=/app/httpd2429 --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 && make install
vim /etc/profile.d/httpd2429.sh   /etc/profile是永久性的环境变量,是全局变量,/etc/profile.d/设置所有  用户生效.以后启动时直接用apachectl start 即可
export PATH=/app/httpd2429/bin:$PATH
. /etc/profile.d/httpd2429.sh

LAMP编译安装

4、二进制安装数据库

tar xvf mariadb-10.2.14-linux-x86_64.tar.gz -C /usr/local/    (也可参考我的上篇博客)
解包时可不放在/usr/local/下,但一会创建软连接一定要放在这下边!要不会麻烦死 各种脚本都要调。
ln -s mariadb-10.2.14-linux-x86_64/ mysql
useradd -r -m -d /app/mysqldb -u 27 -s /sbin/nologin mysql  创建mysql用户
[root@localhost /usr/local/mysql]#scripts/mysql_install_db --datadir=/app/mysqldb --us
er=mysql
[root@localhost /usr/local/mysql]$ cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld

添加启动脚本
[root@localhost /usr/local/mysql]$vim /etc/profile.d/httpd2429.sh 
export PATH=/usr/local/mysql/bin:/app/httpd2429/bin:$PATH
. /etc/profile.d/httpd2429.sh

systemctl start mysqld
ss -tnl
设置权限
mysql_secure_installation   这个一定要设置!!
mysql -uroot -pcentos
grant all on *.* to jin@'172.18.%.%' identified by "centos";

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

MariaDB [(none)]> gran all on wpdb.* to wpuser@'127.%' identified by 'centos';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corres
ponds to your MariaDB server version for the right syntax to use near 'gran all on wpdb.* to wpuser@'127.%' identified by 'centos'' at line 1MariaDB [(none)]> grant all on wpdb.* to wpuser@'127.%' identified by 'centos';
Query OK, 0 rows affected (0.04 sec)

MariaDB [(none)]> grant all on wpdb.* to wpuser@'172.18.%.%' identified by 'centos';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all on wpdb.* to wpuser@'localhost' identified by 'centos';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> 

5、编译安装php

/root/src/   tar xvf  php-7.1.7.tar.bz2 
yum install -y libxml2-devel libmcrypt-devel   #libmcrypt-devel  来自epel源
./configure --prefix=/app/php --enable-mysqlnd  --with-mysqli=mysqlnd   --with-openssl --enable-mbstring --with-png-dir --with-jpeg-dir --with-freetype-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/app/httpd2429/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2
make -j 4 && make install
编译安装一定要看仔细 了!!我在这里出了不少问题。
[root@localhost ~/src/php-7.1.17]$cp php.ini-production /etc/php.ini
vim /app/httpd24/conf/httpd.conf
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
apachectl restart



LAMP编译安装


LAMP编译安装

vim index.php
<html><body><h1> Lamp it works!</h1></body></html>
<?php
$mysqli=new mysqli("127.0.0.1","root","centos");
if(mysqli_connect_errno()){
echo "连接数据库失败!";
$mysqli=null;
exit;
}
echo "连接数据库成功!";
$mysqli->close();
phpinfo();
?>
[root@localhost ~]$ps aux |grep php
root 107589 0.0 0.0 112704 964 pts/2 S+ 21:45 0:00 grep --color=auto ph
p

LAMP编译安装

  
LAMP编译安装


6、安装wordpress


tar xvf wordpress-4.8.1-zh_CN.tar.gz -C /app/httpd2429/htdocs
ln -s wordpress/ blog
cd blog/
cp wp-config-sample.php wp-config.php
vim wp-config.php
define('DB_NAME', 'wpdb');

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

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


LAMP编译安装



LAMP编译安装


ab -c -n 1000 http://URL

LAMP编译安装






6、安装php-xcache

tar xvf xcache-3.2.0.tar.bz2
[root@localhost ~/src/xcache-3.2.0]$/app/php/bin/phpize 
[root@localhost ~/src/xcache-3.2.0]$./configure --enable-xcache --with-php-config=/app
/php/bin/php-config
make && make install
之后会出现一个路径,复制下来!如下面第一个图。
cp xcache.ini /etc/php.d/
vim /etc/php.d/xcache.ini
这里在“extension”后面复制刚才那个路径
[root@lamp xcache-3.2.0]# /etc/init.d/php-fpm restart
apachetcl restart
ab -c10 -n 1000 URL://

  
注意:查了谷歌xache经过测试极大可能是不支持php7以上,此次编译环境php较新,大家可拿php5.6测试。(博主已经累了,这个折腾了很久。0.0)
LAMP编译安装

LAMP编译安装

[root@localhost ~/src/xcache-3.2.0]$ab -c 10 -n 1000 http://172.18.252.35/blog/

加速前


LAMP编译安装

转载于:https://blog.51cto.com/11566825/2119640

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值