1. 程式人生 > >阿里雲通過yum安裝LAMP(成功安裝上)centos7.4

阿里雲通過yum安裝LAMP(成功安裝上)centos7.4

https://blog.csdn.net/qiaosym/article/details/78710305

----------------------------------

              一、檢查

----------------------------------

1、檢視centos版本

[[email protected] ~]# cat /etc/redhat-release
CentOS Linux release 7.4.1708 (Core) 

2、檢視Apache

httpd -v

3、檢視mysql

service mysqld start

4、安裝過進行清理

yum remove mysql
rm -f /etc/my.cnf
rpm -qa | grep httpd

----------------------------------

        二、安裝apache

----------------------------------

1、安裝apache

yum -y install httpd

2、安裝apache擴充套件

yum -y install httpd-manual mod_ssl mod_perl mod_auth_mysql

3、啟動apache

systemctl start httpd.service #啟動apache
systemctl stop httpd.service #停止
systemctl restart httpd.service #重啟

4、設定開機自啟動

systemctl enable httpd.service

5、檢查安裝情況,瀏覽器訪問ip,安裝成功,結果如下

----------------------------------

       三、安裝php

----------------------------------

1、安裝php

yum -y install php

2、安裝php-fpm

yum -y install php-fpm

3、安裝php擴充套件

yum -y install php-gd php-xml php-mbstring php-ldap php-pear php-xmlrpc php-devel

4、測試php安裝

cd /var/www/html

vim v.php #編輯

編寫程式碼( i 鍵進入編輯模式)

1.<?php
2.    echo '<title>hello world</title>';
3.    phpinfo();
3.?>


esc 回到控制模式, :wq 儲存退出. 

瀏覽器訪問域名加路徑,執行v.php. 如: 127.0.0.1/v.php 

----------------------------------

       四、安裝mysql(mariadb)

----------------------------------

 

1、安裝資料庫Mariadb它是MySQL的一個分支幾乎相容mysql所有功能,執行下面命令;

yum -y install mariadb-server mariadb

2、啟動mariadb並且設定為它開機啟動;檢查是否啟動和開機啟動

systemctl start mariadb

systemctl enable mariadb

systemctl status mariadb

systemctl is-enabled mariadb

3、下面配置root密碼和資料庫的一些安全;執行命令,

mysql_secure_installation

#將會輸出讓輸入原始密碼(這裡預設為空密碼請直接回車Enter),

In order to log into MariaDB to secure it, we'll need the current

password for the root user.  If you've just installed MariaDB, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

 

Enter current password for root (enter for none): 

#這裡詢問我們是否設定root密碼,輸入y設定密碼,y(設定);  n(不設定)

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

 

Set root password? [Y/n] 

#輸入密碼再次確認密碼回車

Set root password? [Y/n] y

New password: 

Re-enter new password: 

Password updated successfully!

Reloading privilege tables..

 ... Success!

 

 

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB without having to have a user account created for

them.  This is intended only for testing, and to make the installation

go a bit smoother.  You should remove them before moving into a

production environment.

 

Remove anonymous users? [Y/n] y  (詢問是否移除匿名使用者輸入y回車)

 ... Success!

  

 

Normally, root should only be allowed to connect from 'localhost'.  This

ensures that someone cannot guess at the root password from the network.

 

Disallow root login remotely? [Y/n]  n(詢問是否禁止遠端root登陸我這裡選擇y禁止遠端登入【如果您需要遠端登入連線資料庫可選擇n】)

 

... skipping.

 

By default, MariaDB comes with a database named 'test' that anyone can

access.  This is also intended only for testing, and should be removed

before moving into a production environment.

 

Remove test database and access to it? [Y/n]  y(詢問是否刪除測試資料庫【可選項隨意y或n】這裡我選擇y)

 

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

 

Reload privilege tables now? [Y/n]  y (詢問是否現在重新載入許可權表選擇y回車)

... Success!

 

Cleaning up...

 

All done!  If you've completed all of the above steps, your MariaDB

installation should now be secure.

 

Thanks for using MariaDB!

 

 

#會自動跳到命令頁面,到此我們的資料庫設定了密碼和一些安全。

 


我們可以簡單登入下資料庫;

mysql -uroot -p

Enter password: 【輸入密碼回車即可登入進去】

 

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 13

Server version: 5.5.56-MariaDB MariaDB Server

 

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

 

MariaDB [(none)]> show databases;            【命令顯示資料庫列表】

+--------------------+

| Database           |

+--------------------+

| information_schema |

| mysql              |

| performance_schema |

+--------------------+

4 rows in set (0.01 sec)

 

MariaDB [(none)]> quit                                【退出資料庫】

Bye