一、配置防火墙
CentOS 7.0默认使用的是firewall作为防火墙。
1、关闭firewall:
- systemctl stop firewalld.service
- systemctl disable firewalld.service
2、关闭SELINUX
- vi /etc/selinux/config
-
- SELINUX=disabled
- :wq!
- setenforce 0
SELINUX=enforcing 把这个注释
加上这个
SELINUX=disabled
3.安装apache
- yum install httpd
- systemctl start httpd.service
- systemctl stop httpd.service
- systemctl restart httpd.service
- systemctl enable httpd.service
4.安装mariadb(mysql)
- yum install mariadb mariadb-server
- systemctl start mariadb.service
- systemctl stop mariadb.service
- systemctl restart mariadb.service
- systemctl enable mariadb.service
- mysql
- 修改mysql密码:set password for 'root'@'localhost'=password('root');
- mysql -u root -p
- 输密码 root
- mysql授权远程连接(navicat等): grant all on *.* to root identified by 'root';
5、安装PHP以及组件,使PHP支持 MariaDB
- yum install php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-bcmath php-mhash
-
- systemctl restart mariadb.service
- systemctl restart httpd.service
测试篇
apache的配置文件在:/etc/httpd/conf/httpd.conf
cd /var/www/html
vi index.php #输入下面内容
<?php
phpinfo();
?>
:wq! #保存退出
在客户端浏览器输入服务器IP地址,可以看到如下图所示相关的配置信息
安装nginx
- yum install yum-priorities -y
- wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
- rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm
- yum install nginx
- systemctl start nginx.service
- systemctl stop nginx.service
- systemctl restart nginx.service
- systemctl enable nginx.service
2.更改nginx端口号(根据自己需求)
- cd /etc/nginx/conf.d/
- vim default.conf
- 把listen 80改成listen 81
- systemctl restart nginx.service
下一步安装php-fpm
- systemctl start php-fpm.service
- systemctl enable php-fpm.service
5.更改nginx配置文件识别php
vi /etc/nginx/conf.d/default.conf,把之前的#给去掉就可以了,顺手改一下fastcgi_param
- location ~ \.php$ {
- root html;
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_index index.php;
- fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name;
- include fastcgi_params;
- }
7.负载配置
- upstream site{
- server 172.16.170.138;
- server 172.16.170.139;
- }
- server {
- listen 80;
- server_name localhost;
-
-
-
-
- location / {
- root /usr/share/nginx/html;
- index index.html index.htm;
- proxy_pass http://site;
- }
/usr/share/nginx/html
apache的配置文件详解:http://www.cnblogs.com/Sabre/p/3734008.html