CentOS6编译安装LAMP
注意:防火墙与SELinux的干扰
关闭防火墙的命令:service iptables stop
查看selinux模式
[root@centos6~]#getenforce#查看selinux模式 Permissive#关闭Enforcing#开启
关闭selinux
[root@centos6~]#vim/etc/selinux/config#修改配置文件 #ThisfilecontrolsthestateofSELinuxonthesystem. #SELINUX=cantakeoneofthesethreevalues: #enforcing-SELinuxsecuritypolicyisenforced. #permissive-SELinuxprintswarningsinsteadofenforcing. #disabled-NoSELinuxpolicyisloaded. SELINUX=permissive#修改,永久性关闭,重启服务器后生效 ##################### [root@centos6~]#setenforce0#临时性关闭,设置为permissive模式,立即生效,重启后失效 [root@centos6~]#setenforce1#临时性开启,设置为enforcing模式,立即生效,重启后失效
正式开始编译LAMP
所需软件及其版本
apr-1.6.2.tar.gz
apr-util-1.6.0.tar.gz
httpd-2.4.28.tar.bz2
mariadb-5.5.57-linux-x86_64.tar.gz
下载地址:https://downloads.mariadb.org/
PHP-5.6.31.tar.xz
下载地址:http://www.php.net/
所需包组
yum groupinstall "development tools"
##开发工具
yum install openssl-devel expat-devel pcre-devel bzip2-devel libxml2-devel libmcrypt-devel
##紫色为编译httpd所需要的包,蓝色的为编译PHP所需要的包
注意安装顺序,PHP最后编译安装
1、编译httpd2.4
tarxvfapr-1.6.2.tar.gz#解相关包 tarxvfapr-util-1.6.0.tar.gz tarxvfhttpd-2.4.28.tar.bz2 #开始编译 mvapr-1.6.2httpd-2.4.28/srclib/apr#将apr移动到相应的httpd目录下并重命名 mvapr-util-1.6.0 httpd-2.4.28/srclib/apr-util#将apr移动到相应的httpd目录下并重命名 cd/root/src/httpd-2.4.28#进入包目录下 ./configure\#执行脚本,配置环境,下面为所需选项 --prefix=/app/httpd24\#指定编译安装路径 --enable-so\#开启动态加载模块 --enable-ssl\#支持ssl加密 --enable-cgi\#开启cgi接口 --enable-rewrite\#支持地址重写 --with-zlib\#支持压缩 --with-pcre\ --with-included-apr\ --enable-modules=most\#启用模块 --enable-mpms-shared=all\ --with-mpm=prefork make-j4&&makeinstall#编译安装 vim/etc/profile.d/lamp.sh#加入PATH变量 PATH=/app/httpd24/bin:/usr/local/MysqL/bin/:/app/PHP/bin/:$PATH#加入所有编译的相关PATH变量 ./etc/profile.d/lamp.sh#加入PATH的文件生效 apachectl#开启服务 AH00558:httpd:Couldnotreliablydeterminetheserver'sfullyqualifieddomainname,using127.0.0.1.Setthe'ServerName'directivegloballytosuppressthismessage
完成编译
2、二进制安装mariadb-5.5.57
tar xvf mariadb-5.5.57-linux-x86_64.tar.gz -C /usr/local/ ##解包,固定目录
cd /usr/local/
mv mariadb-5.5.57-linux-x86_64/ MysqL ##改名或者软连接也可以:ln -s mariadb-5.5.57-linux-x86_64/ MysqL
useradd -r -d /data/MysqLdb/ -m -s /sbin/nologin MysqL #创建用户
cd MysqL/
使用逻辑卷:添加磁盘
echo '- - -' > /sys/class/scsi_host/host0/scan #磁盘生效
pvcreate /dev/sdb#逻辑卷
vgcreate vg_MysqLdb /dev/sdb
lvcreate -n lv_MysqLdb -l +100%FREE vg_MysqLdb
mkfs.ext4 /dev/vg_MysqLdb/lv_MysqLdb -L /data/MysqLdb #格式化文件系统
vim /etc/fstab #加入文件系统
/dev/vg_MysqLdb/lv_MysqLdb /data/MysqLdb ext4 defaults 0 0
tune2fs -l /dev/vg_MysqLdb/lv_MysqLdb
tune2fs -o acl /dev/vg_MysqLdb/lv_MysqLdb
mkdir /data/MysqLdb -p
mount -a
cd /data/
cd /usr/local/MysqL
scripts/MysqL_install_db --user=MysqL --datadir=/data/MysqLdb/ #创建数据库
ls /data/MysqLdb/ #查看数据库是否创建成功
cp support-files/my-huge.cnf /etc/MysqL/my.cnf
vim /etc/MysqL/my.cnf
[MysqLd]
datadir = /data/MysqLdb
innodb_file_per_table = ON
skip_name_resolve = ON
cp support-files/MysqL.server /etc/init.d/MysqLd #服务脚本
chkconfig --add MysqLd
chkconfig MysqLd on
service MysqLd start
touch /var/log/MysqLd.log
chown MysqL /var/log/MysqLd.log
service MysqLd start
OK
完成二进制安装
3、编译安装PHP-5.6.31
tar xvf PHP-5.6.31.tar.xz #解包
cd 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 \
--enable-fpm \
--with-mcrypt \
--with-config-file-path=/etc/PHP/ \
--with-config-file-scan-dir=/etc/PHP.d \
--with-bz2
make && make install
cp PHP.ini-production /etc/PHP/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
cp /app/PHP/etc/PHP-fpm.conf.default /app/PHP/etc/PHP-fpm.conf #与CentOS7的不同之处
service PHP-fpm start
ss -ntl
9000 #端口
完成编译
vim /app/httpd24/conf/httpd.conf
去掉下面两行注释
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
修改下面行
DirectoryIndex index.PHP index.html
加下面四行
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
service httpd24 start
附:编译安装xcache
tarxvfxcache-3.2.0.tar.gz cdxcache-3.2.0 ./configure--enable-xcache --with-PHP-config=/app/PHP/bin/PHP-config make&&make install mkdir/etc/PHP.d/ cpxcache.ini/etc/PHP.d/ vim/etc/PHP.d/xcache.ini extension=/app/PHP/lib/PHP/extensions/no-debug-non-zts-20131226/xcache.so修改此行 servicePHP-fpmrestart
CentOS7编译安装LAMP
注意:防火墙和SELinux
实验环境:VMware上CentOS7
实验描述:CentOS7基于FPM编译安装LAMP(同一主机)
实验步骤:注意顺序,PHP最后编译
1、编译安装httpd
yum install openssl-devel pcre-devel expat-devel #编译前的准备:安装所需包
tar xvf apr-1.6.2.tar.gz
tar xvf apr-util-1.6.0.tar.gz
tar xvf httpd-2.4.28.tar.bz2 #解包
mv apr-1.6.2 httpd-2.4.28/srclib/apr/ ##开始编译
mv apr-util-1.6.0 httpd-2.4.28/srclib/apr-util/
cd httpd-2.4.28/
./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
make && make install
vim /etc/profile.d/lamp.sh #加入PATH变量
PATH=/app/httpd24/bin:$PATH
. /etc/profile.d/lamp.sh
apachectl #开启服务
AH00558: httpd: Could not reliably determine the server's fully qualified domain name,using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
测试:curl 192.168.xxx.xxx
<html><body><h1>It works!</h1></body></html>
完成编译
2、二进制安装mariadb
tar xvf mariadb-10.2.9-linux-x86_64.tar.gz -C /usr/local/ ##解包,固定目录
cd /usr/local/
ln -s mariadb-10.2.9-linux-x86_64/ MysqL ##改名也可以:mv mariadb-10.2.9-linux-x86_64/ MysqL
useradd -r -d /app/MysqLdb/ -m -s /sbin/nologin MysqL #创建用户
cd MysqL/
mkdir /etc/MysqL/
cp support-files/my-large.cnf /etc/MysqL/my.cnf #配置配置文件
vim /etc/MysqL/my.cnf
[MysqLd] #加三行
datadir = /app/MysqLdb
innodb_file_per_table = ON
skip_name_resolve = ON
scripts/MysqL_install_db --user=MysqL --datadir=/app/MysqLdb/ #创建数据库
cp support-files/MysqL.server /etc/init.d/MysqLd #拷贝服务脚本
mkdir /var/log/mariadb #创建日志文件
systemctl start MysqLd
vim /etc/profile.d/lamp.sh #加入PATH变量
PATH=/app/httpd24/bin:/usr/local/MysqL/bin:$PATH
MysqL_secure_installation #安全脚本
完成二进制安装
附:MysqL -uroot -pqweasd
......
MariaDB [(none)]> create database blogdb; #创建wp数据库
Query OK,1 row affected (0.00 sec)
MariaDB [(none)]> grant all on blogdb.* to wpuser@'localhost' identified by "qweasd"; #授权用户
Query OK,0 rows affected (0.09 sec)
MariaDB [(none)]> quit
Bye
3、编译安装PHP
yum install bzip2-devel libxml2-devel libmcrypt-devel #安装所需包
tar xvf PHP-7.1.10.tar.xz #解包
cd PHP-7.1.10/ #开始编译
./configure --prefix=/app/PHP \
--enable-MysqLnd \
--with-openssl \
--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 \
--with-config-file-scan-dir=/etc/PHP.d \
--enable-maintainer-zts \
--disable-fileinfo
make && make install
mkdir /etc/PHP/
cp PHP.ini-production /etc/PHP.ini #配置配置文件
cp sapi/fpm/init.d.PHP-fpm /etc/init.d/PHP-fpm #服务脚本
chkconfig --add PHP-fpm
chkconfig PHP-fpm on
chmod +x /etc/init.d/PHP-fpm
cd /app/PHP/etc/
cp PHP-fpm.conf.default PHP-fpm.conf #与CentOS6的不同之处
cpwww.conf.default www.conf
vim /app/httpd24/conf/httpd.conf #配置httpd支持fpm PHP
LoadModule proxy_module modules/mod_proxy.so #开启
.......
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so #开启
.......
DirectoryIndex index.PHP #支持PHP文件
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
vim /app/httpd24/htdocs/index.PHP #测试例子
<?PHP
$MysqLi=new MysqLi("localhost","root","qweasd");
if(MysqLi_connect_errno()){
echo " 连接数据库失败!";
$MysqLi=null;
exit;
}
echo " 连接数据库成功!";
$MysqLi->close();
?>
vim /etc/profile.d/lamp.sh #加入PATH变量
PATH=/app/httpd24/bin:/usr/local/MysqL/bin:/app/PHP/bin/:$PATH
service PHP-fpm start
apachectl stop #停掉httpd
apachectl
测试:curl 192.168.136.132/index.PHP
连接数据库成功!
完成编译
附:支持多个虚拟主机
vim /app/httpd24/conf/httpd.conf
Include conf/extra/httpd-vhosts.conf 取消注释
删除下面两行
ProxyRequests Off
ProxyPassMatch ^/(.*\.PHP)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1
vim /app/httpd24/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/app/httpd24/htdocs"
ServerName www.a.com
ErrorLog "logs/a.com-error_log"
CustomLog "logs/a.com-access_log" common
ProxyRequests Off
ProxyPassMatch ^/(.*\.PHP)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1
<directory /app/httpd24/htdocs>
require all granted
</directory>
</VirtualHost>
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/app/httpd24/htdocs2"
ServerName www.b.com
ErrorLog "logs/b.com-error_log"
CustomLog "logs/b.com-access_log" common
ProxyRequests Off
ProxyPassMatch ^/(.*\.PHP)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs2/$1
<directory /app/httpd24/htdocs2>
require all granted
</directory>
</VirtualHost>
原文链接:https://www.f2er.com/centos/375380.html