配置MySQL
1.準備網路yum源(準備物理機或一臺虛擬機作為倉庫服務器)
[root@zzgrhel8 ~]# yum install -y httpd php php-mysqlnd php-xml php-json createrepo [root@zzgrhel8 ~]# systemctl start httpd [root@zzgrhel8 ~]# systemctl enable httpd [root@zzgrhel8 ~]# mkdir /var/www/html/mysql [root@zzgrhel8 ~]# cd /linux-soft/4/mysql/ [root@zzgrhel8 ~]# tar xf mysql-5.7.17.tar -C /var/www/html/mysql/ [root@zzgrhel8 ~]# cd /var/www/html/mysql/ [root@zzgrhel8 mysql]# createrepo -d .2.在mysql服務器上安裝并啟動mysql-community 5.7
[root@mysql1 ~]# vim /etc/yum.repos.d/mysql.repo [mysql] name=mysql5.7 baseurl=http://你主機的ip地址/mysql enabled=1 gpgcheck=0 [root@mysql1 ~]# yum install mysql-community* [root@mysql1 ~]# systemctl start mysqld [root@mysql1 ~]# systemctl enable mysqld3.修改mysql密碼,匯入案例資料庫
# 啟動Mysql服務時,自動生成了隨機密碼,寫入日志mysqld.log, # 在mysqld.log中查看生成的密碼 [root@mysql1 ~]# grep -i password /var/log/mysqld.log # 修改資料庫的root用戶密碼為NSD2021@tedu.cn [root@mysql1 ~]# mysqladmin -uroot -p'A8cCwrjefY(v' password NSD2021@tedu.cn創建資料庫 # 授權root用戶可以通過任何地址訪問 mysql> grant all on *.* to 'root'@'%' identified by 'NSD2021@tedu.cn'; # 創建名為mybbs的資料庫 mysql> create database mybbs default charset utf8mb4; mysql> use mybbs ; # 創建名為posts的表,有四個欄位,用于存盤留言 mysql> create table posts( id int primary key auto_increment, title varchar(50), pub_date datetime, content text);
配置nginx服務器
# 安裝編譯器 [root@nginx1 ~]# yum install -y gcc pcre-devel zlib-devel ? # 編譯安裝nginx [root@nginx1 ~]# tar xf nginx-1.12.2.tar.gz [root@nginx1 ~]# cd nginx-1.12.2 [root@nginx1 nginx-1.12.2]# ./configure [root@nginx1 nginx-1.12.2]# make && make install ? # 安裝并啟動php-fpm [root@nginx1 ~]# yum install -y php-fpm php-mysql [root@nginx1 ~]# systemctl start php-fpm [root@nginx1 ~]# systemctl enable php-fpm ? # 修改組態檔 [root@nginx1 ~]# vim +65 /usr/local/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.conf; } ? # 啟動nginx服務 [root@nginx1 ~]# /usr/local/nginx/sbin/nginx -t # 語法檢查 nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful ? [root@nginx1 ~]# /usr/local/nginx/sbin/nginx
修改php首頁
# 拷貝php_mysql_bbs目錄下所有內容到nginx的檔案目錄 [root@nginx1 ~]# cp -r tedu_nsd/software/php_mysql_bbs/* /usr/local/nginx/html/ ? # 修改php頁面,使其可以連接到資料庫 [root@nginx1 ~]# cd /usr/local/nginx/html/ [root@nginx1 html]# vim index.php # 只修改第2行 ... ... //以下函式的三個引數分別為:服務器地址、用戶名、密碼 $con = mysql_connect("localhost","root","NSD2021@tedu.cn"); ... ...
?
# 使用瀏覽器訪問http://web服務器地址/index.php
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/299636.html
標籤:其他
上一篇:動態記憶體管理詳解(動態記憶體函式介紹 + 常見動態記憶體錯誤 + 經典筆試題)
下一篇:Linux自我學習筆記
