1. 程式人生 > >阿里雲上安裝LAMP(PHP)

阿里雲上安裝LAMP(PHP)

地址:https://jingyan.baidu.com/article/4d58d54165aaf79dd5e9c058.html

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

安裝Apache

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

第一步:使系統處於最新狀態執行以下命令

yum update -y

第二步:利用yum命令安裝Apache執行命令

yum -y install httpd

第三步:啟動httpd並且設定為它開機啟動

systemctl start httpd    【啟動httpd命令】 

systemctl enable httpd 【設定httpd開機啟動】

第四步:我們這裡可通過倆個命令檢視是否啟動和開機啟動

systemctl status httpd      【檢視是否啟動命令】

systemctl is-enabled httpd 【檢視是否開機啟動(輸出enabled已經成功)】

第五步:安裝成功後,在瀏覽器位址列輸入你的伺服器IP地址出現下圖說明你的httpd已經成功安裝(Appache安裝成功)

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

安裝MySQL

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

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

yum -y install mariadb-server mariadb

第二步:啟動mariadb並且設定為它開機啟動;檢查是否啟動和開機啟動

systemctl start mariadb
systemctl enable mariadb

systemctl status mariadb
systemctl is-enabled mariadb

第三步:下面配置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

 

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

安裝php(需要的元件比較多)

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

第一步:安裝PHP,執行命令;

yum -y install php

第二步:檢視所有元件,執行命令;

yum search php

第三步:選擇所需元件進行安裝,執行命令;

yum -y install php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel

第四步:完成後我們可以新建一個PHP頁面來檢視我們安裝的元件,執行命令;

vim /var/www/html/info.php
#開啟後按鍵盤字母 i  
#編輯為以下內容;

<?php
phpinfo();
?>

#編輯完後按鍵盤 Esc 在輸入  :  最後 wq!   回車。
#vim使用方法可自行百度,不作詳細解釋

第五步:最後重啟的httpd服務,執行命令;

systemctl restart httpd

第六步:

開啟瀏覽器輸入:xx.xx.xx.xx/info.php(即IP地址 / 和檔名)

#看到這個頁面證明您的LAMP環境搭建httpd釋出目錄預設在/var/www/html/

#您可以使用winscp上傳您的頁面到釋出目錄

###最後執行命令    rm -rf /var/www/html/info.php    刪除你的這種測試檔案###

 

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

#rpm -qa|grep php        列出所有的php相關的rpm包

#rpm -e xxx xxx            指的是上一個命令列出的rpm包的包名,複製即可。這一步解除安裝安裝的php的rpm包,注意因為可能存在依賴關係會發生報錯,所以可能需要調整下要寫在的rpm包的順序。