LAMP编译安装系列
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LAMP编译安装系列相关的知识,希望对你有一定的参考价值。
主要还是centos6.9和centos7上相应软件包的安装及编译安装。所用版本均为当前最新版。生产环境中不建议这么干,毕竟生成以稳定为主。
LAMP里php是最后安装,php依赖于服务器和数据库,所以这里单独编译系列就只有httpd和mariadb了。
LAMP之php相关配置说明
apache所支持的文件格式:cat /etc/mime.types
服务器如何支持php;
1.apache加模块modules
2.php以独立软件运行php-fpm
yum install php
rpm -ql php
设index.php为首页
vim httpd.conf
DirectoryIndex index.php
连接数据库
yum install mariadb
systemctl start mariadb
ss -ntl 3306
mysql_secure_installation
mysql -uroot -p
create user ‘test‘@‘192.168.37.%‘ identified by ‘centos‘;
yum install php-mysql
service httpd restart
vim index.php
<?php
$conn = mysql_connect(‘192.168.37.107‘,‘test‘,‘centos‘);
if ($conn)
echo "OK";
else
echo "Failure";
mysql_close();
phpinfo();
?>
vim index2.php
<?php
$mysqli=new mysqli(‘192.168.37.107‘,‘test‘,‘centos‘);
if(mysqli_connect_errno()){
echo "连接数据库失败!";
$mysqli=null;
exit;
}
echo "连接数据库成功!";
$mysqli->clwordpressose();
?>
zip unzip 解压
cp -r phpMyAdmin /var/www/html/pma
yum search mbstring
yum install php-mbstring
systemctl restart httpd
wordpress
wpdb 创建
添加用户
wpuser 192.168.1.%
mima mima
mysql -uroot -pcentos
use wpdb;
create table t1(id int,..)
搭建博客
下载 解压
cp -r wordpress /var/www/html/blog
cd /var/www/html/blog
cp wp-config-sample.php wp-config.php
vim wp-config.php
DB_NAME wpdb
DB_USER wpuser
centos
192.168.37.107
php加速
vim /etc/php.ini
短标签 时区
实验:LAMP的php模块方式应用phpmyadm和wordpress
两台主机
一台A:httpd,php
一台B:mariadb server
1 A:
yum httpd php php-mysql
vim /etc/php.ini
date.timezone = Asia/Shanghai
vim /etc/httpd/conf/httpd.conf
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
systemctl restart httpd
vim /var/www/html/index.php
<?php
echo date("Y/m/d H:i:s");
phpinfo();
?>
2 B
yum install mariadb-server
systemctl start mariadb
mysql_secure_installation
mysql -uroot -pcentos
>grant all on *.* to [email protected]‘192.168.37.%‘ identified by ‘centos‘;
vim /var/www/html/index2.php
<?php
$mysqli=new mysqli("localhost","root","centos");
if(mysqli_connect_errno()){
echo "连接数据库失败!";
$mysqli=null;
exit;
}
echo "连接数据库成功!";
$mysqli->close();
测试 http://websrv/
3 实现phpmyadmin
yum install php-mbstring
unzip phpMyAdmin-4.0.10.20-all-languages.zip
cp -r phpMyAdmin-4.0.10.20-all-languages /var/www/html/pma
cd /var/www/html/pma
cp config.sample.inc.php config.inc.php
vim config.inc.php
$cfg[‘Servers‘][$i][‘host‘] = ‘mysqlserverip‘;
测试 http://websrv/pma/
root,centos
4 A上部署wordpress
mysql -uroot -pcentos
> create database wpdb;
> grant all wpdb.* to [email protected]‘192.168.37.%‘ identified by ‘centos‘;
> flush privileges;
tar xvf wordpress-4.8.1-zh_CN.tar.gz
cp -r wordpress /var/www/html/blog
cd /var/www/html/blog
cp wp-config-sample.php wp-config.php
vim wp-config.php
define(‘DB_NAME‘, ‘wpdb‘);
define(‘DB_USER‘, ‘wpuser‘);
define(‘DB_PASSWORD‘, ‘centos‘);
define(‘DB_HOST‘, ‘192.168.37.107‘);
测试http://websrv/blog/
实验:LAMP的fastcgi方式应用phpmyadm和wordpress
两台主机
一台A apache和php-fpm
一台B mariadb server
1
A:yum install httpd php-fpm php-mysql
systemctl start httpd
systemctl start php-fpm
B:yum install mariadb-server
systemctl start mariadb
mysql_secure_installation
mysql -uroot -pcentos
2 A: vim /etc/httpd/conf.d/fcgi.conf
DirectoryIndex index.php
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1
systemctl reload httpd
3 B上部署wordpress
mysql -uroot -pcentos
> create database wpdb;
> grant all wpdb.* to [email protected]‘192.168.37.%‘ identified by ‘centos‘;
> flush privileges;
tar xvf wordpress-4.8.1-zh_CN.tar.gz
cp -r wordpress /var/www/html/blog
cd /var/www/html/blog
cp wp-config-sample.php wp-config.php
vim wp-config.php
define(‘DB_NAME‘, ‘wpdb‘);
define(‘DB_USER‘, ‘wpuser‘);
define(‘DB_PASSWORD‘, ‘centos‘);
define(‘DB_HOST‘, ‘192.168.37.107‘);
4 测试性能
http://websrv/blog/
实验:CentOS7编译Php-xcache加速访问
1 yum -y install php-devel php-cli
2 tar xvf xcache-3.2.0.tar.bz2 下载并解压缩
3 phpize生成编译环境
4 cd xcache-3.2.0
./configure --enable-xcache--with-php-config=/usr/bin/php-config
make && make install
cp xcache-3.2.0/xcache.ini /etc/php.d/
systemctl restart php-fpm.service
5 测试性能
http://websrv/blog/
实验:CentOS7编译LAMP应用wordpress
软件版本
apr-1.6.2.tar.gz
httpd-2.4.28.tar.bz2
php-7.1.10.tar.xz
apr-util-1.6.0.tar.gz
mariadb-10.2.9-linux-x86_64.tar.gz
wordpress-4.8.1-zh_CN.tar.gz
1 编译httpd2.4
./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
2 二进制安装mariadb10.2
3 源码编译安装Php
yum install libxml2-devel bzip2-devel libmcrypt-devel
tar xvf php-7.1.10.tar.xz
cd 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
4 测试php和mariadb连接
vim /app/httpd24/htdocs/index.php
<html><body><h1> LAMP</h1></body></html>
<?php
$mysqli=new mysqli("localhost","root","centos");
if(mysqli_connect_errno()){
echo "连接数据库失败!";
$mysqli=null;
exit;
}
echo "连接数据库成功!";
$mysqli->close();
phpinfo();
?>
5 配置wordpress
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
vim wp-config.php
define(‘DB_NAME‘, ‘wpdb‘);
/** MySQL数据库用户名 */
define(‘DB_USER‘, ‘wpuser‘);
/** MySQL数据库密码 */
define(‘DB_PASSWORD‘, ‘centos‘);
/** MySQL主机 */
define(‘DB_HOST‘, ‘localhost‘);
6 登录测试
http://websrv/blog
测试性能
ab -c 10 -n 100 http://websrv/blog/
--disable-fileinfo
本文出自 “RightNow” 博客,请务必保留此出处http://amelie.blog.51cto.com/12850951/1974905
以上是关于LAMP编译安装系列的主要内容,如果未能解决你的问题,请参考以下文章