前言
本教程是講述的是從到部署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)
