centOS6.6 部署php項目(詳細過程)

1.安裝mysql

yum install mysql mysql-server
1.1安裝完畢,設置mysql服務 隨系統自啓動:
chkconfig --levels 235 mysqld on
1.2啓動服務
/etc/init.d/mysqld start
1.3設置 mysql 的 root 賬戶的密碼:
mysql_secure_installation

Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n]
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]
直接回車即可。

2.安裝Apache

yum install httpd
2.1安裝完畢,設置Apache 服務 隨系統自啓動:
chkconfig --levels 235 httpd on

服務目錄 /etc/httpd
主配置文件 /etc/httpd/conf/httpd.conf
網站數據目錄 /var/www/html
訪問日誌 /var/log/httpd/access_log
錯誤日誌 /var/log/httpd/error_log

2.2啓動服務
/etc/init.d/httpd start

3.安裝php

yum install php
3.1安裝完畢,需要重新啓動 Apache 服務:
/etc/init.d/httpd start

或者

service httpd restart
3.2 測試環境是否成功

在網站數據目錄 /var/www/html下,新建index.php文件,裏面寫入

<?php
phpinfo();
?>

訪問一下本地127.0.0.1,檢驗環境是否成功。

4.部署php項目注意事項

4.0(補充) 如果測試環境無誤,但是項目訪問不了。看一下是不是項目文件的權限不夠,把權限調整一下!!!
4.1 隱藏訪問路徑中index.php的設置

和入口文件index.php同一個目錄下面的 .haccess文件內容爲

<IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteCond %{REQUEST_FILENAME} !-d
     RewriteCond %{REQUEST_FILENAME} !-f
     RewriteRule ^(.*)$ index.php?s=/$1 [QSA,PT,L]
</IfModule>
4.1.1 centos的配置文件: /etc/httpd/conf/httpd.conf開啓重寫URL設置

LoadModule rewrite_module modules/mod_rewrite.so
將前面"#"去掉,如果不存在則添加上句。

4.1.2.如果你的網站是根目錄的話:

找到

Options FollowSymLinks
AllowOverride None

將上面的None改爲All

4.1.3.如果你的站點不在根目錄,設置如下:

<Directory “/var/www/html/你的項目目錄”>
  Order allow,deny
  Allow from all
  AllowOverride All

然後重啓服務器,service httpd restart ,這樣.htaccess就可以使用了。

4.2 安裝php擴展,例如 gd庫
yum -y install php-gd

安裝結束後,重啓apache,

service httpd restart

同理,參照此種方式安裝項目中需要的擴展。

4.3 導入數據庫
//輸入mysql root用戶密碼
mysql -uroot -p
//創建數據庫
create database 你的數據庫名稱
show databases;
use 你的數據庫名稱;
set names utf8;
//導入數據庫
source 你的數據庫sql文件路徑
//導入完成後
use 你的數據庫名稱;
show tables;
確認導入數據是否有誤。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章