This is a guide to get a fresh CentOS installation running, with LAMP stack and WordPress, in just a few minutes. Even though many cloud providers allow you to immediately deploy a WordPress instance, it has some benefits to do a full installation yourself. You will have more control over the server installation, you can do more customizations and you can add more websites later on.
It looks like a lot of text, but you can mostly copy & paste commands without reading the other information.
Deploy a fresh CentOS installation
I recommend DigitalOcean or Vultr, because they allow you to deploy your server very easy and you can pay by the hour, which makes them perfect for testing. If you like my blog, use one of the referral links below, I use the credit I receive for testing:
Deploy a simple CentOS 7 64bit cloud server, with minimum 1GB RAM (2GB RAM recommended). After deployment, log in to your server as root using SSH. Most of the time your server is deployed with all updates installed, but make sure to check this and install updates using 'yum update'. If there is a kernel update, don't forget to reboot after the installation.
Install MySQL/MariaDB and create a database
I recommend to use MariaDB, which is a MySQL fork. If you prefer MySQL, that will work fine too.
Enter the following commands in your SSH terminal to install and start MariaDB:
- yum install mariadb-server
- systemctl enable mariadb
- systemctl start mariadb
You now have your MariaDB server up and running. It's recommended to set a root password as well, by using this command: mysqladmin password
Now login on the MariaDB/MySQL Command Line Interface and create a database:
- (in your SSH shell) mysql -p
- (in the MySQL CLI) create database wordpress1;
- (in the MySQL CLI) grant all on wordpress1.* to wordpress1@localhost identified by 'PASSWORD';
Change PASSWORD to a safe password. Exit the MySQL CLI using CTRL+D.
Install Apache using these commands in your SSH terminal and open port 80 in your firewall:
- yum install httpd
- systemctl enable httpd
- rm -f /etc/httpd/conf.d/welcome.conf ; touch /etc/httpd/conf.d/welcome.conf
- firewall-cmd --permanent --zone=public --add-port=80/tcp
- firewall-cmd --reload
We don't start Apache yet.
For recent WordPress versions, a recent PHP version is recommended. The standard CentOS packages are relatively old. Although they are patched with security fixes, newer PHP versions usually have better performance, which will make your website quicker. For this reason we will first add another repository (remi in this case, but there are several others) and then install PHP 7.2.
Next to this repository, you will have to install EPEL (Extra Packages for Enterprise Linux - or in this case CentOS). In some cases EPEL is already installed, this depends on the cloud server provider. So don't worry if the EPEL command doesn't actually perform the installation. If EPEL is already installed, this file should exist: /etc/yum.repos.d/epel.repo
Additionally, a few extra PHP modules will be installed, which are required and/or useful for WordPress.
- yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
- yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
- yum --enablerepo=remi-php72 install php php-mysql php-opcache php-gd php-xml
Enter 'Y' when it asks you to import the GPG keys for the new repositories.
Download and unpack WordPress
Use the following commands to download and install WordPress:
- cd /var/www/html
- wget https://wordpress.org/latest.tar.gz
- tar xvzf latest.tar.gz --strip-components=1
- rm latest.tar.gz
- chown -R apache:apache /var/www/html
Optional: add Let's Encrypt SSL
Adding SSL is optional, but it's definitely recommended. It makes sure the connection with your website is encrypted, including when you log in to your website and send the admin username and password over the internet.
First, we create a basic virtual host configuration. This is required for the Let's Encrypt tool (certbot). Create a file called /etc/httpd/conf.d/domainname.com.conf (change domainname.com to the address of your website) and enter the following lines (don't forget to change domainname.com here as well):
<VirtualHost *:80> ServerName domainname.com ServerAlias www.domainname.com DocumentRoot /var/www/html </VirtualHost>
If you don't want your website reachable on the www name, for example when you use a subdomain for your site, just remove the ServerAlias line.
Now, start the web server, modify your firewall and install Let's Encrypt:
- systemctl start httpd
- firewall-cmd --permanent --zone=public --add-port=443/tcp
- firewall-cmd --reload
- yum install mod_ssl python-certbot-apache
After this you're ready to request your SSL certificate. Make sure the DNS is correctly pointed to your server (just create an A record to the IP address of your server). I'll give you two examples, one if you just use one (sub)domain, and another one if you also want to request the www version:
- Single domain: certbot --apache -d domainname.com
- Multiple domains: certbot --apache -d domainname.com -d www.domainname.com
Let's Encrypt will ask you a few questions, such as your e-mail address. Also, you will be asked if you want to add an HTTP -> HTTPS redirect. It's recommended to do this (choose option 2).
Start your web server and install WordPress
If you haven't done so already when requesting a Let's Encrypt certificate, start your web server using the command below:
- systemctl start httpd
- First screen: just click on Let's go.
- Second screen: enter your database information (the same as you used for creating your database and user).
- Third screen: click on Run the installation.
- Fourth screen: you will be asked enter a site title, username and password for your WordPress admin user and your email address. For a new website or for testing purposes, click on the checkbox called Discourage search engines from indexing this site, so search engines won't index your website. If your website is ready to go into production, don't forget to enable this in the WordPress configuration. After you have filled in this information, click on Install WordPress and if everything goes well, your WordPress website is ready for use!
Feel free to ask them in the comments section below!