Install a LAMP on CentOS, Fedora or Redhat : This article provides instructions for installing a LAMP (Linux, Apache, MySQL, PHP) stack on your server. This tutorial is very basic , Strictly for beginners or internal purpose . This guide helps you to install LAMP server on centos.
Install LAMP server on centos 7.
1. Apache installation.2. Mysql installation.
3. PHP installation.
4. Testing all together.
let’s start
Apache installation
Step 1 » Update the repositories.
[root@ali ~]# yum check-update
Step 2 » After updating repository, issue the below command to install apache package.Step 3 » Now start the service and enable it at startup.[root@
ali
~]# yum install httpd
Command to start the service
Step 4 » By default, Apache will listen on port 80. you need to exclude from firewall.[root@
Command to enable at startup
ali
~]# systemctl start httpd.service
[root@
ali
~]# systemctl enable httpd.service
you can simply exclude http service from firewall.
[root@
ali
~]# firewall-cmd --permanent --add-service
http
or you can exclude using port number. Below command will be useful for ports other than 80Step 5 » Now restart firewall service.[root@
ali
~]# firewall-cmd --permanent --add-port=8080/tcp
Step 6 » Apache installation is over . For testing, open http://serverip in your browser, you can see apache demo page like below.[root@
ali
~]# systemctl restart firewalld.service
MySQL installation.
Step 7 » Start installing MariaDB, MySQL drop-in replacement.Step 8 » Now start the service and enable it at startup.[root@
ali
~]# yum install mariadb-server mariadb
Start the service
Step 9 » Secure your DB installation. Type the below command and provide values.[root@
Enable at startup
ali
~]# systemctl start mariadb
[root@
ali
~]# systemctl enable mariadb.service
[root@
1.
ali
~]# mysql_secure_installation
current password ( Leave blank and hit Enter ).
2. Enter new password.
3. Re Enter password.
and Hit enter for all the other options.
Step 10 » MariaDB installation is over. For testing, Check login into DB using the below command.
[root@
ali
~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.37-MariaDB MariaDB Server
Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
PHP installation.
Step 11 » Install PHP and other recommended packages.[root@
ali
~]# yum install php php-mysql
Additional packages are required if you would like to install phpmyadmin .
Step 12 » Now restart apache service.[root@
ali
~]# yum install php-gd php-pear php-mbstring php-pgsql
Step 13 » For testing, Create a file phpinfo.php in /var/www/html/ ( Default root directory ) and add the below code.[root@
ali
~]# systemctl restart httpd.service
Now open http://serverIP/phpinfo.php in your browser. you will see PHP version and other configuration details like below.Testing all together
Step 14 » For testing Database connectivity through PHP. Create a file dbtest.php in /var/www/html/ and add below code . Kindly replace with your root password in the below code .$con = mysql_connect("localhost","root","password");if (!$con){die('Could not connect: ' . mysql_error());}else{echo "Congrats! connection established successfully";}mysql_close($con);?>
Now access http://serverIP/dbtest.php . you should get congrats message.
Have a nice day.
No comments:
Post a Comment
Terima kasih atas komentarnya