CentOS编译安装nginx、memcache、httpd、php

本文详细介绍了如何在CentOS 7环境中从源码安装LAMP(Linux、Apache、MySQL、PHP)套件,包括停用防火墙及SELINUX、安装nginx、memcached、httpd、php及其相关扩展的过程。

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

一、安装nginx:

nginx官网:http://nginx.org

1、关闭firewall(这是centos7中的防火墙)
systemctl stop firewalld.service          #停止firewall  
systemctl disable firewalld.service       #禁止firewall开机启动 










2、关闭SELINUX(这也是centos7)
vi /etc/selinux/config  
#SELINUX=enforcing                        #注释掉  
SELINUX=disabled                          #增加  
:wq!                                      #保存退出  
setenforce 0                              #使配置立即生效

3、先安装nginx依赖PCRE库
yum  install  pcre                        #如果提示以安装PCRE库,那就执行以下命令
yum  install  pcre-devel                  #这个也安装的话,就执行下面的命令行

4、进入安装目录
cd  /usr/local/src
wget  http://nginx.org/download/nginx-1.10.2.tar.gz
tar zxvf nginx-1.10.2.tar.gz
cd nginx-1.10.2/
./configure --prefix=/usr/local/nginx
make && make install

5、启动
cd /usr/local/nginx
进vim /usr/local/nginx/conf/nginx.conf下修改端口为:8080
./sbin/nginx

此时我们安装nginx就完成了!


二、安装memcached:

memcached官网:www.memcached.org/

libevent  官网:http://libevent.org/                          (memcached的依赖库)


1、安装gcc,make,autoconf,libtool系列工具
yum install gcc make libtool autoconf                          #已安装的不用安装

2、安装libevent库
cd /usr/local/src
wget  https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz --no-check-certificate
tar zxvf libevent-2.0.22-stable.tar.gz
cd libevent-2.0.22-stable/
./configure --prefix=/usr/local/libevent                      #检查编译环境
make && make install

注意:在虚拟机下练习编译,一个容易碰到的问题----虚拟机的时间不对,导致的gcc编译过程中,检测时间通不过,一直处于编译过程!
解决:
date -s  ‘yyyy-mm-dd hh:mm:ss’
date -w                                          #把时间写入 cmos

3、安装memcached
cd  /usr/local/src
wget  http://www.memcached.org/files/memcached-1.4.34.tar.gz
tar zxvf memcached-1.4.34.tar.gz
cd memcached-1.4.34/
./configure --prefix=/usr/local/memcached --with-libevent=/usr/local/libevent/cd memcached-1.4.34/                      
make && make install

4、启动memcached
cd   /usr/local/src/memcached
./bin/memcached -p 11211 -m 64 -u nobody -d          #因为memcached拿root用户连接存在威胁,所以用-u 指定一个用户来连接!  -d以后台进程来执行

三、安装httpd

htppd官网:httpd.apache.org/

1、进入安装目录
cd /usr/local/src
wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.25.tar.gz
tar zxvf httpd-2.4.25.tar.gz
cd httpd-2.4.25/
如果在检测环境时报以下错误:

解决:
安装apr
cd  /usr/local/src
wget http://mirrors.cnnic.cn/apache//apr/apr-1.5.2.tar.gz
cd /apr-1.4.6
./configure --prefix=/usr/local/apr
make && make install
安装apr-util
wget http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.gz
tar zxvf apr-util-1.5.4.tar.gz
cd apr-util-1.5.4/
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make  install

安装完后在httpd-2.4.25目录下执行就不会报错:
./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
make && make  install
2、启动httpd
cd   /usr/local/httpd
./bin/apachectl  start
如果在浏览器上访问出现:It  works!表示安装成功!







 
四、安装php
php官网:php.net
1、安装
下载地址:http://jp2.php.net/get/php-5.6.29.tar.gz/from/this/mirror

如果使用命令行下载不下来就在Windows上下载以后再使用!

