作为一个PHP程序员,一定要会在linux下搭建自己的开发环境。
一、环境声明
Linux:CentOS7
Apache:Apache2.4
二、依赖列表
apr-1.6.5.tar.gz (获取:wget http://mirror.bit.edu.cn/apache//apr/apr-1.6.5.tar.gz)
apr-util-1.6.1.tar.gz (获取:wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz)
pcre-8.43.tar.gz (获取:wget https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gz)
前三个是所需要的依赖包。
httpd-2.4.38.tar.gz (获取:wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.38.tar.gz)
这些包只有编译安装时才会用到。
三、安装
1.yum安装,一步搞定
yum install httpd
2.编译安装
apr:
./configure -prefix=/usr/local/apr && make && make install
apr-util:
需要安装expat库
yum install expat-devel
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr && make && make install
pcre:
./configure --prefix=/usr/local/pcre && make && make install
httpd:
./configure --prefix=/lamp/httpd --enable-so --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre && make && make install
apache使用php模块:--enable-so 需要这个参数
四、其他配置
1.防火墙开启80和443端口
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
2.apache解析PHP文件
AddType application/x-httpd-php .php
3.设置为系统服务
cp /lamp/httpd/bin/apachectl /etc/init.d/httpd
4.添加index.php
DirectoryIndex index.html index.php
到此apache的安装就完成了。