linux centOS7 搭建lamp环境

本文详细介绍了如何在Linux环境下从源码编译安装Apache及PHP的过程,包括安装所需的依赖库、配置编译选项、修改Apache配置文件等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

编译安装Apache
1.运行命令安装相关依赖包。

yum install -y gcc gcc-c++ autoconf libtool

2.依次运行以下命令安装apr。

cd /usr/local/src/
wget http://oss.aliyuncs.com/aliyunecs/onekey/apache/apr-1.5.0.tar.gz
tar zxvf apr-1.5.0.tar.gz
cd apr-1.5.0
./configure --prefix=/usr/local/apr
make && make install

3.依次运行以下命令安装apr-util。

cd /usr/local/src/
wget http://oss.aliyuncs.com/aliyunecs/onekey/apache/apr-util-1.5.3.tar.gz
tar zxvf apr-util-1.5.3.tar.gz
cd apr-util-1.5.3
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr

make && make install

4.依次运行以下命令安装pcre。

cd /usr/local/src/
wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/pcre/pcre-8.38.tar.gz 
tar zxvf pcre-8.38.tar.gz
cd pcre-8.38
./configure --prefix=/usr/local/pcre

make && make install

5.依次运行以下命令编译安装Apache。

cd /usr/local/src/
wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/apache/httpd-2.4.23.tar.gz 
tar zxvf httpd-2.4.23.tar.gz
cd httpd-2.4.23
./configure \
--prefix=/usr/local/apache --sysconfdir=/etc/httpd \
--enable-so --enable-cgi --enable-rewrite \
--with-zlib --with-pcre=/usr/local/pcre \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--enable-mods-shared=most --enable-mpms-shared=all \
--with-mpm=event

make && make install

6.修改httpd.conf配置文件参数:

运行 cd /etc/httpd/ 切换到/etc/httpd/目录。
运行 vim httpd.conf 打开httpd.conf文件,按 i 键进入编辑模式。

找到 Directory 参数,注释掉 Require all denied,并添加 Require all granted

找到 ServerName 参数,添加 ServerName localhost:80。

设置 PidFile 路径:在文件最后添加 PidFile "/var/run/httpd.pid"。

按 Esc 键退出编辑模式,输入 :wq 保存并关闭 httpd.conf 文件。

7.依次执行以下命令启动Apache服务并验证。

cd /usr/local/apache/bin/
./apachectl start

netstat -tnlp                             #查看服务是否开启

8.设置开机自启动。

运行 vim /etc/rc.d/rc.local 打开rc.local文件,按 i 进入编辑模式。
添加 /usr/local/apache/bin/apachectl start。

编译安装PHP

1.下载php7
cd /usr/local/src/
wget -O php7.tar.gz http://cn2.php.net/get/php-7.1.1.tar.gz/from/this/mirror
2.解压PHP7
tar -xvf php7.tar.gz
3.进入PHP源文件目录
cd php-7.0.4
4.安装依赖包
yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
5.编译配置
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc/--enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --enable-inline-optimization --disable-debug --disable-rpath --enable-shared --enable-soap --with-libxml-dir --with-xmlrpc --with-openssl --with-mcrypt --with-mhash --with-pcre-regex --with-sqlite3 --with-zlib --enable-bcmath --with-iconv --with-bz2 --enable-calendar --with-curl --with-cdb --enable-dom --enable-exif --enable-fileinfo --enable-filter --with-pcre-dir --enable-ftp --with-gd --with-openssl-dir --with-jpeg-dir --with-png-dir --with-zlib-dir --with-freetype-dir --enable-gd-native-ttf --enable-gd-jis-conv --with-gettext --with-gmp --with-mhash --enable-json --enable-mbstring --enable-mbregex --enable-mbregex-backtrack --with-libmbfl --with-onig --enable-pdo --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-zlib-dir --with-pdo-sqlite --with-readline --enable-session --enable-shmop --enable-simplexml --enable-sockets --enable-sysvmsg --enable-sysvsem --enable-sysvshm --enable-wddx --with-libxml-dir --with-xsl --enable-zip --enable-mysqlnd-compression-support --with-pear --enable-opcache --with-apxs2=/usr/local/apache/bin/apxs
注意: --with-apxs2=/usr/local/apache/bin/apxs 一定要否则apache识别不到PHP
6.编译安装
make && make install
7.配置环境变量
vi /etc/profile
在末尾追加
PATH=$PATH:/usr/local/php/bin
export PATH
执行命令立即生效
source /etc/profile

修改Apache配置(让Apache可以编译PHP文件)
在配置文件httpd.conf追加以下代码
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
定位到DirectoryIndex  添加index.php

重启Apache

注意:启动报
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
#vim /web/apache/conf/httpd.conf (在这里/web/apahce是我安装apache的目录,你默认安装的话应该是/usr/local/apache2/icons)

找到#ServerName www.example.com:80   把#去掉,再重启apache即可没事了。

现象:

bogon:~/webserver/httpd-2.0.59 # /usr/local/apache2/bin/apachectl start
httpd: Could not determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
httpd (pid 20183) already running

這個問題應該是沒有在 /etc/httpd/conf/httpd.conf 中設定 ServerName  

vi /usr/local/apache2/conf/httpd.conf

最简单的,修改httpd.conf文件,增加:
ServerName www.example.com:80
我的改为:

ServerName localhost:80


再次启动就正常了!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值