Skip to content

Instantly share code, notes, and snippets.

@nardhar
Last active September 6, 2017 13:49
Show Gist options
  • Save nardhar/86939bdcfcd056f3470deaa8cd4f08af to your computer and use it in GitHub Desktop.
Save nardhar/86939bdcfcd056f3470deaa8cd4f08af to your computer and use it in GitHub Desktop.
wordpress CentOS 7

Install Wordpress on CentOS 7

Install LAMP

$ sudo yum install httpd mariadb mariadb-server php php-common php-mysql php-gd php-xml php-mbstring php-mcrypt php-xmlrpc unzip wget -y

Enable Apache and MariaDB as service

$ sudo systemctl start httpd
$ sudo systemctl start mariadb
$ sudo systemctl enable httpd
$ sudo systemctl enable mariadb

Secure MariaDB

$ sudo mysql_secure_installation

Answer all the questions as shown below, do not forget to set a strong root password in the first step:

Set root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

Login to MariaDB console

$ mysql -u root -p

It will ask for root password, and after login we will create the WordPress DB (change wordpress user and password)

MariaDB [(none)]>CREATE DATABASE wordpress;
MariaDB [(none)]>GRANT ALL PRIVILEGES on wordpress.* to 'user'@'localhost' identified by 'password';
MariaDB [(none)]>FLUSH PRIVILEGES;
MariaDB [(none)]>exit

Install WordPress

$ wget http://wordpress.org/latest.tar.gz
$ tar -xzvf latest.tar.gz

After extracting the files we copy the wordpress folder contents to /var/www/html/ but I prefer to install it in a virtualhost and another folder, e.g.: /home/wordpress/my_site

The next step is prepare the WordPress site to install itself

#create a folder to store uploaded files
$ sudo mkdir /home/wordpress/my_site/wp-content/uploads
#proper ownership
$ sudo chown -R apache:apache /home/wordpress/my_site/
$ sudo chmod -R 755 /home/wordpress/my_site/

and configure WordPress DB

$ cd /home/wordpress/my_site/
$ sudo mv wp-config-sample.php wp-config.php
$ sudo nano wp-config.php

change connection

define('DB_NAME', 'wordpress');
define('DB_USER', 'user');
define('DB_PASSWORD', 'password');

enable firewall

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

enable virtualhost

$ sudo nano /etc/httpd/conf.d/my_site.conf

copy this content and save

<VirtualHost *:80>
  ServerAdmin user@mysite.com
  DocumentRoot "/home/wordpress/my_site/"
  #using a subdomain
  ServerName blog.mysite.com
  ServerAlias blog.mysite.com
  #we could use root also like this
  #ServerName mysite.com
  #ServerAlias www.mysite.com
  
  ErrorLog "/var/log/httpd/my_site-error_log"
  CustomLog "/var/log/httpd/my_site-access_log" combined
  
  <Directory "/home/wordpress/my_site/">
  	DirectoryIndex index.php
  	Options Indexes FollowSymLinks
  	AllowOverride All
  	Require all granted
  </Directory>
</VirtualHost>

create subdomain in your dns configuration or your domain registrar to point to your server for testing we could edit /etc/hosts

$ sudo nano /etc/hosts

add the following line

127.0.0.1   blog.mysite.com

In your client machine edit /etc/hosts too, but add the server ip

1.2.3.4   blog.mysite.com

Now we just restart apache service with $ sudo systemctl restart httpd.service and configure wordpress in the url blog.mysite.com Saddly I got a 403 forbidden error, but solved it when executing the following:

$ sudo chmod +x /home/wordpress
$ sudo chmod +x /home/wordpress/my_site
$ sudo chcon -t httpd_sys_content_t /home/wordpress/my_site -R

This is because apache must be able to execute all content from the wordpress folder and be searchable (?) too, that's why we need to add execution permission over /home/wordpress folder too

For anyone wondering, the exact error in /var/log/httpd/my_site-error_log was this:

(13)Permission denied: [client x.x.x.x:xxxxx] AH00035: access to / denied (filesystem path '/home/wordpress/my_site') because search permissions are missing on a component of the path

Now we restart apache again and when entering blog.mysite.com I get the install page which I will add later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment