教學文章-Ubuntu安裝WordPress部落格

原文出自:http://www.ubuntugeek.com/installing-wordpress-3-0-on-ubuntu-10-04-lucid-lynx.html

On this post I’ll tell you how to install the latest WordPress version (3.0) on a Ubuntu 10.04 (Lucid Lynx) machine. I personally love WordPress as a blogging engine and hope you find these instructions helpful and that make you create your blogs fast and pragmatically.

So, without further ado, let’s start by opening a terminal and type:

miguel@c31828:~$ sudo aptitude install apache2
Reading package lists… Done
Building dependency tree
Reading state information… Done
Reading extended state information
Initializing package states… Done
The following NEW packages will be installed:
apache2 apache2-mpm-worker{a} apache2-utils{a} apache2.2-bin{a} apache2.2-common{a}
libaprutil1-dbd-sqlite3{a} libaprutil1-ldap{a}
0 packages upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,238kB of archives. After unpacking 10.7MB will be used.
Do you want to continue? [Y/n/?]

Continue with Y. You’ll notice by the end of the update that Apache will be started and have a default configuration set up:

(…)


Enabling module authn_file.
Enabling module authz_host.
Enabling module reqtimeout.


Setting up apache2-mpm-worker (2.2.14-5ubuntu8) ...
* Starting web server apache2                                                                           apache2: Could not reliably determine the server’s fully qualified domain name, using 127.0.1.1 for ServerName
[ OK ]


Setting up apache2 (2.2.14-5ubuntu8) ...


Reading package lists... Done

(…)

Once the installation is finished, we can test if Apache is working OK by opening up a browser and navigate to the URL http://127.0.0.1. If everything is OK you’ll see the “it works!” web page, meaning Apache is up and running!

Next, we’ll need to install MySQL 5.1:

miguel@c31828:~$ sudo aptitude install mysql-server-5.1
Reading package lists… Done
Building dependency tree
Reading state information… Done
Reading extended state information
Initializing package states… Done
The following NEW packages will be installed:
libdbd-mysql-perl{a} libdbi-perl{a} libhtml-template-perl{a} libmysqlclient16{a}
libnet-daemon-perl{a} libplrpc-perl{a} mysql-client-5.1{a} mysql-client-core-5.1{a}
mysql-common{a} mysql-server-5.1 mysql-server-core-5.1{a}
0 packages upgraded, 11 newly installed, 0 to remove and 0 not upgraded.
Need to get 24.2MB of archives. After unpacking 60.7MB will be used.
Do you want to continue? [Y/n/?]

Continue with Y. During the installation we’ll need to insert a root password for MySQL. You can pick a strong password fromstrongpasswordgenerator.com. For obvious reasons, save this password in a safe place!

As you can see from the list above, MySQL 5.1 packages occupy 24.2 MB and this download can take some time depending on the Internet connection and CPU speed.

Next, we’ll install PHP version 5:


miguel@c31828:~$ sudo aptitude install php5 phpmyadmin
Reading package lists… Done
Building dependency tree
Reading state information… Done
Reading extended state information
Initializing package states… Done
The following NEW packages will be installed:
apache2-mpm-prefork{a} dbconfig-common{a} javascript-common{a} libapache2-mod-php5{a}
libjs-mootools{a} libmcrypt4{a} libt1-5{a} php5 php5-common{a} php5-gd{a} php5-mcrypt{a}
php5-mysql{a} phpmyadmin wwwconfig-common{a}
The following packages will be REMOVED:
apache2-mpm-worker{a}
0 packages upgraded, 14 newly installed, 1 to remove and 0 not upgraded.
Need to get 10.1MB of archives. After unpacking 32.7MB will be used.
Do you want to continue? [Y/n/?]

Continue with Y. I also installed phpMyAdmin, although optional, because I like to create the database, users, tables, etc. through this great package and this way I don’t need to give any commands directly on the mysql prompt (I personally tend to forget a lot on the right syntax on long commands).

If you don’t want to install phpMyAdmin, don’t forget to include php5-mysql on the command above (sudo aptitude install php5 php5-mysql).

