How to install Apache, PHP and MySQL (LAMP) on CentOS

Post Reply
User avatar
Juski
Former staff
Former staff
Posts: 147
https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
Joined: Sun Dec 07, 2014 5:04 pm
Location: Seattle, WA

How to install Apache, PHP and MySQL (LAMP) on CentOS

Post by Juski »

This guide is for getting started with PHP/SQL/Apache for CentOS 7.0, if you need assistance with Ubuntu, please see Vanderburg's guide here.

Step 1: Acquire PuTTy (or use the VNC Console tab of your Control Panel)



Step 2: Add additional repository

Code: Select all

rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

Step 3a: Install MySQL (MariaDB)

Code: Select all

yum -y install mariadb-server mariadb
Step 3b: Start SQL service & set to start on boot

Code: Select all

systemctl start mariadb.service
systemctl enable mariadb.service
Step 3c: Finalize SQL installation options

Code: Select all

mysql_secure_installation
Hit ENTER to skip the current password, then enter "Y" to set the root password. Afterwards, it is recommended that you enter "Y" for the next four prompts for security reasons.



Step 4a: Install Apache

Code: Select all

yum -y install httpd
Step 4b: Start Apache service & set to start on boot

Code: Select all

systemctl start httpd.service
systemctl enable httpd.service
Step 4c: Add ports 80 & 443 to CentOS firewall

Code: Select all

firewall-cmd --permanent --zone=public --add-service=http 
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
Step 4d (optional): Test Apache setup
Visit your server's IP address (for example http://192.168.1.100), and if everything went to plan, you should be greeted by the default Apache installation welcome page.



Step 5a: Install PHP

Code: Select all

yum -y install php
Step 5b: Restart Apache service

Code: Select all

systemctl restart httpd.service
Step 5c: Install mysql php extension

Code: Select all

yum -y install php-mysql
Step 5d: Again restart Apache service

Code: Select all

systemctl restart httpd.service

Step 6a: phpMyAdmin (technically option as you can manage mysql via command line)

Code: Select all

yum install phpMyAdmin
Step 6b: Allow remote access to phpMyAdmin

Code: Select all

vi /etc/httpd/conf.d/phpMyAdmin.conf
You will be viewing a text file. VIM is a bit finicky, so here's a VERY brief run down. VIM has two phases, execute phase and editor phase. You start in execute phase, so to edit you have to hit the "i" key on your keyboard (you'll see INSERT at the bottom of your PuTTY window). To get back to execute phase, just hit ESC on your keyboard.

You can only exit, or save and exit, from VIM from the execute phase. And to exit, you type ":q!" and hit ENTER. To save and exit, you enter ":wq" and hit ENTER. Fun, right?!

Now, back to the conf file, since most ISP assigned IP addresses can (and will) change, you will simply want to comment out the entire section between:

Code: Select all

<Directory /usr/share/phpMyAdmin/>

and

</Directory>
To comment it out, first enter editor phase (remember, hit "i" on your keyboard) and simply put # before each line starting with and ending with the above lines.

Step 6c: Change phpMyAdmin authentication type

Code: Select all

vi /etc/phpMyAdmin/config.inc.php
And look for the following line:

Code: Select all

$cfg['Servers'][$i]['auth_type']     = 'cookie';    // Authentication method (config, http or cookie based)?
And change 'cookie' to 'http'. And once again you'll need to reboot the Apache service:

Code: Select all

systemctl restart  httpd.service
You will now be able to access phpMyAdmin by adding /phpmyadmin to your website IP address or DNS address (for example, http://192.168.0.100/phpmyadmin) and your username and password will be the root and the password you setup in the SQL portion of this guide above.



Special Notes:
The root directory of your webserver will be in /var/www/html/ and files can be uploaded there to be viewed in the browser.

Also, you do not want to use the root account on MySQL, generally. Log into phpMyAdmin with the root account, and create a secondary account and then use that account. It's useful for keeping your server secure.
Post Reply