Tutorial to guide newbie how to install complete LAMP stack with Apache, MariaDB MySQL and PHP5 on CentOS 7. Full screenshot pics inlcluded. This is the full all-in-page guide of LAMP stack installation series I wrote for CentOS 6 before. There is no significant difference except the use of new systemctl command. You can read a short introduction (information) about why and what is systemctl command in my previous post.
LAMP which originally stands for Linux, Apache, MySQL and PHP has now recently changed with the rise of MariaDB, a drop-in replacement for original MySQL. Long story short, MariaDB is a fork of MySQL and developed by MySQL developers itself. It has almost all features of what MySQL has and features library binary equivalency and exact matching with MySQL APIs and commands. It means if an app is able to run with MySQL and it also is able to on MariaDB without any glitch. I will not explain what is Apache and PHP as I’ve explained before and I believe you already knew what it is.
Let’s start with the step by step tutorial:
You may need:
- A server (VPS / Dedi) running CentOS 7. I recommend you to use CentOS 7 x86_64 minimal if available. As usual, I’m using a Playground Server from DigitalOcean.
- A knowledge on how to use Putty or Terminal to access a server via SSH.
- I believe you knew –at least part of– most common Unix commands used to manage an unmanaged server.
- A spare time of your life and a cup of coffee.
Install Apache Web Server
Being the most popular web server, Apache is commonly included in most of recent Linux Distro so installation will be very easy.
Before you proceed to the next steps, it is better to explain that all commands in this tutorial are written without the “sudo” prefix. In this tutorial I use root but you may also login as separate user with root privilege. However if you disabled root login and you logged in using another username with root privilege, you can add the “sudo” prefix all by your self. Alternatively you can simply type su, hit Enter and type in your password twice to switch as root.
Step 1 – Login to your server via Putty or Terminal.
Step 2 – Now issue command below to install Apache 2.4 on your CentOS 7 server:
yum install httpd -y
As you can see the command is still the same.
And when the process finished, you’ll see something like this:
Step 3 – Now you have Apache 2.4 installed which you can then start the service by typing command below:
systemctl start httpd.service
service httpd start
systemctl status|start|stop|restart|reload httpd.service
# OR, old command :
service httpd status|start|stop|restart|reload
Step 4 – You can verify that Apache is really running by opening your favorite web browser and access your vps via its IP address:
and you’ll see default Apache welcome page.
In current example I’ve installed Apache v2.4.6.
or, you can directly issue this command:
systemctl status httpd.service
you’ll see something like this:
Enable Apache to automatically run every time your server reboot:
systemctl enable httpd.service
Step 5 – Now, it is time to install PHP5. Default command is:
yum install php -y
That’ really is a simple command but since we will install MySQL then we’ll need PHP MySQL modules plus any other PHP5 modules you website / app may need it. You can view all available modules using this command:
yum search php-
Confused? You can read my previous article or you can simply use command below that includes common PHP5 modules most websites can run with it.
yum install php php-common php-cli php-devel php-gd php-imap php-intl php-mysql php-process php-xml php-xmlrpc php-zts -y
And once done, you’ll see something like this:
You can test which version of PHP is installed by typing php -v command.
In my example it is PHP v5.4.16.
Install MariaDB MySQL Server
Step 6 – Installing MariaDB mysql server on CentOS 7 is pretty easy and once again we’ll make us of yum package manager:
yum install mariadb-server mariadb -y
and once done you’ll see something like this:
Step 7 – Now you can start MariaDB server for the very first time using this simple systemctl command :
systemctl start mariadb.service
You may also see the status of MariaDB by typing:
systemctl status mariadb
MariaDB Initial Configuration
Step 8 – So its service is now running but there is one thing you should do immediately: configuring MariaDB setup for the very first time like setting up your mysql root password. Issue this command:
Then you’ll see a series of question, just answer it accordingly. The main important part is to define your root password while everything else is just up to you or you can simply hit the “ENTER” key through each prompt to accept the default values.
If you need to automatically run MariaDB everytime your server boot, simply issue this command:
systemctl enable mariadb.service
You may also need to test your newly installed MariaDB by logging in as root:
mysql -u root -p
As you can see from the screenshot above, it is Maria DB v5.5.37.
Step 9 – Also test if Apache and PHP is running well and able to process any *.php files. Create a php info page using this command followed by restarting apache
echo "<?php phpinfo(); ?>" > /var/www/html/info.php
systemctl restart httpd.service
Now open up your browser and access that newly created php page:
You’ll see a page similar to this one:
Step 10 – Now your server has Apace, PHP and MariaDB installed. It means it should be OK now to install PhpMyAdmin, a popular web-based database management system so you can easily manage your database without having to login via SSH and issuing several command lines. Unluckily, this piece of awesome software is not available in CentOS 7.0 default repositories. In this case you have to add / enable third-party repo like EPEL or RPMForge.
Method #1: RPMForge
First, download the rpm file.
then enable the repository and delete the .rpm file as it is not needed again.
rpm -ivh rpmforge-release-*
Method #2: EPEL
Download the .rpm file:
The url above is still its beta version. However if the repository is out of beta status, the link most likely will be different. In case that happens, you can find out its latest download url at Fedora Project website.
enable the repository and delete the .rpm file:
rpm -ivh epel-release*
Step 11 – Next, install it using yum again:
yum install phpmyadmin -y
Step 12 – That’s it. Now you also have phpMyAdmin (PMA) installed but you should be better if you change its default configuration before using it. First, you’ll need to backup default PMA’s config file:
cp /etc/httpd/conf.d/phpMyAdmin.conf /etc/httpd/conf.d/phpMyAdmin.conf.old
then edit file phpMyAdmin.conf file using your favorite editor. In this example I use Nano editor:
Step 13 – You’ll now see the content of phpMyAdmin.conf, next you have to allow connections from remote hosts by editing few lines inside section <Directory “/usr/share/phpMyAdmin”>.
Also you’ll need to edit few lines next:
Shortly it should look like this:
# Apache 2.4
Require all granted
# Apache 2.2
#Deny from All
Allow from All
Require all granted
Once done, save and exit editor (In Nano it is Control+O then Control+X).
Step 14 – Restart Apache again:
systemctl restart httpd.service
Now you can test opening PMA on your browser via your server’s IP address:
and default login page of phpMyAdmin should be displayed:
That’s all. Now you can host your websites or blogs in that server, even WordPress.
Do not forget to follow me on twitter to get faster update or download my official Android app. Enjoy..