1.安装Apache
安装centos7默认自带(Apache2.4.6)版本
yum -y install httpd
2.开启apache服务
systemctl start httpd.service
3.设置apache服务开机启动
systemctl enable httpd.service
4.开启防火墙
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
firewall-cmd --permanent --zone=public --add-service=http
5.开启80端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
在浏览器中输入你虚拟机的ip地址,如果看到apache默认的页面--有Testing 123...字样,便是成功安装了apache服务了
6.安装php
a、默认centos7 自带的是php5.4版本,升级php5.6。不升级只有yum 安装
b、升级php5.6
yum install epel-release
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
7.安装PHP5.6.x
yum源配置好了,下一步就安装PHP5.6
yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof php-gd php-redis
安装PHP-fpm
yum install --enablerepo=remi --enablerepo=remi-php56 php-fpm
8.重启apache
systemctl restart httpd.service
9.测试是否成功
然后,你可以写一个php文件在浏览器中运行一下了;
eg:
vi /var/www/html/info.php
i
<?php phpinfo(); ?>
Esc
:wq
然后,在自己电脑浏览器输入 虚拟机ip/info.php运行,会出现php的配置一些信息安装成功
-------------------------------------下面安装nginx-----------------------------------------------------------------------------------
1. 在安装nginx前,先要安装依赖包
yum -y install gcc gcc-c++ pcre pcre-devel zlib zlib-devel openssl-devel
2.下载nginx对应的tar包
wget http://nginx.org/download/nginx-1.13.7.tar.gz
3.解压tar 包
tar zxvf nginx-1.13.7.tar.gz
4.创建nginx 目录
mkdir -p /usr/local/nginx
进入
cd nginx-1.13.7
./configure --prefix=/usr/local/nginx
make && make install
5.进入nginx/sbin目录启动nginx
cd /use/local/nginx/sbin
启动nginx
./nginx
6.Nginx中其他简单的操作也类似
cd /use/local/nginx/sbin
重新载入配置
./nginx -s reload
重新启动Nginx
./nginx -s reopen
停止Nginx
./nginx -s stop
7.php-fpm,并设置php-fpm开机自启
service php-fpm start
chkconfig php-fpm on
8.在相应的目录下找到nginx.conf配置文件,这里是在默认目录下,开启Nginx支撑PHP的模块
cd /usr/local/nginx/conf 进入Nginx配置目录
vim nginx.conf 配置nginx.conf文件
修改前
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
修改后
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
首先将注释,也就是#号去掉,接着将fastcgi_param对应的/scripts$fastcgi_script_name改成$document_root$fastcgi_script_name
保存完修改后的配置,重启一下nginx,让配置生效,我们就可以通过nginx来处理PHP请求了
-----------------------------------------nginx end----------------------------------------------------------------------------
-------------------------------------------------安装mysql----------------------------------------------------------------------------------------
1.安装mysql5.7
centos7不自带mysql5.7 rmp 包需自己手动步骤如下
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
// 或者使用
wget http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
rpm -ivh mysql57-community-release-el7-9.noarch.rpm
2.安装mysql5.6
yum -y install mysql-community-server
3.配置mysql
MySQL 安装完成之后,在 /var/log/mysqld.log 文件中给 root 生成了一个默认密码
通过下面的方式找到root 默认密码,然后登录 MySQL 进行修改:
systemctl start mysqld
grep 'temporary password' /var/log/mysqld.log # 查找默认密码
2017-04-10T02:58:16.806931Z 1 [Note] A temporary password is generated for root@localhost: !E+rhl4VGhh(密码)安装完成之后,在 /var/log/mysqld.log
4.登录 MySQL:(如果登入不成功提示错误请用步骤4)
mysql -uroot -p'!E+rhl4VGhh'
修改root 默认密码:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyPass1!';
或者:
mysql> set password for 'root'@'localhost'=password('123abc');
注:
MySQL5.7 默认安装了密码安全检查插件(validate_password),默认密码检查策略要求密码必须包含:大小写字母、数字和特殊符号,并且长度不能少于8位。否则会提示 ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 错误
5.配置mysql
登入数据库对mysq进行操作
mysql -uroot -p'密码'
show databases;