Install lamp server (apache, mysql, php) on rhel, centos

     
In this tutorial we can see the step by step installation of Apache webhệ thống along with mysql & php enabled. This tutorial is very basic , Strictly for beginners or internal purpose .

Bạn đang xem: Install lamp server (apache, mysql, php) on rhel, centos

After installing Centos 6 (Centos 6 installation step by step screenshots ) and configuring network (How khổng lồ setup network in centos 6)

Update yum repositories & packages by typing the below command

localhost ~># yum update After updating repositories , we can start installing packages one by one. 1. Apache2 installation and configuration 2. Mysql installation 3. PHP installation 4. Testing all together

Apache2 installation :

Apache2 package installation & configuration is very simple .

Step 1 » just type the command

localhost ~># yum install httpd

This commvà will install httpd package along with dependencies

After installing the package .

Step 2 » xuất hiện the file /etc/httpd/conf/httpd.conf . Find “#ServerName www.example.com:80” (line no : 276 ) . # #ServerName www.example.com:80 and add this line below . “ServerName youripaddress:80”

# #ServerName www.example.com:80 ServerName 192.168.141.22:80

Step 3 » Now start apabịt service

localhost ~># service httpd start

& type this below comm& lớn start apađậy service automatically while booting.

localhost ~># chkconfig --levels 235 httpd on

Step 4 » Now you have successfully configured apache web server . open your browser and type the ip address in the address bar & hit enter . you can see the kiểm tra page of your website VPS .

*

Testing your page:

Goto lớn the mặc định apache root path /var/www/html . create a new file index.html & paste the below code and save it.

Welcome lớn my webserver

Again open the webserver ip address in the browser . you can see the index page created by you.

*

Mysql installation :

Step 1 » just type the comm& to install mysql hệ thống và client packages along with dependencies .

localhost ~># yum install mysql-server

After installation packages và dependencies .

Step 2 » Start mysql service

localhost ~># service mysqld start

and type this below commvà to lớn start mysql server automatically while booting.

Xem thêm: Hướng Dẫn Nhập Dữ Liệu Trong Excel Theo Cách Nhập Dữ Liệu Vào Excel Nhanh Nhất

localhost ~># chkconfig --levels 235 mysqld on

Step 3 » Create a new root password for mysqlserver

localhost ~># mysqladmin -u root password "********"

Step 4 » Test your mysql server by login as root

localhost ~># mysql -u root -p ( press enter ) Enter password:(Type your mysql root password and press enter) Now you can see the mysql prompt.

PHPhường installation :

Step 1 » Install php package along with php-mysql . localhost ~># yum install php php-mysql After installing php , create a php info tệp tin khổng lồ thử nghiệm your php configuration .

Step 2 » Goto the mặc định apabít root path /var/www/html . create a new file phpinfo.php & paste the below code và save it.


1
2
3
phpinfo();
?>

Step 3 » Restart apabịt service

localhost ~># service httpd restart

Step 4 » open the filepath in the browser ( http://192.168.141.22/phpinfo.php ). you can see the php information page as below.

*

and make sure you can see the mysql details in the php information page .

*

Finally apache2 , php và mysql has been configured perfectly . few more steps need lớn be performed khổng lồ kiểm tra the database connectivity.

Testing All together :

We need to chạy thử mysql database connectivity in php .

Step 1 » create a new file dbtest.php in the apabịt root path (/var/www/html) & paste the below code .Replace “password” with your mysql root password.


1
2
3
4
5
6
7
8
9
10
11
12
$bé = mysql_connect("localhost","root","password");
if (!$con)

die("Could not connect: " . mysql_error());

else

emang lại "Congrats! connection established successfully";

mysql_close($con);
?>

Step 2 » open the filepath in the browser ( http://192.168.141.22/dbthử nghiệm.php ). you can see the page as below.

*

Congrats , you just made it

If you are getting some errors like

» Could not connect: Can’t connect to local MySQL hệ thống through socket ‘/var/lib/mysql/mysql.sock’ (2)

( This means your mysql hệ thống service is stopped , you must start the service “service mysql start”)

» Could not connect: Access denied for user ‘root’
’localhost’ (using password: YES)

(Something wrong with username và password )

if you are getting a blank page , then must be a problem with the code .

Like this post » just buy me a beer or leave sầu a comment

Also see

Setup LAMPhường hệ thống on ubuntu 18.04


Related Posts


*
PreviousHow lớn install teamviewer7 on ubuntu 12.04


*
Next

Installing and configuring samcha on centos 6


JOIN US
Recent Posts
Follow us
Recent Comments
Categories

Chuyên mục: Domain Hosting