在CentOS上搭建LAMP+vsftpd環(huán)境的簡單指南
VPS 可以看成是一臺(tái)只有你一個(gè)人使用的服務(wù)器(事實(shí)上它是一個(gè)虛擬機(jī)),你可以在上面安裝任何軟件,擁有最大的權(quán)限。正所謂權(quán)限越大,責(zé)任越大,你需要自行安裝 Web 服務(wù)器,數(shù)據(jù)庫,PHP,還有其它一些維護(hù)工作都要自行處理。
現(xiàn)在大多數(shù) VPS 提供的操作系統(tǒng)都是 Linux,而且是沒有圖形界面的的,只提 SSH 命令行接口,所以需要會(huì)一些簡單的 Linux 命令行。Linux 又有眾多的發(fā)行版,最好的發(fā)行版可能是 Redhat,但它是商業(yè)軟件,不能免費(fèi)使用,不過好在它還有一個(gè)社區(qū)版本 CentOS,完全采用 Redhat 的源代碼,去掉 Redhat 的 LOGO,替換成自己的,另外去掉一些閉源軟件,所以系統(tǒng)功能、性能及穩(wěn)定性幾乎等同于 Redhat,就選它了。
安裝 Linux
對(duì)于 Linux 的安裝而言,你可以選擇你所熟悉的發(fā)行版如 Ubuntu、Debian、Fedora 等,服務(wù)商會(huì)以最小化安裝方式默認(rèn)裝好,我選擇的版本是 CentOS 6.3,考慮到 VPS 內(nèi)存較小,安裝的是 32 位版本。
安裝好以后以以 root 用戶登陸上去,并且讓系統(tǒng)進(jìn)行一些必要的更新。Linux 和 Mac 都自帶了 Terminal,如果是 Windows,建議使用 PuTTY 來進(jìn)行 SSH 連接。
#以 root 用戶登陸服務(wù)器 ssh root@198.xxx.xxx.xxx ... #系統(tǒng)更新 yum update ...
安裝 Apache
Apache 是一款 Linux 平臺(tái)上老牌的免費(fèi)開源 Web 服務(wù)器,據(jù)說全世界超過一半的網(wǎng)站都是跑在 Apache 上的。要安裝 Apache,在命令行下輸入以下命令:
yum install httpd
默認(rèn)安裝的 Apache 可能不是最新版,但確是在此 Linux 版本上經(jīng)過測試的最穩(wěn)定版本,如果你一定需要安裝最新版,則需從 Apache 官網(wǎng)上去下載最新版。
安裝好后,執(zhí)行以下命令啟動(dòng) Apache 服務(wù):
service httpd start
默認(rèn)的網(wǎng)頁存放目錄位于/var/www/html/,然后在瀏覽器中訪問 http://198.xxx.xxx.xxx,如果可以出現(xiàn) Apache 的一個(gè)測試頁面,那么說明 Apache 已安裝成功。
安裝 MySQL
MySQL 是一款非常流行的數(shù)據(jù)庫軟件,最初由瑞典 MySQL AB 公司所開發(fā),后被 Sun 公司收購,目前為 Oracle 公司旗下產(chǎn)品,安裝 MySQL 的命令如下:
yum install mysql-server
啟動(dòng) MySQL 服務(wù):
service mysqld start
然后需要為 MySQL 的 root 用戶設(shè)置一個(gè)密碼,可輸入一下命令:
/usr/bin/mysql_secure_installation
執(zhí)行以上命令的話,MySQL 會(huì)要求你提供現(xiàn)在 root 用戶的密碼,因?yàn)槲覀儎倓傃b好,所以密碼是空的,直接回車,然后設(shè)置新的 root 用戶密碼。
緊接著還會(huì)有一些安全選項(xiàng)要你選擇 Y 還是 N。例如,是否移除匿名登陸,是否阻止 root 用戶從遠(yuǎn)程登陸,如果選擇 y ,那么 root 只能以 localhost 方式登陸,另外還有是否移除 test 數(shù)據(jù)庫、立即刷新權(quán)限表等,大概情況如下:
[root@CentOS6 ~]# /usr/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! 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): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MySQL root user without the proper authorisation. Set root password? [Y/n] y New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! 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 a production environment. Remove anonymous users? [Y/n] 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] y ... Success! 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] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MySQL installation should now be secure. Thanks for using MySQL!
安裝 PHP
PHP 是一個(gè)被廣泛使用的開源動(dòng)態(tài)腳本語言,要安裝 PHP,并使其與 MySQL 協(xié)同工作,需執(zhí)行以下命令:
yum install php php-mysql
此時(shí)需要測試 PHP 是否能正常工作,可以建一個(gè)測試頁。
#切換到 Apache 默認(rèn)網(wǎng)頁目錄 cd /var/www/html #創(chuàng)建一個(gè) php 腳本文件 touch phpinfo.php #向文件寫入一小段 php 腳本,測試用 echo '<?php phpinfo(); ?>' > phpinfo.php# 因?yàn)閯倓偘惭b了 PHP,所以別忘了重啟一下 Apache,否則 PHP 不能正常工作
service httpd restart
然后瀏覽器中訪問 http://198.xxx.xxx.xxx/phpinfo.php,看 PHP 是否已經(jīng)正常工作。
如果該頁面能正常顯示服務(wù)器相關(guān)環(huán)境信息,說明 LAMP 環(huán)境已經(jīng)可以正常工作了。
安裝 vsftpd
要安全地上傳文件到服務(wù)器,或者從服務(wù)器上下載文件,最簡便的方式是用 FTP,這里我們選擇 Linux 下非常流行的 “Very Secure FTPD”,即非常安全的 FTP:
yum install vsftpd
安裝好后,還要進(jìn)行一些簡單的配置:
#編輯 vsftpd 配置文件 vi /etc/vsftpd/vsftpd.conf ... #不允許匿名登陸 anonymous_enable=NO #本地賬戶可以登陸 local_enable=YES #可以寫入 write_enable=YES #所有用戶只能訪問其 home 目錄 chroot_local_user=YES ... #重啟 vsftpd 以上設(shè)置才能生效 service vsftpd restart
如何以 FTP 協(xié)議訪問服務(wù)器呢,這里推薦 FileZilla 這個(gè) FTP 客戶端工具,有 Windows 版本、Linux 版本以及 Mac OS 版本。
登陸 vsftpd 一般用 Linux 用戶區(qū)登陸,但是不允許用 root 用戶登陸,所以,需要另外新建一個(gè) Linux 用戶:
#添加用戶 lichao adduser lichao #為 lichao 設(shè)置密碼 passwd lichao #如果出于安全考慮,這個(gè)用戶你只想它能登陸 vsftpd, #而不能以 ssh 方式登陸服務(wù)器,可以禁止其 ssh 登陸 usermod -s /sbin/nologin lichao
至此,就可以用任何 FTP 工具如 FileZilla,以 lichao 這個(gè)用戶及對(duì)應(yīng)的密碼來來登陸 vsftpd 了,默認(rèn)的目錄是 /home/lichao
設(shè)置 Apache、MySQL 和 vsftpd 服務(wù)開機(jī)啟動(dòng)
設(shè)置它們開機(jī)啟動(dòng)的命令如下:
chkconfig httpd on chkconfig mysqld on chkconfig vsftpd on
PHP 會(huì)隨 Apache 一起啟動(dòng)。
至此,一個(gè)基本完整的動(dòng)態(tài)網(wǎng)頁服務(wù)器、數(shù)據(jù)庫服務(wù)器、FTP 服務(wù)器安裝完成。
相關(guān)文章
PHP網(wǎng)站安裝程序制作的原理、步驟、注意事項(xiàng)和示例代碼
其實(shí)PHP程序的安裝原理無非就是將數(shù)據(jù)庫結(jié)構(gòu)和內(nèi)容導(dǎo)入到相應(yīng)的數(shù)據(jù)庫中,從這個(gè)過程中重新配置連接數(shù)據(jù)庫的參數(shù)和文件,為了保證不被別人惡意使用安裝文件,當(dāng)安裝完成后需要修改安裝文件。2010-08-08php基于curl實(shí)現(xiàn)的股票信息查詢類實(shí)例
這篇文章主要介紹了php基于curl實(shí)現(xiàn)的股票信息查詢類,結(jié)合完整實(shí)例形式分析了php使用curl調(diào)用API接口實(shí)現(xiàn)股票信息查詢功能的相關(guān)操作技巧,需要的朋友可以參考下2016-11-11Zend Studio 實(shí)用快捷鍵一覽表(精心整理)
以下是小編精心整理的Zend Studio實(shí)用快捷鍵。很有用哦!需要的朋友可以過來參考下2013-08-08PHP和Selenium搭建高效網(wǎng)絡(luò)爬蟲實(shí)現(xiàn)技術(shù)探索
隨著信息時(shí)代的到來,網(wǎng)站被認(rèn)為是獲取信息的主要途徑之一,但是,手動(dòng)獲取網(wǎng)站上的信息是非常繁瑣的,因此出現(xiàn)了自動(dòng)抓取網(wǎng)頁的方式——網(wǎng)絡(luò)爬蟲,這篇文章將介紹如何使用PHP和Selenium搭建一個(gè)高效的網(wǎng)絡(luò)爬蟲來自動(dòng)收集信息2024-01-01thinkPHP5實(shí)現(xiàn)的查詢數(shù)據(jù)庫并返回json數(shù)據(jù)實(shí)例
這篇文章主要介紹了thinkPHP5實(shí)現(xiàn)的查詢數(shù)據(jù)庫并返回json數(shù)據(jù)功能,結(jié)合實(shí)例形式分析了thinkPHP5數(shù)據(jù)庫查詢及json格式數(shù)據(jù)簡單操作技巧,需要的朋友可以參考下2017-10-10