1. 程式人生 > >傻瓜式搭建php+nginx+mysql服務器環境

傻瓜式搭建php+nginx+mysql服務器環境

遠程登錄 mct efault get html mysql5 找到 mysql location

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;

傻瓜式搭建php+nginx+mysql服務器環境