首頁  >  文章  >  後端開發  >  教你玩轉linux下部署php專案-Apache、php、mysql關聯(分享)

教你玩轉linux下部署php專案-Apache、php、mysql關聯(分享)

慕斯
慕斯轉載
2021-06-10 09:44:213932瀏覽

這篇文章跟大家分享教你玩轉linux下部署php專案-Apache、php、mysql關聯(分享)有一定的參考價值,有需要的朋友可以參考一下,希望對大家有幫助。

教你玩轉linux下部署php專案-Apache、php、mysql關聯(分享)

  linux下部署php專案環境可以分為兩種,一種使用Apache,php,mysql的壓縮包安裝,一種用yum指令進行安裝。

使用三種軟體的壓縮套件進行安裝,需要手動配置三者之間的關係。 apache和php之間的配置沒有什麼難度,但是和mysql進行配置的時候就需要對php的了解了。

以下是用yum在linux中設定php環境:

MySql

  1.mysql和apache最好是先安裝的,因為在配置php的時候需要與mysql和apache進行關聯配置和測試

首先下載mysql-sever文件,因為博主linux環境是CentOS版本,yum源中看似沒有正常安裝mysql時的mysql-sever文件,需要去官網上下載

1.下载mysql-service文件
[root@tele-1 ~]# wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
2.安装mysql-service文件
[root@tele-1 ~]# rpm -ivh mysql-community-release-el7-5.noarch.rpm

 2.安裝mysql

[root@tele-1 ~]# yum install mysql-community-server

 3.安裝完畢後啟動mysql服務

[root@tele-1 ~]# service mysqld restart

# 3.安裝完畢之後啟動mysql服務

[root@tele-1 ~]# mysql -uroot
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 474801
Server version: 5.6.36 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

4. 初步安裝的mysql是沒有密碼的,使用者名稱預設是root。所以我們需要修改密碼,用mysql命令列進行修改

 

1.進入mysql命令列

2.使用命令进行密码修改
mysql> set password for 'root'@'localhost' = password('你要修改的密码');
Query OK, 0 rows affected (0.06 sec)
1.操作mysql数据库表

 5.因為博主是用本地navicat軟體來連接linux下的mysql的,所以如果要在本地存取的話,就需要改一下mysql資料庫中的user表了

mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql>

2.查看user表中的数据(在mysql命令行中可以直接进行sql语句编写)
mysql> select * from user;
mysql>
mysql> update user set Host = '%' where ???

# 3.博主的表中是修改之後的表了,想要遠端訪問,就需要上邊紅色標註的資料了,Host指的是可以存取此資料庫的ip位址,%代表的是所有的請求都可以連接進來。

大家可以修改一條數據,也可以增加一條數據。但最好不要修改上邊藍色標註的數據,修改語句就是下邊的格式

mysql> \q
Bye

# 4.最後推出exit或\q都是退出mysql指令行的方法#
[root@tele-2 ~]# yum install httpd

 安裝Apache

 1.apache安裝方法相對簡單

[root@tele-2 ~]# service httpd start
Redirecting to /bin/systemctl start  httpd.service
[root@tele-2 ~]# service httpd status
Redirecting to /bin/systemctl status  httpd.service
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2017-06-05 15:57:34 CST; 5s ago
     Docs: man:httpd(8)
           man:apachectl(8)
  Process: 54532 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
  Process: 39046 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
 Main PID: 54573 (httpd)
   Status: "Processing requests..."
   Memory: 15.8M
   CGroup: /system.slice/httpd.service
           ├─54573 /usr/sbin/httpd -DFOREGROUND
           ├─54576 /usr/sbin/httpd -DFOREGROUND
           ├─54577 /usr/sbin/httpd -DFOREGROUND
           ├─54578 /usr/sbin/httpd -DFOREGROUND
           ├─54579 /usr/sbin/httpd -DFOREGROUND
           └─54580 /usr/sbin/httpd -DFOREGROUND

Jun 05 15:57:34 tele-2 systemd[1]: Starting The Apache HTTP Server...
Jun 05 15:57:34 tele-2 systemd[1]: Started The Apache HTTP Server.

2.外網存取虛擬機器中的位址,我們需要修改apache的設定檔/etc/httpd/conf/httpd.conf

找到#ServerName www.example.com :80       改為ServerName localhost:80

   如右圖:

## 找出#Listen       

## 找到#Listen       linux中開放的連接埠號碼80XX)

 如右圖所示:

3.修改完成之後我們需要再次啟動httpd服務,並查看啟動狀態

[root@tele-2 ~]# yum install php

 4.此時你就可以存取你的伺服器了,輸入localhost或ip位址,出現一個Apache test page powered by centos的測試頁面

PHP

 1.php安裝指令

[root@tele-2 ~]# service httpd start
Redirecting to /bin/systemctl start  httpd.service

 2.直接一路安裝,安裝完成之後再重新啟動httpd服務

 3.重啟之後我們進行測試PHP相關訊息,我們新建一個PHP介面進行測試在apache預設頁路徑/

var

/www/html下新建一個test.php頁面,新增程式碼

[root@tele-2 ~]# yum search php

 4.造訪這個頁面,輸入localhost/test.php,或者ip:連接埠號碼/test.php就可以看見php環境的設定資訊了

   

 ## 

#關聯php和mysql

1.搜尋模組

[root@tele-2 ~]# yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml  php-xmlrpc

2.安裝相關模組

数据库目录:/var/lib/mysql/

配置文件:/usr/share/mysql(mysql.server命令及配置文件)

相关命令:/usr/bin(mysqladmin mysqldump等命令)

my.cnf: /etc/my.cnf

启动脚本:/etc/rc.d/init.d/(启动脚本文件mysql的目录)

3.安裝完成,重新啟動mysqld,重啟httpd重新造訪剛才的info.php,我們發現已經多了MySQL的相關資訊。如右圖:

 

### #######

 至此,php在linux中的运行环境就已经成功配置完成了。

 

1.mysql yum安装默认文件夹及相关命令

数据库目录:/var/lib/mysql/

配置文件:/usr/share/mysql(mysql.server命令及配置文件)

相关命令:/usr/bin(mysqladmin mysqldump等命令)

my.cnf: /etc/my.cnf

启动脚本:/etc/rc.d/init.d/(启动脚本文件mysql的目录)
启动命令:service mysql start
停止命令:service mysql stop
运行状态:service mysql status

 2.apache

配置文件路径:/etc/httpd/conf/httpd.conf
启动命令:service httpd start
停止命令:service httpd stop
运行状态:service httpd status

 3.php

php默认页面路径:/var/www/html

推荐学习:《PHP视频教程

 

 

 

 

以上是教你玩轉linux下部署php專案-Apache、php、mysql關聯(分享)的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:csdn.net。如有侵權,請聯絡admin@php.cn刪除