CentOS7 下 Yum 安装 LNMP PHP5.6及其扩展

Introduction

Step 1、Install Nginx

Step 2、Install Apache

Step 3、Install MYSQL

Step 4、Install PHP5.6

Step 5、Install memcached


Step 1、Intall Nginx

1、使用yum安装nginx需要包括Nginx的库,安装Nginx的库

rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

2、使用下面命令安装nginx

yum install nginx

3、修改监听端口号

这里我们使用nginx监听8080端口,使用Apache监听80端口,修改nginx配置:

vim /etc/nginx/conf.d/default.conf

1
 

listen  80 修改为 listen 8080

4、启动Nginx

systemctl start nginx.service
systemctl status nginx.service

5、设置自动启动

cd /etc/systemd/system/multi-user.target.wants/
systemctl enable nginx.service

Step 2、Intall Apache

1、安装apache

yum install httpd

2、修改配置

vim /etc/httpd/conf/httpd.conf

(1)# ServerName www.example.com:80

取消#,并修改为ServerName 域名:8080(如果没有域名的话,就设为localhost)

3、启动apache

systemctl start httpd.service

4、查看启动状态

systemctl status httpd.service

5、设置自动启动

cd /etc/systemd/system/multi-user.target.wants/
systemctl enable httpd.service

Step 3、Intall MYSQL

CentOS7的yum源中默认好像是没有mysql的。为了解决这个问题,我们要先下载mysql的repo源

1、下载mysql的repo源

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm

2、安装mysql-community-release-el7-5.noarch.rpm包

rpm -ivh mysql-community-release-el7-5.noarch.rpm

3、安装mysql

yum install mysql-server

4、启动mysql

systemctl start mysqld.service
systemctl status mysqld.service

5、设置自动启动

cd /etc/systemd/system/multi-user.target.wants/

1
 
systemctl enable mysqld.service

Step 4、Intall PHP5.6

1、检查当前安装的PHP包

yum list installed | grep php

如果有安装的PHP包,先删除他们

yum remove php.x86_64 php-cli.x86_64 php-common.x86_64 php-gd.x86_64 php-ldap.x86_64 php-mbstring.x86_64 php-mcrypt.x86_64 php-mysql.x86_64 php-pdo.x86_64

2、配置yum源

以下是CentOS 7.0的源

yum update
yum install epel-release
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm

使用yum list命令查看可安装的包(Packege)

yum list --enablerepo=remi --enablerepo=remi-php56 | grep php

3、安装PHP5.6.x

yum源配置好了,下一步就安装PHP5.6

yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-pecl-apcu php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-pdo php-pear php-fpm php-cli php-xml php-bcmath php-memcache php-memcached php-process php-gd php-common

用PHP命令查看版本

php --version

4、安装PHP-fpm

yum install --enablerepo=remi --enablerepo=remi-php56 php-fpm

5、PHP配置

vim /etc/php.ini

设置 date.timezone = PRC

systemctl restart httpd.service

重启之后我们进行测试PHP相关信息,我们新建一个PHP界面进行测试

vi /var/www/html/index.php

按  i   进行编辑,输入:

<?php

phpinfo();

?>

编辑完毕,保存退出

此时我们访问这个页面,输入localhost,就会出现一个现实PHP信息的网页,说明你的PHP安装成功了。

Step 5、Install memcached

yum install memcached
memcached -d -p 11211 -u memcached -m 1024 -c 1024 -P /var/run/memcached/memcached.pid -l 10.141.104.150
memcached -h
systemctl enable memcached