Build Wordpress Server with CentOS7

DEC 27 2017 - DEC 29 2017

Here is a work flow following the guidance [How To Install WordPress on CentOS 7].

Environment:
- Mac
- Virtualbox Version 5.2.4 r119785 (Qt5.6.3)
- CentOS 7 x86_64

After installation virtualbox and CentOS, Kindly make sure that the network works.

  • use ‘NAT’ as network connection method
    • Try ping 8.8.8.8 and ping www.google.com to check DNS configuration.
  • use ‘Host Only’ as well for communication between host PC and virtual machine.

How to check my ip?
ip ad or
ip addr show eth0 | grep inet | awk '{ print $2; }' | sed 's/\/.*$//'(sometimes ‘eth0’ should be changed into other words)

How to use SSH?
ssh root@server_ip

Reference:

Pre-requirement

How To Install Linux, Apache, MySQL, PHP (LAMP) stack On CentOS 7

  • Step one Install Apache

    • sudo yum install httpd
    • Start Apache service: sudo systemctl start httpd.service
    • To enable Apache to start on boot: sudo systemctl enable httpd.service
  • Step Two — Install MySQL (MariaDB)
    MariaDB is a community-developed fork of the MySQL relational database management system.

    • sudo yum install mariadb-server mariadb
    • Then start MariaDB: sudo systemctl start mariadb
    • Now that our MySQL database is running, we want to run a simple security script that will remove some dangerous defaults and lock down access to our database system a little bit. Start the interactive script by running: sudo mysql_secure_installation
    • To enable MariaDB to start on boot: sudo systemctl enable mariadb.service
  • Step Three — Install PHP
    PHP is the component of our setup that will process code to display dynamic content. It can run scripts, connect to our MySQL databases to get information, and hand the processed content over to our web server to display.
    • Install: sudo yum install php php-mysql
    • Once finished installing php, we need to restart Apache web server in order for it to work with PHP: sudo systemctl restart httpd.service
    • Install PHP Modules: use yum search php- to see the available options for PHP modules and libraries. And use yum info package-name to see descriptions of PHP packages.

Step One — Create a MySQL Database and User for WordPress

Reference:

#may need to update yum
sudo yum update

#neet to install wget
yum install wget

MySQL must be installed from the community repository. Download and add the repository, then update.

wget http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
sudo rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum update

#Install MySQL as usual and start the service. 
sudo yum install mysql-server
sudo systemctl start mysqld
#MySQL will bind to localhost (127.0.0.1) by default.
Using MySQL
Root login
  • To log in to MySQL as the root user:
mysql -u root -p
  • When prompted, enter the root password you assigned when the mysql_secure_installation script was run. You’ll then be presented with a welcome header and the MySQL prompt as shown below:
mysql>
  • To generate a list of commands for the MySQL prompt, enter \h.
Create a New MySQL User and Database
  • In the example below, testdb is the name of the database, testuser is the user, and password is the user’s password.
create database testdb;
create user 'testuser'@'localhost' identified by 'password';
grant all on testdb.* to 'testuser' identified by 'password';

You can shorten this process by creating the user while assigning database permissions:

create database testdb;
grant all on testdb.* to 'testuser' identified by 'password';
  • Then exit MySQL
exit
Create a Sample Table
  • Log back in as testuser
mysql -u testuser -p
  • Create a sample table called customers. This creates a table with a customer ID field of the type INT for integer (auto-incremented for new records, used as the primary key), as well as two fields for storing the customer’s name.
use testdb;
create table customers (customer_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, first_name TEXT, last_name TEXT);
Reset the MySQL Root Password
  • Stop the current MySQL server instance, then restart it with an option to not ask for a password.
sudo systemctl stop mysqld
sudo mysqld_safe --skip-grant-tables &
  • Reconnect to the MySQL server with the MySQL root account.
mysql -u root
  • Use the following commands to reset root’s password. Replace password with a strong password.
use mysql;
update user SET PASSWORD=PASSWORD("password") WHERE USER='root';
flush privileges;
exit

Now we are okay to create a database for wordpress. Just use the following command:

CREATE DATABASE FOR WORDPRESS
CREATE DATABASE wordpress;
CREATE USER wordpressuser@localhost IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wordpress.* TO wordpressuser@localhost IDENTIFIED BY 'password';
  • Then restart MySQL
sudo systemctl start mysqld

Step Two — Install WordPress

Before we download WordPress, there is one PHP module that we need to install to ensure that it works properly. Without this module, WordPress will not be able to resize images to create thumbnails. We can get that package directly from CentOS’s default repositories using yum:

sudo yum install php-gd

Then restart Apache service so that it recognizes this new module:

sudo service httpd restart

Now ready to download and install WordPress from the project’s website.

cd ~
wget http://wordpress.org/latest.tar.gz

#then unzip
tar -xzvf latest.tar.gz

#use rsync to transfer our WordPress files, which will preserve the files' default permissions:
rsync -avP ~/wordpress/ /var/www/html/
#rsync will safely copy all the contents from the directory we unzip.

#Then we need to mkdir for WordPress to store uploaded files.
mkdir /var/www/html/wp-content/uploads

#Then change the ownership and permission to WordPress files and folders
chown -r apache:apache /var/www/html/*
#You can check whether the user 'apache' exists:
cat /etc/passwd | grep apache

Step Three — Configure WordPress

configuration file: wp-config.php

in directory where WordPress is installed:
cd /var/www/html

copy the configuration sample:
cp wp-config-sample.php wp-config.php

then edit wp-config.php:

// ** 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');

Step Four — Complete Installation Through the Web Interface

Access http://192.168.56.101 to install WordPress.
You can go to the website http://192.168.56.101/wp-admin/install.php as well.

Further you need to allow the Firewall-cmd to http and https as follows:

firewall-cmd --permanent --zone=public --add-service=http 
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

Notes:

Configure Name-based Virtual Hosts

File excerpt: /etc/httpd/conf/httpd.conf
When new requests come in from the internet, Apache checks which VirtualHost block matches the requested url, and serves the appropriate content

Add the following configuration in the end of httpd.conf in Virtual machine. In this way VM can access via example.com/www.example.com.

<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
</VirtualHost>

Add the following configuration in /etc/hosts in local host PC. In this way the localhost PC can access via example.com/www.example.com.

127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost

192.168.56.101 example.com     #new added
192.168.56.101 www.example.com #new added

How to install GUI using command line in CentOS?

yum grouplist
Then find GNOME Desktop Environment
yum groupinstall "GNOME Desktop"
Edit /etc/inittab and add id:5:initdefault:(5 represents X11)
Then startx

How to set CentOS init default from command line to GUI?

From CentOS, we cannot config via run level any more, which uses systemd instead. Therefore, there is some differences in configuring init default.
We can see cat /etc/inittab, there are two init modes:

multi-user.target: analogous to runlevel 3  #command line mode
graphical.target: analogous to runlevel 5   #GUI mode
  • use systemctl get-default to get current mode
  • use systemctl set-default graphical.target to set default as graphical mode. (You should install GUI first)
  • Then reboot

It seems that CentOS7 will no longer use service httpd restart, then will use systemctl restart httpd instead.

9

5

5

5

5

5

5

5

5

5

5

5

5

5

5

5

5

5
5
5

5

6

6

6
6

6
6

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值