I always use the following way when setting up a new project when I am working in the office where we have ubuntu
and it always works perfectly.
Follow these steps below, and create 2 virtual hosts with the name www.myapp.com
and admin.myapp.com
1) Open terminal and type
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/www.myapp.com.conf
.
sudo nano /etc/apache2/sites-available/www.myapp.com.conf
.
add the following code once the file opens.
<VirtualHost *:80>
ServerName www.myapp.com
DocumentRoot "/path/to/project/root/frontend/web"
<Directory "/path/to/project/root/frontend/web">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# use index.php as index file
DirectoryIndex index.php
# ...other settings...
</Directory>
</VirtualHost>
2) Close & save the file and then in terminal write
sudo a2ensite www.myapp.com.conf
- open hosts file
sudo nano /etc/hosts
and add in the end on a new line 127.0.0.1 www.myapp.com
.
- Restart apache
sudo service apache2 restart
3) Repeat the above steps for the backend
and change the file names and ServerName
, Directory
and DirectoryRoot
respectively.
4) Just make sure you have a .htaccess
file in the frontend/web
and backend/web
with the following
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
And thats it you wont need any other .htaccess
file other than these now type in the browser www.myapp.com
or admin.myapp.com
and see it working.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…