Setup
The steps in this tutorial require the user to have root privileges. You can see how to set that up in the Initial Server Setup in steps 3 and 4.
Before working with wordpress, you need to have LEMP installed on your virtual private server. If you don't have the Linux, nginx, MySQL, PHP stack on your VPS, you can find the tutorial for setting it in the LAMP tutorial.
Once you have the user and required software, you can start installing wordpress!
Step One—Download WordPress
We can download Wordpress straight from their website:
wget http://wordpress.org/latest.tar.gz
This command will download the zipped wordpress package straight to your user's home directory. You can unzip it the the next line:
tar -xzvf latest.tar.gz
Step Two—Create the WordPress Database and User
After we unzip the wordpress files, they will be in a directory called wordpress in the home directory on the virtual private server.
Now we need to switch gears for a moment and create a new MySQL directory for wordpress.
Go ahead and log into the MySQL Shell:
mysql -u root -p
Login using your MySQL root password, and then we need to create a wordpress database, a user in that database, and give that user a new password. Keep in mind that all MySQL commands must end with semi-colon.
First, let's make the database (I'm calling mine wordpress for simplicity's sake; feel free to give it whatever name you choose):
CREATE DATABASE wordpress; Query OK, 1 row affected (0.00 sec)
Then we need to create the new user. You can replace the database, name, and password, with whatever you prefer:
CREATE USER wordpressuser@localhost; Query OK, 0 rows affected (0.00 sec)
Set the password for your new user:
SET PASSWORD FOR wordpressuser@localhost= PASSWORD("password"); Query OK, 0 rows affected (0.00 sec)
Finish up by granting all privileges to the new user. Without this command, the wordpress installer will not be able to start up:
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password'; Query OK, 0 rows affected (0.00 sec)
Then refresh MySQL:
FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
Exit out of the MySQL shell:
exit
Step Three—Setup the WordPress Configuration
The first step to is to copy the sample WordPress configuration file, located in the WordPress directory, into a new file which we will edit, creating a new usable WordPress config:
cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php
Then open the wordpress config:
sudo nano ~/wordpress/wp-config.php
Find the section that contains the field below and substitute in the correct name for your database, username, and password:
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'wordpress'); /** MySQL database username */ define('DB_USER', 'wordpressuser'); /** MySQL database password */ define('DB_PASSWORD', 'password');Save and Exit.
Step Four—Copy the Files
We are almost done uploading Wordpress to the server. We need to create the directory where we will keep the wordpress files:
sudo mkdir -p /var/www
We can modify the permissions of /var/www to allow future automatic updating of Wordpress plugins and file editing with SFTP. If these steps aren't taken, you may get a "To perform the requested action, connection information is required" error message when attempting either task.
The first command changes the ownership of /var/www to www-data, the ubuntu web user and group. The subsequent two add a user to the group, and allow the group to read and write to any file in the directory.
sudo chown -R www-data:www-data /var/www sudo usermod -a -G www-data username sudo chmod -R g+rw /var/www
The final move that remains is to transfer the unzipped WordPress files to the website's root directory.
sudo cp -r ~/wordpress/* /var/www
Step Five—Set Up Nginx Server Blocks
Now we need to set up the WordPress virtual host. Create a new file for the for WordPress host, copying the format from the default configuration:
sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/wordpress
Open the WordPress virtual host:
sudo nano /etc/nginx/sites-available/wordpress
The configuration should include the changes below (the details of the changes are under the config information):
[...] server { listen 80; ## listen for ipv4; this line is default and implied #listen [::]:80 default ipv6only=on; ## listen for ipv6 root /var/www; index index.php index.html index.htm; # Make site accessible from http://localhost/ server_name example.com; location / { # First attempt to serve request as file, then # as directory, then fall back to index.html try_files $uri $uri/ /index.php?q=$uri&$args; # Uncomment to enable naxsi on this location # include /etc/nginx/naxsi.rules } location /doc/ { alias /usr/share/doc/; autoindex on; allow 127.0.0.1; deny all; } # Only for nginx-naxsi : process denied requests #location /RequestDenied { # For example, return an error code #return 418; #} #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/www; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini # With php5-cgi alone: fastcgi_pass 127.0.0.1:9000; # With php5-fpm: # fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } } […]Here are the details of the changes:
- Change the root to /var/www/
- Add index.php to the index line.
- Change the server_name from local host to your domain name or IP address (replace the example.com in the configuration)
- Change the "try_files $uri $uri/ /index.html;" line to "try_files $uri $uri/ /index.php?q=$uri&$args;" to enable Wordpress Permalinks with nginx
- Uncomment the correct lines in “location ~ \.php$ {“ section
Save and Exit that file.
Step Six—Activate the Server Block
Although all the configuration for worpress has been completed, we still need to activate the server block by creating a symbolic link:sudo ln -s /etc/nginx/sites-available/wordpress /etc/nginx/sites-enabled/wordpress
Additionally, delete the default nginx server block.
sudo rm /etc/nginx/sites-enabled/default
Then, as always, restart nginx:
sudo service nginx restart
Step Seven—RESULTS: Access the WordPress Installation
Once that is all done, the wordpress online installation page is up and waiting for you:
Access the page by visiting your site's domain or IP address (eg. example.com) and fill out the short online form (it should look like this).
출처 : https://www.digitalocean.com/community/articles/how-to-install-wordpress-with-nginx-on-ubuntu-12-04
'공부 > 일반' 카테고리의 다른 글
리눅스 권한 에러 '/etc/sudoers is mode 0777 should be 0440' (0) | 2012.11.02 |
---|---|
내 홈페이지(블로그) 로딩시간, 속도 측정 (0) | 2012.10.27 |
리눅스(우분투12.04)서버에 Nginx, Mysql, Php 설치하기 (0) | 2012.10.03 |
리눅스서버에 APM설정 (0) | 2012.09.11 |
리눅스 일반계정 관리자권한주기 (0) | 2012.08.31 |