You’ll notice that during phpMyAdmin installation you’ll have to choose the web server that should be configured to run phpMyAdmin: apache2 or lighttpd. Choose apache2 (with the space key) and hit Ok (with the tab and then the space key) to continue the installation. You’ll then get a screen telling you if you want to configure database for phpMyAdmin with dbconfig-common. Hit No (with tab and then the space key).

After phpMyAdmin installation, you can again open the browser and hit URL http://127.0.0.1/phpmyadmin/Et voilà! You can now get inside your MySQL database world through your browser using the user root and the password chosen above (but be aware that user root has full access to your databases and should be used wisely).

Now, we only need to download WordPress 3.0 from the official WordPress web page:

http://wordpress.org/latest.zip (2.2MB) or http://wordpress.org/latest.tar.gz (2.0MB)

Right click on one of these links and download it to a location of your preference (for example, ~/Desktop) using the option “Save Link As…”. Unpack this package (I’ll use here folder /var/www as it is a standard location where the web server will look for web pages) using unzip (for the .zip archive) or tar (for the .tar.gz archive).


miguel@c31828:~/Desktop$ sudo mv latest.zip /var/www

or

miguel@c31828:~/Desktop$ sudo mv wordpress-3.0.1.tar.gz /var/www


miguel@c31828:~/Desktop$ cd /var/www


miguel@c31828:/var/www$ sudo unzip latest.zip

or

miguel@c31828:/var/www$ sudo tar -zxvf latest.tar.gz

After unpacking, you’ll get a folder wordPress extracted to your chosen location:


miguel@c31828:/var/www$ ls -al
total 2912
drwxr-xr-x  3 root   root      4096 2010-06-30 18:00 .
drwxr-xr-x 17 root   root      4096 2010-06-30 16:32 ..
-rw-r–r–  1 root   root       177 2010-06-30 16:32 index.html
drwxr-xr-x  5 root   root      4096 2010-06-17 17:05 wordpress
-rw-r–r–  1 miguel miguel 2964966 2010-06-30 17:38 latest.zip

One of the important things to do is to give the right permissions for your user to read and write into the wordpress folder. For this, you will want to give the correct ownership to your local user (in my case, user miguel):

miguel@c31828:/var/www$ sudo chown -R miguel:users wordpress

As you can see, the wordpress folder now has the right permissions for my user to change it:

miguel@c31828:/var/www$ ls -al
total 2912
drwxr-xr-x 3 root root 4096 2010-06-30 18:00 .
drwxr-xr-x 17 root root 4096 2010-06-30 16:32 ..
-rw-r–r– 1 root root 177 2010-06-30 16:32 index.html
drwxr-xr-x 5 miguel users 4096 2010-06-17 17:05 wordpress
-rw-r–r– 1 miguel miguel 2964966 2010-06-30 17:38 latest.zip

You can now delete the .zip or .tar.gz archive:


miguel@c31828:/var/www$ sudo rm -f latest.zip

or

miguel@c31828:/var/www$ sudo rm -f wordpress-3.0.1.tar.gz

Now all we’re missing is creating a MySQL database and configure WordPress!

For creating a database using phpMyAdmin, follow these steps:

  • Start by choosing a name for your WordPress database (like ‘wordpress‘ or ‘blog‘), enter it in the Create new database field, and clickCreate (choose the right Connection Collation for you or use utf8_general_ci).
  • Click the Home icon in the upper left to return to the main page, then click Privileges. If a user relating to WordPress does not already exist in the list of users, create one:
  • Click Add a new User.
  • Chose a username for WordPress (like ‘wordpress‘) and enter it in the User name field. (Be sure Use text field: is selected from the dropdown.)
  • Choose a strong password password (use strongpasswordgenerator.com), and enter it in the Password field. (Be sure Use text field: is selected from the dropdown.) Re-enter the password in the Re-type field.
  • Write down the username and password you chose.
  • Leave all options under Global privileges at their defaults.
  • Click Go.
  • Return to the Privileges screen and click the Edit privileges icon (on the right-most column) on the user you’ve just created for WordPress. In the Database-specific privileges section, select the database you’ve just created for WordPress under the Add privileges to the following database drop down. The page will refresh with privileges for that database. Click Check All to select all privileges, and click Go.
  • On the resulting page, make note of the host name listed after Server: at the top of the page. (This will usually be localhost.)

