How to install Apache, PHP and MySQL (LAMP) on CentOS
Posted: Thu Jan 15, 2015 9:03 pm
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
Step 3a: Install MySQL (MariaDB)
Step 3b: Start SQL service & set to start on boot
Step 3c: Finalize SQL installation options
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
Step 4b: Start Apache service & set to start on boot
Step 4c: Add ports 80 & 443 to CentOS firewall
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
Step 5b: Restart Apache service
Step 5c: Install mysql php extension
Step 5d: Again restart Apache service
Step 6a: phpMyAdmin (technically option as you can manage mysql via command line)
Step 6b: Allow remote access to phpMyAdmin
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:
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
And look for the following line:
And change 'cookie' to 'http'. And once again you'll need to reboot the Apache 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.
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
Code: Select all
systemctl start mariadb.service
systemctl enable mariadb.service
Code: Select all
mysql_secure_installation
Step 4a: Install Apache
Code: Select all
yum -y install httpd
Code: Select all
systemctl start httpd.service
systemctl enable httpd.service
Code: Select all
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
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
Code: Select all
systemctl restart httpd.service
Code: Select all
yum -y install php-mysql
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
Code: Select all
vi /etc/httpd/conf.d/phpMyAdmin.conf
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>
Step 6c: Change phpMyAdmin authentication type
Code: Select all
vi /etc/phpMyAdmin/config.inc.php
Code: Select all
$cfg['Servers'][$i]['auth_type'] = 'cookie'; // Authentication method (config, http or cookie based)?
Code: Select all
systemctl restart httpd.service
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.