---
# System prepended metadata

title: 僅記錄安裝composer+laravel+mysql

---

# 僅記錄安裝composer+laravel+mysql

**相關參考網址:**
https://vocus.cc/article/6299f859fd89780001bd2895
**Nginx安裝參考:**
由於nginx一開始就裝了，也就忘記怎麼裝的。
相關路徑:/etc/nginx、/usr/share/nginx

配置php-fpm:
`vi /etc/php-fpm.d/www.conf`
24、26從apache改nginx。



**composer安裝參考:**
https://tony915.gitbooks.io/laravel4/content/install/install_composer.html
遇到問題:
```
Some settings on your machine make Composer unable to work properly.
Make sure that you fix the issues listed below and run this script again:

The json extension is missing.
Install it or recompile php without --disable-json
```
解決的相關網址:https://stackoverflow.com/questions/27437206/composer-installing-the-json-extension-is-missing

安裝路徑:/usr/local/bin (這樣才會是全域指令)
已經將名稱改為composer，可確認版本指令:
```
composer -V
```
**laravel安裝參考:**
路徑:/var/www/laravel

遇到錯誤:
```
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - phpunit/phpunit[8.5.8, ..., 8.5.x-dev] require ext-dom * -> it is missing from your system. Install
 or enable PHP's dom extension.
    - phpunit/phpunit[9.3.3, ..., 9.3.8] require php ^7.3 || ^8.0 -> your php version (7.2.24) does not s
atisfy that requirement.
    - phpunit/phpunit[9.3.9, ..., 9.6.x-dev] require php >=7.3 -> your php version (7.2.24) does not sati
sfy that requirement.
    - Root composer.json requires phpunit/phpunit ^8.5.8|^9.3.3 -> satisfiable by phpunit/phpunit[8.5.8,
..., 8.5.x-dev, 9.3.3, ..., 9.6.x-dev].

To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php.ini
    - /etc/php.d/20-bz2.ini
    - /etc/php.d/20-calendar.ini
    - /etc/php.d/20-ctype.ini
    - /etc/php.d/20-curl.ini
    - /etc/php.d/20-exif.ini
    - /etc/php.d/20-fileinfo.ini
    - /etc/php.d/20-ftp.ini
    - /etc/php.d/20-gettext.ini
    - /etc/php.d/20-iconv.ini
    - /etc/php.d/20-json.ini
    - /etc/php.d/20-phar.ini
    - /etc/php.d/20-sockets.ini
    - /etc/php.d/20-tokenizer.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-dom` to temporarily ignore these requ
ired extensions.
[root@localhost laravel]# composer install --ignore-platform-req=php
No composer.lock file present. Updating dependencies to latest instead of installing from lock file. See
https://getcomposer.org/install for more information.
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - phpunit/phpunit[8.5.8, ..., 8.5.x-dev, 9.3.3, ..., 9.6.x-dev] require ext-dom * -> it is missing from your system. Install or enable PHP's dom extension.
    - Root composer.json requires phpunit/phpunit ^8.5.8|^9.3.3 -> satisfiable by phpunit/phpunit[8.5.8,
..., 8.5.x-dev, 9.3.3, ..., 9.6.x-dev].

To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php.ini
    - /etc/php.d/20-bz2.ini
    - /etc/php.d/20-calendar.ini
    - /etc/php.d/20-ctype.ini
    - /etc/php.d/20-curl.ini
    - /etc/php.d/20-exif.ini
    - /etc/php.d/20-fileinfo.ini
    - /etc/php.d/20-ftp.ini
    - /etc/php.d/20-gettext.ini
    - /etc/php.d/20-iconv.ini
    - /etc/php.d/20-json.ini
    - /etc/php.d/20-phar.ini
    - /etc/php.d/20-sockets.ini
    - /etc/php.d/20-tokenizer.ini
You can also run `php --ini` in a terminal to see which files are used by PHP in CLI mode.
Alternatively, you can run Composer with `--ignore-platform-req=ext-dom` to temporarily ignore these requ
ired extensions.
```
解決方法:https://stackoverflow.com/questions/43408604/php7-install-ext-dom-issue

之後直接輸入
```
composer install
```
就行了

**mysql安裝參考**:
不知道為什麼已經安裝好了，但還是找了一個參考網址
https://vocus.cc/article/61891655fd89780001e85c44
路徑:/usr/local/mysql/bin、/var/log/mysql
帳號是root，密碼跟linux的root的密碼一樣。
mysql對資料庫的操作:https://medium.com/web-design-zone/mysql%E8%B3%87%E6%96%99%E5%BA%AB%E7%9A%84%E5%AE%89%E8%A3%9D%E8%88%87%E5%9F%BA%E6%9C%AC%E6%93%8D%E4%BD%9C-f36a079afd85

**SQL語法:**
https://blog.techbridge.cc/2020/02/09/sql-basic-tutorial/
# Nginx 的設定
http://blog.tonycube.com/2018/09/vps-centos-7-nginx-php-fpm-mariadb-8-using-nginx.html
# 用RESTful API對user、table進行CRUD等操作
**api與RESTful api:**
https://medium.com/itsems-frontend/api-%E6%98%AF%E4%BB%80%E9%BA%BC-restful-api-%E5%8F%88%E6%98%AF%E4%BB%80%E9%BA%BC-a001a85ab638
**laravel設置api:**
https://angela52799.medium.com/php-%E5%9F%BA%E6%9C%AC%E9%85%8D%E7%BD%AE%E8%88%87-restful-api-%E5%85%A5%E9%96%80-17a4284b0100

注意:文中的程式碼的 ' 是不一樣的，須改掉

關於Usercontroller.php，chatgpt的解釋:
```
這是一個用於處理CRUD操作（創建、讀取、更新和刪除）的RESTful API的PHP代碼，針對 UserInfo 模型進行操作。

namespace 表示這是位於 App\Http\Controllers\api 命名空間中的控制器類別。這個類別擴展了Laravel提供的基礎控制器類別 Controller。

UserInfoController 類別有五個方法，每個方法都代表一個CRUD操作：

index() 方法返回數據庫中的所有 UserInfo 記錄作為JSON響應，HTTP狀態碼為200。
store(Request $request) 方法接受POST請求，請求體內包含以JSON格式提交的 UserInfo 數據。它使用提供的數據在數據庫中創建一條新的 UserInfo 記錄，並將創建的記錄作為JSON響應返回，HTTP狀態碼為201。
show($id) 方法返回一個以 $id 參數為標識的 UserInfo 記錄，作為JSON響應返回，HTTP狀態碼為200。
update(Request $request, $id) 方法接受PUT/PATCH請求，請求體內包含以JSON格式提交的 UserInfo 數據。它使用提供的數據更新以 $id 參數為標識的 UserInfo 記錄，在更新完成後將更新的記錄作為JSON響應返回，HTTP狀態碼為200。
destroy($id) 方法刪除以 $id 參數為標識的 UserInfo 記錄，返回一個JSON響應，HTTP狀態碼為204，表示請求成功但沒有內容返回。
這個代碼使用了Laravel內置的 response() 方法來返回帶有適當HTTP狀態碼的JSON響應。它還使用了Laravel內置的 findOrFail() 方法來通過ID檢索 UserInfo 記錄，如果未找到該記錄，則會拋出 ModelNotFoundException。
```
**laravel 與 nginx 設置:**
https://hackmd.io/D1FIJHToSpex0rYwQgKJ1w?both




Regenerate response
