Linux(CentOS7)搭建LAMP服务环境

简介: 本文介绍了在Linux (CentOS 7) 上搭建LAMP服务环境的详细步骤,包括安装Apache HTTPd、解决编译时依赖问题、配置Apache服务、安装PHP以及处理PHP与Apache集成时遇到的问题。同时,还涉及了防火墙设置和SELinux权限调整,确保Web服务能够正常运行。

1、MySQL高版本5.7及以上安装在CentOS7x64位系统,安装过程在以往笔记里找,这里不再赘述;

2、安装Apache-Httpd,下载地址:http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.23.tar.gz

在编译安装Apache(httpd-2.4.3)时分别出现了apr not found、APR-util not found、pcre-config for libpcre not found的问题,下面就httpd-2.4.3的这些问题解决来实际操作一把。

http://apr.apache.org/download.cgi 下载apr-1.4.5.tar.gz、apr-util-1.3.12.tar.gz

https://sourceforge.net/projects/pcre/files 下载pcre-8.31.zip 或者 pcre2-10.22.tar.gz

1.解决apr not found问题

[root@localhost bin]# tar -zxf apr-1.5.2.tar.gz

[root@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr

[root@localhost apr-1.5.2]# make && make install

[root@localhost apr-1.5.2]# make install

2.解决APR-util not found问题

[root@localhost bin]# tar -zxf apr-util-1.5.4.tar.gz

[root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr/

[root@localhost apr-util-1.5.4]# make && make install

[root@localhost apr-util-1.5.4]# make install

在安装apr-util时,缺少/opt/apr-util-1.5.4/xml/expat/libexpat.la文件 

在当前目录 执行命令:yum search libexpat 即可解决;

3、解决pcre-config for libpcre not found问题

[root@localhost ~]# unzip pcre-8.10.zip 

[root@localhost ~]# cd pcre-8.10 

[root@localhost pcre-8.10]# ./configure --prefix=/usr/local/pcre 

[root@localhost pcre-8.10]# make && make install

先将支持Apache-httpd的几个程序安装完,之后在安装Apache【反正安装没坏处】

解压Apache:tar -zxvf Apache-httpd-2.4.24.tar.gz

md5sum httpd-2.4.23.tar.gz

tar zvxf httpd-2.4.23.tar.gz 

./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --enable-modules=all --enable-rewrite  --enable-ssl --with-ssl --enable-cgid --enable-cgi

apr是为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库

2.4.23Apche之后的编译版本命令有所不同:

(除了指定Apache的安装目录外,还要安装apr、apr-util、pcre,并指定参数)make && make install

因为httpd默认端口:80,已经给tomcat使用了,所以要去安装目录/usr/local/apache/conf/httpd.conf

vim它,修改它的listener:80,变成8082

启动:/usr/local/apache/bin/apachectl start 报错:AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. 

Set the 'ServerName' directive globally to suppress this message

vim httpd.conf 配置文件,增加一行:ServerName  localhost[先配置虚拟机ip]:8081

防火墙开启端口8081,windows可远程访问apachehttpd服务

iptables -I INPUT -p tcp --dport 80 -j ACCEPT

CentOS7防火墙设置:firewall-cmd --zone=public --add-port=8082/tcp --permanent

  防火墙重启: firewall-cmd --reload

•停止Apache:/usr/local/apache/bin/apachectl stop

•重启Apache:/usr/local/apache/bin/apachectl restart

cp /usr/local/apache/bin/apachectl /etc/init.d/httpd #复制服务到服务列表

如果复制没有权限,使用软链接:ln -s /usr/local/apache/bin/apachectl /etc/init.d/httpd

service httpd start / stop restart 启动httpd

chmod 755 /etc/init.d/httpd  

chkconfig --add httpd 报错:service httpd does not support chkconfig

解决办法:打开vi /etc/rc.d/init.d/httpd 添加(#!/bin/sh下面) 

#description: Activates/Deactivates Apache Web Server

3、安装PHP(下载php-5.5-.38.tar.gz)

  • 因为httpd默认端口:80,已经给tomcat使用了,所以要去安装目录/usr/local/apache/conf/httpd.conf
    
    vim它,修改它的listener:80,变成8082
    
    启动:/usr/local/apache/bin/apachectl start 报错:AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. 
    
    Set the 'ServerName' directive globally to suppress this message
    
    vim httpd.conf 配置文件,增加一行:ServerName  localhost[先配置虚拟机ip]:8081
    
    防火墙开启端口8081,windows可远程访问apachehttpd服务
    
    iptables -I INPUT -p tcp --dport 80 -j ACCEPT
    
    CentOS7防火墙设置:firewall-cmd --zone=public --add-port=8082/tcp --permanent
    
      防火墙重启: firewall-cmd --reload
    
    •停止Apache:/usr/local/apache/bin/apachectl stop
    
    •重启Apache:/usr/local/apache/bin/apachectl restart
    
    cp /usr/local/apache/bin/apachectl /etc/init.d/httpd #复制服务到服务列表
    
    如果复制没有权限,使用软链接:ln -s /usr/local/apache/bin/apachectl /etc/init.d/httpd
    
    service httpd start / stop restart 启动httpd
    
    chmod 755 /etc/init.d/httpd  
    
    chkconfig --add httpd 报错:service httpd does not support chkconfig
    
    解决办法:打开vi /etc/rc.d/init.d/httpd 添加(#!/bin/sh下面) 
    
    #description: Activates/Deactivates Apache Web Server
    

    make: *** [sapi/cli/PHP] 错误 1

#make clean  

#make

<?php>

phpinfo();

<?>

浏览器打开测试test.php,环境不能解析php代码,访问出现源代码;

修改vim /usr/local/apache/conf/httpd/conf

找到AddType内容

#添加[MIME映射](https://www.baidu.com/s?wd=MIME%E6%98%A0%E5%B0%84&tn=44039180_cpr&fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1YdmHc4rH6LuWfdPAFbnhnv0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3En1RLnHf1PHcY),让apache把PHP文件当成代码文件来执行

AddType application/x-httpd-php .php .phtml

重启apache--httpd服务就好了

\[so:warn\] \[pid 3020:tid 139963331409728\] AH01574: module php5\_module is already loaded, skipping

apache重装php环境,重复加载php5\_module模块,编辑apache/conf/httpd.conf 删除即可;

(20014)Internal error (specific information not available): AH00058: Error retrieving pid file logs/httpd.pid

要删除apache/logs/httpd.pid这个进程文件;
相关文章
|
9月前
|
Linux 网络安全 Docker
盘古栈云,创建带ssh服务的linux容器
创建带ssh服务的linux容器
467 146
|
9月前
|
存储 Linux 开发工具
Linux环境下使用Buildroot配置软件包
使用Buildroot可以大大简化嵌入式Linux系统的开发和维护工作,但它需要对Linux系统和交叉编译有深入的理解。通过上述步骤,可以有效地配置和定制软件包,为特定的嵌入式应用构建高效、稳定的系统。
980 11
|
10月前
|
缓存 安全 Linux
六、Linux核心服务与包管理
在没有网络的情况下,使用系统安装光盘是获取RPM包的常用方法。场景二:配置本地文件镜像源 (使用系统安装光盘/ISO)(检查RPM包的GPG签名以保证安全) 或。YUM/DNF包管理工具 (yum/dnf)(此处可以放置您为本主题制作的思维导图)处理依赖问题的危险选项 (应极力避免)(覆盖文件、替换已安装包)。(list) 则是列出文件。(query file) 是。(假设系统安装光盘已挂载到。信息 (verbose)。(upgrade) 选项。(all) 已安装的包。(package) 选项
675 11
|
11月前
|
Linux
Linux环境下的UDEV机制及其与守护进程的关联
实际使用时管理员需要熟悉编写合适udev rules去满足特殊需求;同时也需要注意避免编写过度复杂导致无法预料结果rules.UDEVD虽然稳健但错误配置可能导致无法预料问题因此需谨慎处理相关配置工作.
392 16
|
Linux 应用服务中间件 nginx
CentOS7 自定义服务
服务配置 服务配置主目录存放路径 # cd /usr/lib/systemd/system 文件内容格式 [Unit]:服务的说明 Description:描述服务 After:在哪些描述服务类别之后启动 [Service]服务运行参数的设...
1032 0
|
11月前
|
存储 Ubuntu Linux
VMware-安装CentOS系统教程及安装包
虚拟机相当于是一个独立于你电脑的环境,在这个环境上面,你可以安装Linux、Windows、Ubuntu等各个类型各个版本的系统,在这个系统里面你不用担心有病读等,不用担心文件误删导致系统崩溃。 虚拟机也和正常的电脑系统是一样的,也可以开关机,不用的时候,你关机就可以了,也不会占用你的系统资源,使用起来还是比较方便 这里也有已经做好的CentOS 7系统,下载下来解压后直接用VMware打开就可以使用
1646 69
|
10月前
|
存储 分布式计算 Linux
安装篇--CentOS 7 虚拟机安装
VMware 装 CentOS 7 不知道从哪下手?这篇超详细图文教程手把手教你在 VMware Workstation 中完成 CentOS 7 桌面系统的完整安装流程。从 ISO 镜像下载、虚拟机配置,到安装图形界面、设置用户密码,每一步都有截图讲解,适合零基础新手快速上手。装好之后无论你是要搭 Hadoop 集群,还是练 Linux ,这个环境都够你折腾一整天!
4404 3
|
11月前
|
Ubuntu Linux 索引
Centos 7、Debian及Ubuntu系统中安装和验证tree命令的指南。
通过上述步骤,我们可以在CentOS 7、Debian和Ubuntu系统中安装并验证 `tree`命令。在命令行界面中执行安装命令,然后通过版本检查确认安装成功。这保证了在多个平台上 `tree`命令的一致性和可用性,使得用户无论在哪种Linux发行版上都能使用此工具浏览目录结构。
960 78