一:yum源
基于centos7.1
cat *.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
二、安装httpd。
yum -y install httpd
安装完成之后使用以下命令启动httpd服务:
systemctl restart httpd.service #重启apache
systemctl enable httpd.service #设置apache开机启动
systemctl stop firewalld.service
systemctl disable firewalld.service //禁止防火墙开机启动
关闭SeLinux:
setenforce 0临时关闭
三、安装MySQL数据库。
MySQL数据库,新版本已经更名为Mariadb,所以这里需要安装Mariadb,可以使用下面的命令进行安装:
yum install -y mariadb-server mariadb
安装完成以后使用下面的命令开启数据库服务:
systemctl restart mariadb.service #重启MariaDB
systemctl enable mariadb.service #设置开机启动
四、安装PHP。
使用下面的命令可以安装PHP:
yum -y install php
使用下面的命令安装php对Mariadb的支持:
yum install php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
使用下面的命令重启Mariadb和httpd服务:
systemctl restart mariadb.service #重启MariaDB
systemctl restart httpd.service #重启apache
五、安装nginx。
yum install -y nginx
要想使用nginx做反向代理,需要修改Apache的httpd和nginx的配置文件,使其监听不同的端口,这里我们使用nginx监听80端口,使用Apache监听8080端口,这里我们分别配置Apache和nginx的配置文件,修改结果如下:
(1)Apache配置文件:/etc/httpd/conf/httpd.conf
Listen 8080
(2)nginx配置如下:
server {
listen 80;
server_name localhost;
location ~ \.php$ {
proxy_pass http://127.0.0.1:8080;
}
}
systemctl restart httpd
systemctl restart nginx
六:测试
cd /var/www/html/
vim test.php
<?php
.phpinfo();
?>
http://172.25.254.200/test.php
链接数据库测试
mysql
set password=password('Taren1');
vim test11.php
<?php
$link=mysql_connect('localhost','root','Taren1');
if($link) echo "Success !!"; //成功则显示Success !!
else echo "Failure !!"; //失败则显示Failure !!
mysql_close(); //关闭数据库连接
?>
http://172.25.254.200/test11.php