傻瓜式搭建php+nginx+mysql服务器环境

1.安装nginx

1.安装yum

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

2.安装nginx

yum install -y nginx

3.启动nginx并设置开机自动运行

systemctl start nginx #启动,restart-重启,stop-停止

systemctl enable nginx #开机启动

4.查看版本及运行状态

nginx -v #查看版本

ps -ef | grep nginx #查看运行状态

2.安装php7

1.安装yum

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2.查看php7 yum组件,示例安装php7.2

yum search php72w

3.选择自己需要的组件安装,php72w.x86_64  php72w-fpm.x86_64 为核心程序必装

yum install php72w.x86_64 php72w-fpm.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-gd.x86_64 php72w-ldap.x86_64 php72w-mbstring.x86_64 php72w-mcrypt.x86_64 php72w-mysql.x86_64 php72w-pdo.x86_64 php72w-pecl-redis.x86_64

4.启动php并设为开机启动

systemctl start php-fpm #启动,restart-重启,stop-停止

systemctl enable php-fpm #开机启动

5.查看版本及运行状态

php-fpm -v #查看版本

ps -ef | grep php-fpm #查看运行状态

.修改nginx配置

vi /etc/nginx/conf.d/default.conf

找到第一个location中的这一行

index  index.html index.htm;

修改为:

index  index.php index.html index.htm; #添加index.php

2.

FastCGI server这行下面的location的注释去掉,并修改成下面这样子

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000

#

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;

}

service nginx restart   #重启nginx

service php-fpm start   #开启php-fpm

3.

在网站根目录新建index.php文件

vim /usr/share/nginx/html/index.php

4.

输入内容:

<?php

phpinfo();

5.

在浏览器中输入虚拟机ip,已经可以看到phpinfo的信息了 

3.安装MYSQL
yum localinstall http://dev.mysql.com/get/mysql57-community-release-el7-7.noarch.rpm

yum install mysql-community-server

//开启mysql
service mysqld start

//查看mysql的root账号的密码
grep 'temporary password' /var/log/mysqld.log

//登录mysql
mysql -uroot -p

//修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';

//修改root用户可远程登录
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

//刷新
flush privileges;

转自:https://www.cnblogs.com/crazytata/p/9686490.html

https://www.cnblogs.com/ampl/p/9881660.html;

猜你喜欢

转载自www.cnblogs.com/muzitoutou/p/10515740.html