tar zxvf php-5.6.29.tar.gz 
cd php-5.6.29/


./configure --prefix=/usr/local/php --with-apxs2=/usr/local/httpd/bin/apxs

出现:Thank you for using PHP. 说明安装成功!

make  &&  make  install

2、编辑httpd.conf文件
cd    /usr/local/httpd/conf
vim   httpd.conf
./bin/apachectl restart                  #重启apache
cd   htdocs/vim  test.php                     #编写php代码,输出phpinfo就可以了

访问xxxxx/test.php,能显示就说明apache成功的解析了php代码:




五、安装memcached的php扩展(通用的方法)

php扩展网址:pecl.php.net/

1、先安装libmemcached
wget  https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
tar  zxvf libmemcached-1.0.18.tar.gz
cd   libmemcached-1.0.18/
./configure  --prefix=/usr/local/libmemcached   --with-memcached
make && make install


2、安装memcached扩展
cd    /usr/local/src
wget  http://pecl.php.net/get/memcached-2.2.0.tgz
tar   zxvf memcached-2.2.0.tgz
cd   memcached-2.2.0/
/usr/local/php/bin/phpize --with-php-config=/usr/local/php/bin/php-config   
#上面一行命令是:装扩展通用,作用是“通过phpize动态的判断当前的环境,并且创建
符合环境的扩展编译脚本!”
./configure --enable-memcached  --with-php-config=/usr/local/php/bin/php-config --with-libme
mcached-dir=/usr/local/libmemcached --disable-memcached-sasl
make && make install

3、修改php.ini



 

进入/usr/local/php/lib/中你会发现没有php.ini
cp /usr/local/src/php-5.6.29/php.ini-development /usr/local/php/lib/php.ini  #拷贝一份过来
vim   php.ini
extension=/usr/local/php/lib/php/extensions/no-debug-zts-20131226/memcached.so   #加入


4、重启httpd
/usr/local/httpd/bin/apachectl  restart



就此:memcached的扩展已经装完!



CentOS7中yum安装lamp环境地址:
http://blog.youkuaiyun.com/zph1234/article/details/51248124




















可以使用 LAMP 或 LNMP 等一键安装包来快速搭建 CentOS 上的 PHP 开发环境。 LAMP(Linux + Apache + MySQL + PHP)是常用的一键安装包,以下是安装步骤: 1. 安装 Apache ```bash yum install httpd -y systemctl start httpd systemctl enable httpd ``` 2. 安装 MySQL ```bash yum install mariadb-server mariadb -y systemctl start mariadb systemctl enable mariadb mysql_secure_installation ``` 3. 安装 PHP ```bash yum install php php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml -y ``` 4. 配置 PHP 编辑 `/etc/httpd/conf.d/php.conf` 文件,将以下内容复制到文件末尾: ``` <FilesMatch \.php$> SetHandler application/x-httpd-php </FilesMatch> ``` 重启 Apache: ```bash systemctl restart httpd ``` LNMP(Linux + Nginx + MySQL + PHP)也是常用的一键安装包,以下是安装步骤: 1. 安装 Nginx ```bash yum install nginx -y systemctl start nginx systemctl enable nginx ``` 2. 安装 MySQL 参考 LAMP 安装步骤。 3. 安装 PHP ```bash yum install php-fpm php-mysql php-devel php-gd php-pecl-memcache php-pspell php-snmp php-xmlrpc php-xml -y ``` 4. 配置 NginxPHP 编辑 `/etc/nginx/conf.d/default.conf` 文件,将以下内容复制到文件中: ``` location ~ \.php$ { root /usr/share/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } ``` 编辑 `/etc/php-fpm.d/www.conf` 文件,将以下内容修改为: ``` listen = 127.0.0.1:9000 ``` 重启 NginxPHP-FPM: ```bash systemctl restart nginx systemctl restart php-fpm ``` 以上是简单的一键安装步骤,如果需要更复杂的配置,可以参考相关文档进行设置。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值