Linux 6下yum方式安装配置LAMP平台
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux 6下yum方式安装配置LAMP平台相关的知识,希望对你有一定的参考价值。
问题:在搭建环境的最好时时刻出现下面的错误,搞了半天当时就蒙了,但要相信好事多磨,,重启apache提示找不到libphp5-zts的模块,iptables也查了,selinux也设置了都不见解决
[[email protected] html]# service httpd start
正在启动 httpd:httpd: Syntax error on line 221 of /etc/httpd/conf/httpd.conf: Syntax error on line 9 of /etc/httpd/conf.d/php.conf: Cannot load /etc/httpd/modules/libphp5-zts.so into server: /etc/httpd/modules/libphp5-zts.so: cannot open shared object file: No such file or directory
二、安装apache httpd
详细可以参考:Linux下安装Apache httpd
###检查是否已安装httpd
# rpm -qa|grep httpd
httpd-tools-2.2.15-45.el6.centos.x86_64
httpd-2.2.15-45.el6.centos.x86_64
# yum -y install httpd ###此时我们看到httpd的小版本从45变成了53
# rpm -qa|grep httpd
httpd-tools-2.2.15-53.el6.centos.x86_64
httpd-2.2.15-53.el6.centos.x86_64
###查询生成的相关配置文件
# rpm -qc httpd|grep conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf/httpd.conf
/etc/httpd/conf/magic
/etc/sysconfig/htcacheclean
/etc/sysconfig/httpd
###启动httpd
# /etc/init.d/httpd start
Starting httpd: [ OK ]
# netstat -nltp|grep 80
tcp 0 0 :::80 :::* LISTEN 7621/httpd
###验证web服务
HTTP/1.1 403 Forbidden
Date: Tue, 12 Jul 2016 09:25:15 GMT
Server: Apache/2.2.15 (CentOS)
Accept-Ranges: bytes
Content-Length: 4961
Connection: close
Content-Type: text/html; charset=gbk
###编写一个php页面测试
# echo "
> <html>
> <h1>This is a php test page.</h1>
> <?php
> phpinfo();
> ?>
> </html>">>/var/www/html/index.php
###测试结果为phpinfo函数没有被解释
<html>
<h1>This is a php test page.</h1>
<?php
phpinfo();
?>
</html>
三、安装php ###安装php,同时会安装依赖包
# yum install php
Installing:
php x86_64 5.3.3-47.el6 base 1.1 M
Installing for dependencies:
php-cli x86_64 5.3.3-47.el6 base 2.2 M
php-common x86_64 5.3.3-47.el6 base 530 k
###查看php安装清单
# rpm -ql php
/etc/httpd/conf.d/php.conf
/usr/lib64/httpd/modules/libphp5.so
/var/lib/php/session
/var/www/icons/php.gif
###查看php的配置文件
# grep -vE "^#|^$" /etc/httpd/conf.d/php.conf
<IfModule prefork.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
LoadModule php5_module modules/libphp5-zts.so
</IfModule>
AddHandler php5-script .php
AddType text/html .php
DirectoryIndex index.php
###在上面的配置文件中,由于php以模块化方式与httpd结合工作,根据httpd的mpm模式不同,
###其所需要的php模块格式有所不同; prefork模式使用libphp5模块 worker和event模式则使用libphp5-zts模块
###重启httpd已使得php模块生效
# /etc/init.d/httpd configtest
Syntax OK
# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
###验证php模块已经被加载
# httpd -M |grep php
php5_module (shared)
###验证php页面
<html>
<h1>This is a php test page.</h1>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html><head>
<style type="text/css">
body {background-color: #ffffff; color: #000000;}
...........
###切换为使用worker工作模式 用了sed来实现其实可以直接编辑配置文件,见前一篇博客有
# cp /etc/sysconfig/httpd /etc/sysconfig/httpd.bk
# sed -i "[email protected]#HTTPD=/usr/sbin/[email protected]=/usr/sbin/[email protected]" /etc/sysconfig/httpd
# grep -vE "^#|^$" /etc/sysconfig/httpd
HTTPD=/usr/sbin/httpd.worker
###从下面的提示中,我们需要使用php5zts模块
# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd.worker: Syntax error on line 221 of /etc/httpd/conf/httpd.conf:
Syntax error on line 9 of /etc/httpd/conf.d/php.conf: Cannot load /etc/httpd/modules/libphp5-zts.so
into server: /etc/httpd/modules/libphp5-zts.so: cannot open shared object file: No such file or directory
[FAILED]
###安装php-zts模块
# yum -y install php-zts
# rpm -ql php-zts
/usr/lib64/httpd/modules/libphp5-zts.so #这里需要安装该模块就可以解决上述的问题
# ps -ef|grep http ###查看httpd,已经切换为使用worker模式
root 10339 1 0 04:35 ? 00:00:00 /usr/sbin/httpd.worker
apache 10341 10339 0 04:35 ? 00:00:00 /usr/sbin/httpd.worker
apache 10342 10339 0 04:35 ? 00:00:00 /usr/sbin/httpd.worker
apache 10343 10339 0 04:35 ? 00:00:00 /usr/sbin/httpd.worker
apache 10344 10339 0 04:35 ? 00:00:00 /usr/sbin/httpd.worker
四、安装mysql # rpm -qa|grep mysql
mysql-libs-5.1.73-5.el6_6.x86_64
# yum install mysql-server
# rpm -qa|grep mysql
mysql-5.1.73-7.el6.x86_64
mysql-libs-5.1.73-7.el6.x86_64
mysql-server-5.1.73-7.el6.x86_64
###查看mysql安装产生的文件
# rpm -ql mysql-server
# rpm -ql mysql
# more /etc/f
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
# /etc/init.d/mysqld start
# /usr/bin/mysqladmin -u root password ‘***‘
# mysql -uroot -p
mysql> show variables like ‘port‘;
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| port | 3306 |
+---------------+-------+
###安装php连接mysql驱动
# yum install php-mysql
###查看安装完毕后生产的文件
# rpm -ql php-mysql
/etc/php.d/mysql.ini ### Author : Leshami
/etc/php.d/pdo_mysql.ini
/usr/lib64/php/modules/mysql.so
/usr/lib64/php/modules/mysqli.so
/usr/lib64/php/modules/pdo_mysql.so
###测试到mysql的连接
#vim /var/www/html/connmysql.php
<?php
$conn = mysql_connect(‘127.0.0.1‘,‘root‘,‘***‘);
if ($conn)
echo "succ";
else
echo "failure";
mysql_close();
?>
succ
五、小结
1、apache httpd与php之间的衔接是通过模块化的方式来实现。
2、对于perfork模式使用libphp5模块,worker和event模式则使用libphp5-zts模块。
3、php与mysql则通过安装php-mysql包来实现php到mysql的访问。
本文出自 “大鸟地带-点滴积累” 博客,谢绝转载!
以上是关于Linux 6下yum方式安装配置LAMP平台的主要内容,如果未能解决你的问题,请参考以下文章
CentOS 6.9 yum方式安装LAMP环境,并部署Discuz