# Wordpress on Ubuntu ###### tags: `計概` [TOC] ## Install #### prerequisite (前置作業) - web server : apache2 - database : mysql - others : libapache2-mod-php, php, other php plugins - 因為 wordpress 是用 php 寫,所以需要安裝php套件 - overall install command : ``` sudo apt install apache2 \ ghostscript \ libapache2-mod-php \ mysql-server \ php \ php-bcmath \ php-curl \ php-imagick \ php-intl \ php-json \ php-mbstring \ php-mysql \ php-xml \ php-zip ``` ### Wordpress - get the latest version of wordpress - `wget https://wordpress.org/latest.tar.gz` - 解壓縮 - `tar -xvf latest.tar.gz` - 移到指定檔案(ex. `/var/www`,方便管理,不一定要做) - `mv wordpress /var/www` - 改此檔案權限給 web server(www-data) - `chown www-data:www-data /var/www/wordpress` - web server要有權限去存取此檔案,才能將wordpress的內容顯示在網頁上。 ->www-data: web server的使用者 ## Configuration ### Database - 因為 wordpress 會使用到資料庫(ex. 管理員帳號資訊),所以要有資料庫 - 建立 database - `CREATE DATABASE {database_name};` - 建立 db 使用者 - `CREATE USER {user_name}@localhost IDENTIFIED BY {password};` - 給此 database 的所有權限(ex. select, insert) to 此使用者 - `GRANT ALL PRIVILEGES ON {database_name}.* TO {username}@localhost;` - `FLUSH PRIVILEGES;` ### Apache - 幫此 wordpress 網站寫一個設定檔 : `vi /etc/apache2/sites-available/wordpress.conf` ```conf= # listen to 80 port <VirtualHost *:80> DocumentRoot /var/www/wordpress <Directory /var/www/wordpress> Options FollowSymLinks AllowOverride Limit Options FileInfo DirectoryIndex index.php Require all granted </Directory> # wp-content is the place wordpress store static object, ex. image file <Directory /var/www/wordpress/wp-content> Options FollowSymLinks Require all granted </Directory> </VirtualHost> ``` - `DocumentRoot` : 此 wordpress 檔案的路徑 - `<Directory /var/www/wordpress></Directory>` : 此路徑(`/var/www/wordpress`)下檔案的存取設定 - `FollowSymLinks` : 允許存取此 `Directory` 底下的軟連結檔案 - `AllowOverride` : 允許 wordpress 自帶的設定檔(.htaccess)更改部分 apache 的 設定檔 - .htaccess : 設定了一些對於存取 wordpress 網站的限制,包含不能直接存取和 `Directory` 下存在的檔案名稱相同的檔案(ex. `wp-config.php`)等等 - `DirectoryIndex` : 優先存取的檔案,wordpress 首頁預設是 index.php - `Require all granted` : 允許所有 ip 都能存取此 wordpress 網頁 - enable 此 conf : `sudo a2ensite wordpress` - 開啟改寫 url 的功能 : `sudo a2enmod rewrite` - 重新載入 apache 設定 : `sudo systemctl reload apache2` ### Wordpress - 用官方的樣本且使用 web server 的使用者權限(`www-data`)建立 wordpress 的設定檔 : `sudo -u www-data cp /var/www/wordpress/wp-config-sample.php /var/www/wordpress/wp-config.php` - 更改資料庫的設定,用之前建好的資料 -  - `DB_NAME` : 剛剛建的資料庫名稱 - `DB_USER` : 剛剛建的資料庫使用者名稱 - `DB_PASSWORD` : 剛剛建的資料庫使用者密碼 - `DB_HOST` : 資料庫 ip address,因為是建在本地所以是 `localhost` - 設定 wordpress 的 url 為內部網段的 ip,讓內網下都可以連到 - 先幫此台 vm 裝一個網卡,這樣 ubuntu 才會有自己的內部 ip -  - 看一下此台 ip : `ifconfig` -  - 設定 `vi wp-config.php` : -  ## Demo - go to http://{your_ip} - 設定一下 wordpress 管理員資訊 -  - 設定完後,就可正常登入 -  - 可以新增文章等等 -  ## Ref - https://ubuntu.com/tutorials/install-and-configure-wordpress#1-overview ## PPT [LinuxOS](https://docs.google.com/presentation/d/1TX1H4dWKdaUAMmSLZQ1viIbQYtjirkAqLJK2dZvXKxw/edit#slide=id.g4dfce81f19_0_45)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up