Setup WordPress on CentOS 7

From rdkwiki
Jump to: navigation, search


The steps below will configure a working WordPress web-server. The steps assume that you have a (fresh) CentOS 7 server running.

Install prerequisites

  • yum install nano wget --> install the nano editor and wget

Apache webserver installation

If Apache isn't already running then here's how to install and configure it: Installing Apache webserver

Firewall configuration

  • firewall-cmd --permanent --add-port=80/tcp --> allow http traffic
  • firewall-cmd --permanent --add-port=443/tcp --> allow https traffic
  • firewall-cmd --reload --> restart firewall with new config

MySQL installation

If MySQL isn't already running then here's how to install and configure it: Installing MySQL on CentOS 7

Installing and testing PHP

  • yum install php php-mysql php-fpm php-gd --> install WordPress requirements
  • systemctl restart httpd.service --> restart Apache webserver
  • nano /var/www/html/info.php —> create testscript
content of file: <?php phpinfo(); ?> and save the file
  • http://<serverip>/info.php —> test (should give you info about PHP)
  • rm /var/www/html/info.php —> remove testscript after successful testing

Configuring MySQL user and database for WordPress

  • mysql -h <host> -u <user> -p --> connect to your MySQL-server
  • create database <wordpress database>; --> create a database with name of choice
  • create user '<wordpress user>'@'<host>' identified by ‘<password>’; --> create a user of choice
  • grant all privileges on <wordpress database>.* to '<wordpress user>'@'<host>' identified by ‘<password>’; --> give new user rights on new database
  • flush privileges; --> reload all rights
  • exit --> exit the MySQL interface

WordPress installation

  • cd /<directory> —> goto a directory of choice to extract WordPress
  • wget --> download latest WordPress release
  • tar xzvf latest.tar.gz --> extract the package
  • sudo mv ./wordpress/ /var/www/html/<sitename> —> move all files to live location with a name of choice
  • mkdir /var/www/html/wp-content/<sitename>/uploads —> create directory for uploads
  • chown -R apache:apache /var/www/html/ --> make apache owner of the directory

vhost configuration (optional)

if you want to create a vhost for WordPress then this is the moment. Here you can find how: installing Apache webserver

WordPress configuration

  • cd /var/www/html/<site> --> goto your WordPress directory
  • cp wp-config-sample.php wp-config.php --> copy example configuration to live configuration
  • sudo nano wp-config.php --> alter the default configuration
change: define('DB_NAME', '<databasename>');
change: define('DB_USER', '<username>');
change: define('DB_PASSWORD', '<password>');
add define('FS_METHOD', 'direct'); to end of file

Secure Wordpress directories/files

  • find /var/www/html/<site> -type d -exec chmod 755 {} \; --> secure directories
  • find /var/www/html/<site> -type f -exec chmod 644 {} \; --> secure files

Access your WordPress server

Now you should be able to access your WordPress server at http://<host>.<domain>.<tld>