Ubuntu18.04 apache2配置ThinkPHP6


1.修改apache2的配置文件 /etc/apache2/apache2.conf

修改根目錄和AllowOverride權限

<Directory /home/ubuntu/thinkphp/tp6/think/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>

 

2.修改/etc/apache2/sites-available/000-default.conf中的根目錄

 

DocumentRoot /home/ubuntu/thinkphp/tp6/think/public

 

3.修改ThinkPHP public目錄下的.htaccess文件:

<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>

 

4.執行

sudo a2enmod rewrite

 

5.重啟服務

 

sudo service apache2 restart

 

可以這樣訪問了:

http://111.229.200.158/Index/myhello

 

注意,自帶的hello因為路由問題不能http://111.229.200.158/Index/hello這樣訪問

 

如果配置了多站點,如/etc/apache2/sites-available/mysite.conf:

<VirtualHost *:8080>
<Directory /home/ubuntu/xhadmin/public>

AllowOverride All
Options Indexes FollowSymLinks
Require all granted
</Directory>
ServerAdmin webmaster@localhost
DocumentRoot /home/ubuntu/xhadmin/public

 

ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined


</VirtualHost>

則一定要執行:

cd /etc/apache2/sites-available
sudo a2ensite mysite
sudo service apache2 reload


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM