How To Install Linux, Apache, MySQL, PHP (LAMP) stack On CentOS 7
For web development what you need is LAMP on your linux machine.
Following are the steps to install LAMP
- Get the VPN server from
- Host.inertiagroups.com
- For other cheaper options for the hosting where we simply need to host anyone website in PHP
- Visit this link: Shared Hosting Plans
- Once you purchase the VPN or shared Server as mentioned above or in case you already have a server in place with you and its OS is CENTOS, refer below simple steps to get your server ready
Install Apache
- to install apache in centos trigger following command :
- commands:
sudo yum install httpd
Since we are using a
sudo
command, these operations get executed with root privileges. - Once it installs, you can start Apache on your VPS:
sudo systemctl start httpd.service
- As this is started you can check the same at your browser
http://your_server_IP_address/
- If you see this page, then your web server is now correctly installed. The last thing you will want to do is enable Apache to start on boot. Use the following command to do so:
sudo systemctl enable httpd.service
- disable/add a port to the firewall using the command :
- iptables -I INPUT 5 -i eth0 -p tcp –dport 80 -m state –state NEW,ESTABLISHED -j ACCEPT
- if your system is using firewalld
- For instance, if we are running a web server serving conventional HTTP traffic, we can allow this traffic for interfaces in our “public” zone for this session by typing:
- sudo firewall-cmd –zone=public –add-service=http
You can leave out the
--zone=
if you wish to modify the default zone. We can verify the operation was successful by using the--list-all
or--list-services
operations:- sudo firewall-cmd –zone=public –list-services
output
dhcpv6-client http ssh
- Once you have tested that everything is working as it should, you will probably want to modify the permanent firewall rules so that your service will still be available after a reboot. We can make our “public” zone change permanent by typing:
- sudo firewall-cmd –zone=public –permanent –add-service=http
outputsuccess
You can verify that this was successful by adding the
--permanent
flag to the--list-services
operation. You need to usesudo
for any--permanent
operations:- sudo firewall-cmd –zone=public –permanent –list-services
outputdhcpv6-client http ssh
Your “public” zone will now allow HTTP web traffic on port 80. If your web server is configured to use SSL/TLS, you’ll also want to add the
https
service. We can add that to the current session and the permanent rule-set by typing:- sudo firewall-cmd –zone=public –add-service=https
- sudo firewall-cmd –zone=public –permanent –add-service=https
- For instance, if we are running a web server serving conventional HTTP traffic, we can allow this traffic for interfaces in our “public” zone for this session by typing:
- commands:
- to install apache in centos trigger following command :
Restart the firewalld service
after this, we should we able to check to see the screen as shown above.
[bibblio style=”bib–row-3 bib–default bib–hover bib–white-label bib–font-arial bib–size-18″ query_string_params=e30=]
Install MySQL (MariaDB)
Install Mysql following this link
- Command:
sudo yum install mariadb-server mariadb
start MariaDB with the following command:
sudo systemctl start mariadb
- Start the interactive script by running:
sudo mysql_secure_installation
in this command run you would be asked multiple question where you would need to enter password , please enter that and remember for future usage
- Enable MariaDB to start on boot. Use the following command to do so:
sudo systemctl enable mariadb.service
check whether you mysql is installed successfully or not
- commoand:
- mysql -u root -p “password”
- this command should give the mysql prompt
- commoand:
- Command:
Install PHP
We’re going to install php and php-mysql package :
sudo yum install php php-mysql
- this will install PHP on your centOS
Test PHP Processing on your Web Server
- Now it looks like the LAMP is installed on your VM, so to test for the success of the same perform following steps :
- In CentOS 7, web directory is located at
/var/www/html/
. We can create the file at that location by typing:sudo vi /var/www/html/info.php
- Inside this file enter following line, this line will help us in getting the PHP version info
<?php phpinfo(); ?>
- save and close the file
- command : :wq
- disable your VM firewall or run following command to allow access
- commands to allow HTTP and HTTPS traffic:
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --reload
- commands to allow HTTP and HTTPS traffic:
- install mcrypt – this package is mostly required.
sudo yum install php-mcrypt*
- The address you want to visit will be:
http://your_server_IP_address/info.php
- In CentOS 7, web directory is located at
- Now it looks like the LAMP is installed on your VM, so to test for the success of the same perform following steps :
Conclusion
Now that you have a LAMP stack installed, you have many choices for what to do next. Basically, you’ve installed a platform that will allow you to install most kinds of websites and web software on your server.
This document is the verified document, so people trying this will not face any error in setting up LAMP and in case any of you are facing any issue please post in the comment below with your concerns.