天天看點

阿裡雲ECS伺服器Linux環境下配置php運作環境(安裝配置篇)

阿裡雲ECS伺服器Linux環境安裝配置php的運作環境,不同于window作業系統下配置,因為是linux作業系統主要是在指令窗體裡輸入指令來操作,對于初次接觸過linux系統的可能會有點怕怕的,下不去手。。。。。。

需要安裝的軟體有Apache+PHP+MySQL。

安裝Apache

yum install httpd #根據提示,輸入Y安裝即可成功安裝

安裝成功後開啟Apache,

/etc/init.d/httpd start #啟動Apache

Apache啟動之後可能會提示錯誤:

httpd:httpd: Could not reliably determine the server's fully qualif domain name, using ::1 for ServerName

解決方法:

vi /etc/httpd/conf/httpd.conf  #編輯http.conf檔案

查找到 #ServerName www.example.com:80

按“i”鍵代表修改文檔

修改為 ServerName localhost:80 #這裡設定為你自己的域名,如果沒有域名,可以設定為localhost

阿裡雲ECS伺服器Linux環境下配置php運作環境(安裝配置篇)

按“Esc”鍵退出,然後再按“:wq”#儲存退出

chkconfig httpd on #設為開機啟動

/etc/init.d/httpd restart #重新開機Apache伺服器

(如果不是很确定在指令窗體能夠修改,可以下載下傳一個WinSCP連接配接伺服器後按 /etc/httpd/conf/httpd.conf這個路徑查找修改,代碼大概在278行,在修改之前把檔案格式先轉換為utf-8編碼,或者先将httpd.conf 檔案備份,防止改錯了可以替換回去!!)

第一步已經完成了,哈哈哈哈!

阿裡雲ECS伺服器Linux環境下配置php運作環境(安裝配置篇)

安裝MySQL

yum install mysql mysql-server #根據提示,輸入Y安裝即可成功安裝

/etc/init.d/mysqld start #啟動MySQL服務

chkconfig mysqld on #設定為開機啟動

cp  /usr/share/mysql/my-medium.cnf  /etc/my.cnf  #拷貝配置檔案

接下來就是為mysql的root賬号設定密碼(預設的密碼是空)

mysql_secure_installation 按Enter鍵

如果你是新安裝mysql,會彈出提示:

In order to log into MySQL to secure it, we'll need the current password for the root user. If you've just installed MySQL, 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):

因為你是新安裝,預設密碼為空,直接按enter鍵就可以。

然後設定新的密碼,輸入Y即可

輸入兩次密碼确認(一定要記住密碼哦!後面設定其他使用者還需要用的密碼進入MySQL,建立使用者等操作)

再接着就是會有若幹個提示:

By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL 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 aproduction environment.

Remove anonymous users? [Y/n] y

MySQL會預設建立一個匿名使用者,問你是否删除,一般輸入Y删除掉。

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] y

root使用者預設隻能通路localhost,以防有人猜密碼,是否禁止root登陸,一般選擇yes。

By default, MySQL 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]

mysql預設建立一個名為test的資料庫,這個庫任何人都可以通路,是否删除掉,一般不删除。

Reloading the privilege tables will ensure that all changes made so far will take effect immediately.

Reload privilege tables now? [Y/n]

意思是上面的修改是否馬上生效:輸入Y

最後會出現:Thanks for using MySQL!

MySQL密碼設定完成,重新啟動MySQL:

/etc/init.d/mysqld restart #重新開機MySQL服務

安裝php

yum install php #根據提示,輸入Y安裝即可成功安裝

安裝php元件,讓php5 支援 mysql

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 #根據提示,輸入Y安裝即可成功安裝

/etc/init.d/mysqld restart #重新開機mysql

/etc/init.d/httpd restart #重新開機Apache

終于完成了所有軟體的安裝,現在進行測試一下

安裝完成之後在/var/www/ 會有一個html檔案夾,這個就是預設的通路路徑。

編寫一個index.php 檔案進行測試

<?php

echo "hello world";

?>

!!!!!!!!!!!!!!!

如果前面的三個安裝步驟都成功,而在測試的時候出現通路不了的問題,有可能是因為阿裡雲ECS伺服器裡面的安全組設定問題;

解決方法,在雲ECS伺服器裡添加安全組規則;

這裡要登入阿裡雲的控制台--

https://www.aliyun.com/

選擇雲伺服器ECS->安全組,找到你的伺服器在哪個區,選擇配置規則->添加安全組規則

阿裡雲ECS伺服器Linux環境下配置php運作環境(安裝配置篇)
阿裡雲ECS伺服器Linux環境下配置php運作環境(安裝配置篇)