部署php項目

部署php 項目,需要工具Xampp,其中包含了apache,php,mysql 運行環境

3設置權限

chmod 777 xampp-linux-x64-5.6.31-0-installer.run

4 運行文件
./xampp-linux-x64-5.6.31-0-installer.run
運行成功會提示選擇一些選項 一路Y即可

下面是我安裝的過程

Welcome to the XAMPP Setup Wizard.
Select the components you want to install; clear the components you do not want

to install. Click Next when you are ready to continue.XAMPP Core Files : Y (Cannot be edited)
XAMPP Developer Files [Y/n] :y
Is the selection above correct? [Y/n]: y
Installation Directory
XAMPP will be installed to /opt/lampp

Press [Enter] to continue:Setup is now ready to begin installing XAMPP on your computer.
Do you want to continue? [Y/n]: y
Please wait while Setup installs XAMPP on your computer.
Installing

0% ______________ 50% ______________ 100%

#########################################Setup has finished installing XAMPP on your computer.

安裝完成以後 可以使用你的服務器IP地址或者本地的127.0.0.1來測試切換到/opt/lampp目錄下

cd /opt/lampp/

ls

可以看到有個 htdocs 目錄

這裏就是存放你的代碼

打開ftp

1 本地就不用説了吧

2 服務器的賬號密碼 默認的就是root. 密碼是你在購買服務器時 提示讓你設置的密碼 不要忘記了。記得要隔一段時間修改一下

在htdocs目錄下新建一個目錄 比如ruofan

然後新建一個build.php

寫入
echo '歡迎來到若凡';
成功以後進行下一步

啓動

1 啓動關閉

需要切換目錄:cd /opt/lampp/
啓動 XAMPP
./lampp start
停止 XAMPP
./lampp stop
重啓 XAMPP
./lampp restart
2 訪問數據庫,並設置密碼
進入mysql
/opt/lampp/bin/mysql -uroot -p
xampp安裝完畢後,默認數據庫密碼為空
Enter password:

這裏如果沒有啓動lampp ,會報一下錯誤ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/opt/lampp/var/mysql/mysql.sock' (2 "No such file or directory")

確定啓動lampp以後直接Enter就可以進入數據庫
Welcome to the MariaDB monitor.  Commands end with ; or \g.Your MariaDB connection id is 5Server version: 10.1.21-MariaDB Source distribution
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.MariaDB [(none)]>
設置root用户密碼
set password for root@localhost = password('123');

創建用户並設置遠程訪問權限,不要直接用root用户直接遠程訪問 創建一個個人用户MariaDB [(none)]> CREATE USER '用户名'@'%' IDENTIFIED BY '密碼';
MariaDB [(none)]> GRANT ALL ON . TO '用户名'@'%';
MariaDB [(none)]> flush privileges;

//2017-08-19一個實例,添加一個對某個數據庫只有查詢權限的用户
MariaDB [(none)]> create user 'zhangsl'@'%' identified by 'zhangsl2017';

Query OK, 0 rows affected (0.02 sec)MariaDB [(none)]> grant select  on db_name.* to 'zhangsl'@'%';

Query OK, 0 rows affected (0.00 sec)MariaDB [(none)]> flush privileges;

Query OK, 0 rows affected (0.00 sec)

打開你的數據庫訪問軟件 我這裏用的是 Mac Sequel pro

使用上述創建的個人用户進行訪問 這裏的數據庫填寫 mysql

進去以後 新建一個自己的數據庫,然後回到連接的地方 把mysql 改為自己的數據庫

3 配置虛擬主機
執行

cat /opt/lampp/etc/httpd.conf
 可以查找到以下數據

Virtual hosts#Include etc/extra/httpd-vhosts.conf

這裏如果提示 Permission denied

可以先賦予權限  

 xampp為我們準備了一個專用於配置虛擬主機的文件了,去掉#號以刪除其註釋,然後編輯

vim /opt/lampp/etc/extra/httpd-vhosts.conf
文件,此文件中xampp為我們創建了兩個虛擬主機的示例,然後添加我們自己需要的虛擬主機

DocumentRoot /opt/lampp/htdocs
ServerName blog.upwqy.com
DocumentRoot表示虛擬主機對應的路徑,即網站目錄,ServerName表示虛擬主機的訪問地址,類似IIS中的主機頭值。

至此,虛擬主機的設置也算是完成了。

最後我們需要在apache配置文件/opt/lampp/etc/httpd.conf中添加一下網站目錄的訪問權限。

Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all