Ubuntu下安裝Apache及網站基本配置+CI框架基本配置

 

公司官網是外包給其他公司,公司組織架構變化後服務器不能再使用,需要在新服務器上進行安裝配置官網,於是我這個完全不懂PHP的就光榮接手此任務。

手上只有網站代碼,原有服務器不能訪問,所以從網上找了些內容,但每一個都有這樣那樣的一點點問題。於是把自己的配置過程記錄下來。

1.安裝apache2

sudo apt-get install apache2

 

2.安裝php

sudo apt-get install libapache2-mod-php5

sudo apt-get install php5

 

3.安裝sql服務器

sudo apt-get install mysql-server

sudo apt-get install php5-mysql

 

5.修改web目錄權限

chown -R www-data:www-data /var/www

 

6.在/var/www新建目錄example,並將網站內容全部放到此目錄

 

7.在/etc/apache2/sites-available/目錄下建立文件example.conf,內容如下:

<VirtualHost *:80>

ServerAdmin webmaster@localhost

   RewriteEngine On

   RewriteOptions Inherit

   DocumentRoot /var/www/example

   <Directory />

       Options FollowSymLinks

       AllowOverride None

   </Directory>

   <Directory /var/www/example>

       Options Indexes FollowSymLinks MultiViews

        AllowOverride All

       Order allow,deny

       allow from all

   </Directory>

         ErrorLog${APACHE_LOG_DIR}/error.log

         CustomLog${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

 

8.建立配置文件軟鏈接並刪除默認有效配置():

sudo ln -s /etc/apache2/sites-available/example.conf/etc/apache2/sites-enabled/example.conf

sudo rm /etc/apache2/sites-enabled/000-default.conf(刪除目錄sites- enabled下任何所有非example.conf的其他文件)

9. 使apache支持 rewrite 模塊(去掉index.php針對CI模塊鏈接中必有index.php的問題)

sudo ln -s/etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load

10. 添加 rewrite 規則 (網站根目錄的 .htaccess 文件)

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond $1 !^(index\.php|images|robots\.txt)

RewriteRule ^(.*)$ /index.php/$1 [L]

 

11.重啓apache

sudo /etc/init.d/apache2 restart

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章