For creating a database using MySQL client, follow these steps:

miguel@c31828:/var/www$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 61
Server version: 5.1.41-3ubuntu12.3 (Ubuntu)


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


mysql> CREATE DATABASE databasename;
Query OK, 1 row affected (0.00 sec)


mysql> CREATE USER wordpressuser;
Query OK, 0 rows affected (0.00 sec)


mysql> SET PASSWORD FOR wordpressuser = PASSWORD(”wordpresspassword“);
Query OK, 0 rows affected (0.00 sec)


mysql> GRANT ALL PRIVILEGES ON databasename.* TO “wordpressuser“@”localhost” IDENTIFIED BY “wordpresspassword“;
Query OK, 0 rows affected (0.00 sec)


mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)


mysql> EXIT


Bye

Now all we have to do is to configure WordPress!


miguel@c31828:~$ cd /var/www/wordpress
miguel@c31828:/var/www/wordpress$ sudo cp wp-config-sample.php wp-config.php

Edit this new file, wp-config.php, with your favorite editor (I used emacs!) and change the values under the section labeled MySQL settings

  • DB_NAME: Database Name used by WordPress
  • DB_USER: Username used to access Database
  • DB_PASSWORD: Password used by Username to access Database
  • DB_HOST: The hostname of your Database Server

And also put your Authentication Unique Keys and Salts under the section labeled Authentication Unique Keys using WordPress’ online generator to obtain them:

  • AUTH_KEY
  • SECURE_AUTH_KEY
  • LOGGED_IN_KEY
  • NONCE_KEY

Save all your changes to file /var/www/wordpress/wp-config.php and open a browser and give it the URLhttp://127.0.0.1/wordpress/. If everything is OK by now you should see the WordPress welcome and configuration page (if you got the error “Error establishing a connection” that probably means something is wrong with the username or password you have saved in file wp-config.php):

 

All we need now is to put some more few details like the site’s title, the user name and password we’ll use to login (once again I suggest using a strong password from the strong password generator site, and after everything is just the way we want just click the “Install WordPress” button!
If everything went perfect, a “Success!” web page follows and we can start using WordPress by logging in with the user name and password chosen on the previous step.

After you logged in, you will be redirected to the Dashboard page under which you can customize your wordpress blog to suit more easily your looks and purposes.

To install a new theme, hit the “Appearance” menu and then the “Install Theme” tab. Under the search field enter a theme search term by keyword, author, or tag. For instance, I chose “clean”. One of the search results gave me the Fusion theme. Hit the Install link and then the Install now link at the preview window. At the Connection Information wordrepss page you will need to enter the following information: your hostname, FTP username and password and connection type. For this to work, you will first need to have a FTP daemon running on your web server. If you don’t have it already, you can install one by using the command

sudo aptitude install vsftpd

After the installation, you will just have to edit the file /etc/vsftpd.conf as root using your favorite editor and enable the features you would like your ftp daemon to be enabled. I enabled the following ones (read the FTP daemon’s documentation first if you’re not sure of which options to enable and the security impact those changes will have):

anonymous_enable=YES
local_enable=YES
write_enable=YES
local_umask=022
anon_upload_enable=YES
anon_mkdir_write_enable=YES

Now all I have to do is to run the FTP daemon with the command:

sudo service vsftpd start

Let’s now return at the “Connection Information” configuration page. Fill the necessary information in the text fields for your hostname (I used 127.0.0.1 but you can also use localhost), the user name (I used miguel) and the password (I won’t tell you this one!). Choose FTP protocol and hit Install. If everything is OK, you should now see that your theme is being downloaded and installed in wordpress/wp-content/themes folder. Hit the “Preview” link to preview what your page will look like with the new theme, hit “Activate” link to use the newly installed theme or hit “Return to Theme Installer” page to install another theme!

Have fun using WordPress!