Install Craft CMS on CentOS 7
In order to run Craft your server needs to meet the following requirements:
- PHP 5.3.0 or later
- MySQL server 5.1.0 or later
- A web server (Apache, Nginx, IIS)
- 32MB or more memory allocated to PHP
- 20MB or more free disk space
- 1MB or more database space
Installing Craft is very easy. First of all log in to your server as user root and make sure that all packages are up to date by executing the following command
yum -y update
Run the following command to install MariaDB database server
yum install mariadb mariadb-server
Start the MariaDB database server and enable it to start at the boot time
systemctl start mariadb systemctl enable mariadb
Run the ‘mysql_secure_installation’ script to secure the database server and set your MariaDB root password
Log in to the MariaDB server using the ‘root’ user and create new database and user for Craft.
mysql -u root -p CREATE DATABASE craft; CREATE USER 'craftuser'@'localhost' IDENTIFIED BY 'PASSWORD'; GRANT ALL PRIVILEGES ON `craft`.* TO 'craftuser'@'localhost'; FLUSH PRIVILEGES;
Don’t forget to replace ‘PASSWORD’ with a strong password.
Next, we will install Apache web server
yum install httpd
Same as we did with MariaDB, start the Apache web server and add it to automatically start on the system start-up
systemctl start httpd systemctl enable httpd
Craft is PHP based application, so we need to install PHP among with few PHP modules
yum install php php-pdo php-common php-mcrypt php-mbstring
Download the latest stable release of Craft from their official website.
Unpack the downloaded zip archive.
The archive contains two directories ‘craft/’ and ‘public/’ . It is recommended to move the ‘craft/’ directory above the document root directory.
mv craft/ /var/www/
And move the ‘public/’ directory to the document root directory on your server and change your current working directory.
mv public/ /var/www/html/ cd /var/www/html/ mv public/ craft/
If you are not sure where is your document root directory you can use the following command to find out
grep -i '^documentroot' /etc/httpd/conf/httpd.conf DocumentRoot "/var/www/html"
Change the ownership
chown -R apache:apache craft/
Now, we need to tell Craft how to connect to the MariaDB database. Opoen the db.conf file and enter the database information:
vim ../../craft/config/db.php 'server' => 'localhost', 'user' => 'craftuser', 'password' => 'PASSWORD', 'database' => 'craft', 'tablePrefix' => 'craft',
Rename the htacces file located in the ‘public/’ directory
mv public/htaccess public/.htaccess
Next, create Apache virtual host for your domain. Create ‘/etc/httpd/conf.d/vhosts.conf’ directory with the following content
vim /etc/httpd/conf.d/vhosts.conf IncludeOptional vhosts.d/*.conf
and create the virtual host
vim /etc/httpd/vhosts.d/yourdomain.com.conf <VirtualHost YOUR_SERVER_IP:80> ServerAdmin [email protected] DocumentRoot "/var/www/html/craft/" ServerName yourdomain.com ServerAlias www.yourdomain.com ErrorLog "/var/log/httpd/yourdomain.com-error_log" CustomLog "/var/log/httpd/yourdomain.com-access_log" combined <Directory "/var/www/html/craft/"> DirectoryIndex index.html index.php Options FollowSymLinks AllowOverride All Require all granted </Directory> </VirtualHost>
Restart the Apache web server for the changes to take effect.
systemctl restart httpd
Now, load Craft’s administrator panel at http://yourdomain.com/admin to finish the installation.
Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install Craft for you. They are available 24×7 and will take care of your request immediately.
PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.