17th December 2024

Installing Php, Apache and Mysql on Centos

In this article, we will talk about apache, mysql and PHP installations on Centos. After logging in as root, we enter the following commands on the terminal screen in order. We can install with a single command or with a separate command. We will install apache, mysql and PHP with yum command at a time. When we type -y after yum in the command, it means that we approve the download of the required files.

yum -y install httpd php mysql mysql-server php-mysql
install httpd php mysql mysql-server php-mysql
install httpd php mysql mysql-server php-mysql

 

You can install PHP, MySQL and Apache separately as follows, as it is installed with a single command.

sudo yum -y install mysql mysql-server
install mysql mysql-server
install mysql mysql-server

 

sudo yum -y install httpd
install httpd
install httpd
sudo yum -y install PHP
install php
install php

 

Config file

We add the following lines to the config files in order for the services to start automatically when the system restarts.

/sbin/ chkconfig httpd on
/sbin/ chkconfig mysqld on
Config file
Config file

 

Running services

We enter the commands that run Apache and mysql respectively.

sudo /sbin/service httpd start
sudo /sbin/service mysqld start
Running services
Running services

 

Testing that PHP is Working

Apache’s default folder in Centos systems is /var/www/html. We will go into this folder and create the test.php file. We enter the test.php file and enter the following code, press CTRL+X, click y, save and exit.

cd /var/www/html
sudo nano test.php
/var/www/html
/var/www/html
test.php
test.php

 

Now we write “http://youraddress/test.php” to our browser and see if PHP is working. As you can see on the screen below, php is working.

Testing that PHP is Working
Testing that PHP is Working

 

LEARN MORE  What is Ansible? How is the file structure?

Leave a Reply

Your email address will not be published. Required fields are marked *