Lamp:centos+apache+mysql+php配置教程

前言

本教程是講述的是從到部署php項(xiàng)目到阿里云服務(wù)器上面。


配置環(huán)境

Contos: 7
Xshell版本:Xshell 5


教程開(kāi)始

購(gòu)買(mǎi)服務(wù)器

  • 先去阿里云官網(wǎng) 買(mǎi)一個(gè)ECS服務(wù)器 之后 創(chuàng)建一個(gè)實(shí)例。
  • 通過(guò)快速創(chuàng)建規(guī)則添加安全組規(guī)則 如下:


    M(IBCU$(R{P@68M1}84VU55.png
  • 用Xshell 進(jìn)入服務(wù)器

安裝apache

  • 安裝apachecentos可以直接yum安裝apache 。
    命令:yum install httpd //根據(jù)提示,輸入Y安裝即可成功安裝
    -訪問(wèn) http://<服務(wù)器的公網(wǎng) IP 地址>/
    你將會(huì)看到一個(gè)出于通知和測(cè)試目的而存在的默認(rèn) CentOS 7 Apache 網(wǎng)頁(yè)。說(shuō)明安裝成功,失敗的話(huà),去阿里云官網(wǎng)添加安全組。
  • 然后啟動(dòng)apache,并且設(shè)置系統(tǒng)讓 Apache 開(kāi)機(jī)自動(dòng)啟動(dòng)。
    命令:systemctl start httpd.service //啟動(dòng)Apache
    systemctl enable httpd.service//設(shè)置開(kāi)機(jī)自啟

安裝mysql

  • 安裝mysql,此處也直接yum安裝
命令:  
yum install mysql mysql-server。//安裝mysql
 yum install mariadb-server -y //MariaDB代替了mysql數(shù)據(jù)庫(kù)所以要裝  
 systemctl start mariadb.service //啟動(dòng)服務(wù)  
 systemctl enable mariadb.service //開(kāi)機(jī)啟動(dòng)服務(wù)  
 mysql -u root -p //登錄mysql 
 UPDATE user SET      Password=PASSWORD('newpassword') where USER='root'; //更新root密碼
mysql> UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';//最新版MySQL請(qǐng)采用SQL命令
FLUSH PRIVILEGES;//刷新權(quán)限 
quit;//退出mysql
systemctl restart mariadb.service//重啟mysql
mysql -uroot -p//使用root用戶(hù)重新登錄mysql

安裝PHP,和PHP組件

  • 安裝PHP,和PHP組件
命令:
yum install php

yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt

到此我們的apache、mysql、php都安裝完了。在此重啟一次apache和mysql

命令:
systemctl restart httpd.service  
systemctl restart mariadb.service   

文件目錄

  • apache默認(rèn)網(wǎng)站目錄是/var/www/html
  • httpd.conf目錄是/etc/httpd/conf

錯(cuò)誤及解決辦法

  • Host '某個(gè)ip' is not allowed to connect to this MariaDB server
解決辦法
mysql -uroot -p//登錄root數(shù)據(jù)庫(kù)

//允許用戶(hù)testuser從ip為222.129.1.1的主機(jī)連接到mysql服務(wù)器,并使用testpassword作為密碼
 grant all privileges on *.* to 'testuser'@'指定ip' identified by '數(shù)據(jù)庫(kù)密碼' with grant option;    
(若是允許所有ip:GRANT ALL PRIVILEGES ON *.* TO ‘?dāng)?shù)據(jù)庫(kù)用戶(hù)名’@'%’ IDENTIFIED BY ‘?dāng)?shù)據(jù)庫(kù)密碼’ WITH GRANT OPTION;)  
 flush privileges;   //刷新權(quán)限緩存  
 show privileges;  
 show grants for  'testuser'@'222.129.1.1'   
  • thinkphp的STORAGE_WRITE_ERROR:問(wèn)題
解決辦法
//加 777 權(quán)限
sudo chmod -R 777 目錄;

附加命令

cd 返回根目錄
cd .. 返回上級(jí)目錄
cd /目錄名 可以到該目錄下
cp 文件1名 文件2名   把文件1復(fù)制成文件2
vim 命令:
vim 文件名 打開(kāi)文件(不能修改)
i 按i進(jìn)行編輯
esc + : + wq 保存退出
esc + : + q! 不保存退出

systemctl is-enabled iptables.servicesystemctl is-enabled servicename.service #查詢(xún)服務(wù)是否開(kāi)機(jī)啟動(dòng)
systemctl enable *.service #開(kāi)機(jī)運(yùn)行服務(wù)
systemctl disable *.service #取消開(kāi)機(jī)運(yùn)行
systemctl start *.service #啟動(dòng)服務(wù)
systemctl stop *.service #停止服務(wù)systemctl restart *.service #重啟服務(wù)
systemctl reload *.service #重新加載服務(wù)配置文件
systemctl status *.service #查詢(xún)服務(wù)運(yùn)行狀態(tài)systemctl --failed #顯示啟動(dòng)失敗的服務(wù)
注:*代表某個(gè)服務(wù)的名字,如http的服務(wù)名為httpd
例如在[CentOS](http://www.linuxidc.com/topicnews.aspx?tid=14) 7 上安裝http
[root@CentOS7 ~]# yum -y install httpd啟動(dòng)服務(wù)(等同于service httpd start)systemctl start httpd.service停止服務(wù)(等同于service httpd stop)
systemctl stop httpd.service重啟服務(wù)(等同于service httpd restart)
systemctl restart httpd.service查看服務(wù)是否運(yùn)行(等同于service httpd status)
systemctl status httpd.service開(kāi)機(jī)自啟動(dòng)服務(wù)(等同于chkconfig httpd on)systemctl enable httpd.service開(kāi)機(jī)時(shí)禁用服務(wù)(等同于chkconfig httpd on)
systemctl disable httpd.service查看服務(wù)是否開(kāi)機(jī)啟動(dòng) (等同于chkconfig --list)

參考鏈接

lamp:centos+apache+mysql+php安裝配置方法

Centos7與Fedora24安裝mysql后無(wú)法啟動(dòng),提示 Unit mysql.service failed to load:No such file or directory

CentOS 7 上systemctl 的用法

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 導(dǎo)語(yǔ) 一個(gè) LAMP 軟件棧通常由多個(gè)開(kāi)源軟件組合而成,它們合力驅(qū)動(dòng)一個(gè)服務(wù)器去運(yùn)行 web 站點(diǎn)和應(yīng)用。LAMP...
    xuyan0閱讀 14,878評(píng)論 4 29
  • php+mysql+apache+centos 編譯安裝 領(lǐng)導(dǎo)要求先保證php環(huán)境穩(wěn)定,然后再去考慮其他,例如性能...
    dnaEMx閱讀 2,470評(píng)論 1 16
  • 苔毫窸窣風(fēng)撩撥 竹林遠(yuǎn)上白云頭 道是誰(shuí)家廳做客 張莊門(mén)楣吳郎休 2017-2-2
    姑蘇卿相閱讀 181評(píng)論 0 0
  • 花了近一天的時(shí)間粗讀了高士其的著作《細(xì)菌世界歷險(xiǎn)記》,作者以細(xì)菌的口吻給我們描述出了一個(gè)鮮活的“微型世界”。這里也...
    寫(xiě)下即永恒閱讀 2,318評(píng)論 0 0
  • 月臺(tái)上,擰著大包小包的人們熙來(lái)攘往,或愁緒、或愉悅,或平靜,他們將通過(guò)這狹長(zhǎng)的站臺(tái),駛向家鄉(xiāng)抑或是遠(yuǎn)方。此刻,阿亮...
    寂寞捕手閱讀 705評(píng)論 13 9

友情鏈接更多精彩內(nèi)容