http://www.2cto.com/os/201505/401588.html
Ubuntu+Apache+PHP+Mysql環境搭建(完整版)
一、操作系統
Ubuntu 14.04 64位,阿里雲服務器
二、Apache
1、安裝Apache,安裝命令:sudo apt-get install apache2
2、環境配置:
1)配置文件:路徑為/etc/apache2,配置文件是apache2.conf,而沒有http.conf。
2)默認網站根目錄:/var/www/html,使用瀏覽器訪問http://localhost 即可打開;
3)修改網站根目錄:
A、“sudo vim /etc/apache2/apache2.conf"-->找到""的位置-->更改"/var/www/"為新的根目錄“/home/www”即可
B、"sudo vi/etc/apache2/sites-available/000-default.conf"-->找到"DocumentRoot /var/www/html"的位置-->更改"/var/www/html"為新的根目錄“/home/www”即可。
4)重啟Apache服務器: sudo /etc/init.d/apache2 restart
三、PHP
1、更新源列表,否則安裝php會失敗:
命令行輸入: vim /etc/apt/source.list
在最前面添加以下內容:
deb http://mirrors.aliyun.com/ubuntu/ precise main restricteduniverse multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-security mainrestricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-updates mainrestricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-proposed mainrestricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ precise-backports mainrestricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise mainrestricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-securitymain restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-updatesmain restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-proposedmain restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ precise-backportsmain restricted universe multiverse
********************************************************************************
源的版本2
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
apt-get update //更新一下列表
2、安裝PHP,安裝命令:sudoapt-get install php5
3、讓Apache支持php,安裝命令:sudo apt-get install libapache2-mod-php5
4、安裝php5-gd模塊,安裝命令:sudoapt-get install php5-gd
5、讓PHP支持curl
1)首先查看php5-curl是否已安裝:dpkg -l | grep 'php5-curl'
2)如果沒有安裝,則:apt-get install php5-curl
3)確保 extension_dir存在,並且包含curl.so,
查找extension_dir:php -i | grep extension_dir
4)確保 /etc/php5/mods-available/curl.ini存在,文件內容如下:
; configuration for php CURL module
; priority=20
extension=curl.so
PDO已是PHP的核心,無需再安裝。
只需安裝php5的mysql數據庫擴展php5-mysql:
sudo apt-get install php5-mysql
這樣就可以使用PDO了,不需要修改php.ini。需要重啟服務器。
5)如果以上步驟均確定,重啟服務器。
四、Mysql
1、安裝Mysql,安裝命令:sudoapt-get install mysql-server,安裝過程中設置密碼
2、允許root遠程登錄:
1)從所有主機:grant all privileges on *.* to root@"%" identified by "passw0rd" with grant option;
2)can't connect to mysql server解決方法:修改配置文件,路徑為/etc/mysql/my.cnf,注釋掉bind-address = 127.0.0.0
即:#bind-address = 127.0.0.1
五、FTP
1、安裝FTP,安裝命令:sudoapt-get install vsftpd
2、查看是否安裝成功:輸入"sudo service vsftpdrestart"重啟vsftpd服務
3、建立FTP目錄: sudo mkdir/home/ftpfile/ftpfile
4、新建ftp用戶: sudouseradd –d /home/ftpfile –s /bin/bash myftp
5、設置myftp用戶密碼: sudopasswd myftp ,輸入兩次密碼
6、修改ftp配置文件,路徑為/etc/vsftpd.conf,
1)配置修改如下:
anonymous_enable=NO
local_enable=YES
write_enable=YES
chroot_local_user=YES
chroot_list_enable=YES
chroot_list_file=/etc/vsftpd.chroot_list
2)在/etc/目錄中新建vsftpd.chroot_list文件,添加ftp用戶名:myftp。或直接:
echo “myftp” >> /etc/vsftpd.chroot_list 即可。
六、SVN
1、安裝SVN,安裝命令:sudo apt-get install subversion
2、創建SVN工程:sudo svnadmin create /home/svn/kyssp
3、修改svn配置: vim /home/svn/kyssp_pub/conf/svnserve.conf
anon-access = read
auth-access = write
password-db = passwd
4、設置訪問用戶以及密碼: 編輯文件vim /home/svn/kyssp_pub/conf/passwd
在最后一行添加:用戶名 = 密碼
5、啟動svn:svnserve -d-r /home/svn/
6、使用SVN的post-commithooks 同步推送代碼到生產環境
1)進入/home/svn/kyssp/hooks目錄,cp post-commit.tmpl post-commit
2)在最后,添加如下:
REPOS="$1" REV="$2" #TXN_NAME="$3" WEB_PATH="/home/www/kyssp" #"$REPOS"/hooks/mailer.py commit "$REPOS"$REV "$REPOS"/mailer.conf #export LANG=zh_CN.UTF-8 export LANG=en_US.UTF-8 # #svn co --username zrs --password zrs@tzuo.cnsvn://112.74.**.**/kyssp_pub /home/www/kyssp svn update --username zrs --password zrs@tzuo.cn /home/www/kyssp 其中: svn co --username zrs --password zrs@tzuo.cnsvn://112.74.**.**/kyssp /home/software/www/kyssp 下載工程代碼 svn update --username z** --password z*** /home/software/www/kyssp 更新工程代碼