Configuring Symfony 5 Application on Apache server - php

I need some help with configuring Symfony on apache2 web server.
My current project category structure is:
var/www/domain.com/public_html
Inside public_html is where my Symfony application is located.
I am stuck at figuring our what I am doing wrong in my either .htaccess or /etc/apache2/sites-available/domain.com.conf files.
I am using symfony/apache-pack. My .htaccess files live inside /public folder as per documentation. Here it is:
DirectoryIndex index.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 307 ^/$ /index.php/
</IfModule>
</IfModule>
And here is my /etc/apache2/sites-available/domain.com.conf
<VirtualHost *:80>
ServerAdmin someemail#example.com
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/mydomain.com/public_html/public
<Directory /var/www/mydomain.com/public_html/public>
AllowOverride All
Order allow,deny
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.mydomain.com [OR]
RewriteCond %{SERVER_NAME} =mydomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I also read this and updated 000-default.conf as follows:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerAlias www.mydomain.com
DocumentRoot /var/www/mydomain.com/public_html/public
<Directory /var/www/domain.com/public_html/public>
Options FollowSymlinks MultiViews
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml >
</IfModule>
</VirtualHost>
For the moment I am still seeing symfony project folder structure.
I tried:
inside .htaccess changing DirectoryIndex to /public/index.php
inside .conf file changin DocumentRoot to /va/www/domain.com/public_html/public
tried clearing cache
SO far nothings seems to help.
Would be extremely helpful for any advice.

I see that you are editing vhost which begins with
<VirtualHost *:80>......
That mean your website should be reachable by 80 port or in other words by http protocol. But! If in reality you are accessing your website by https protocol then make sure you are editing right Apache2 .conf file.
If the website is reachable by https protocol (especially if you use LetEncrypt), then try locating /etc/apache2/sites-available/....-le-ssl.conf config file (or similar one with corresponding domain title and with ssl prefix or postfix in it's name).
After editing that file do not forget to restart Apache2 webserver with $sudo service apache2 restart and test website again.

Related

Hot to setup 2 different wordpress project with same domain on AWS Linux

currently i want to setup 2 different Wordpress project on my AWS Linux 2. but i still want to use a same domain. but i stuck.
1st Wordpress project use domain http://domainname.com
2nd wordpress project use domain http://domainname.com/second
what i have done is like this
1st Wordpress project
i set the .htaccess with this.. this setting is avoid 404 page when access http://domainname.com/second
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !^/second/.*$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./ /index.php [L]
</IfModule>
i also create a file "domainname.conf" on folder "/etc/httpd/conf.d/" with this setting
<VirtualHost *:80>
ServerName domainname.com
ServerAdmin email#gmail.com
DocumentRoot "/var/php_apps/domainname"
<Directory "/var/php_apps/domainname">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
ErrorLog /var/log/apache2/bar.error.log
LogLevel warn
CustomLog /var/log/apache2/bar.access.log combined
</VirtualHost>
this setting can load the page corretly. but i still can't display the 2nd wordpress project.. here is my setting
2nd Wordpress project
i set the .htaccess file with this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
i create a file "second.conf" on folder "/etc/httpd/conf.d/" with this setting
<VirtualHost *:80>
ServerName domainname.com/second
ServerAdmin email#gmail.com
DocumentRoot "/var/php_apps/second"
<Directory "/var/php_apps/second">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
Require all granted
</Directory>
ErrorLog /var/log/apache2/bar.error.log
LogLevel warn
CustomLog /var/log/apache2/bar.access.log combined
</VirtualHost>
but the 2nd wordpress project can't load the page when access domain http://domainname.com/second
error display
Not Found
The requested URL was not found on this server.
how do i able load the page from 2nd wordpress project when access domain http://domainname.com/second ?
please help.

Wordpress paramlinks change from plain to post name resulting in 404 not found

Hello I have a WordPress site and I changed the paramlinks from plain to post name. All my posts are showing 404 not found. I tried to check all possible causes but I could not find why it is not working.
My .htaccess is as below:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Apache mode rewrite is enabled, the command a2enmod rewrite gives:
Module rewrite already enabled
PHP info shows mod_rewrite in Loaded Modules.
My vhost is as following:
<VirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com
ServerAdmin webmaster#mysite.com
DocumentRoot /var/www/mysite/public_html
ErrorLog /var/www/mysite/logs/error.log
CustomLog /var/www/mysite/logs/access.log combined
<Directory "/var/www/mysite/public_html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Any help on this please? Thanks.

setting .htaccess file in slim

I am having issues redirecting to index.php in my slim app with .htaccess file.
Routes work if I add the index.php at the end of the URL
So slimapp.dev/hello/myname gets error
Not Found The requested URL /hello/myname was not found on this server.
while slimapp.dev/index.php/hello/myname works
Here is my .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^index.php [QSA,L]
I am using Apache 2 on Ubuntu 18.04
File structure
public_html
|_index.php
|_ vendor
|_.htaccess
virtualHost 000-default.conf
<VirtualHost *:80>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
If I use the php -S localhost:3000 it works as expected but if I use the Apache web server, I most add the index.php to the end of the URL to make it work. Thanks
You are doing wrong.This is quite simple with just two lines of code:
RewriteEngine On
RewriteRule ^myname/(.*)$ /$1 [L]

Symfony 4 deployement's rooting on apache

So I have my symfony 4 app and I have to deploy it on a private server.
My private server (on debian) has already a website in var/www/html/ accessible by 'url.com' My etc/hosts file look like this:
127.0.0.1 localhost
xxx.xx.xx.xx url.com url
I would like my symfony app to be accessible whether by 'app.url.com' or url.com/app.
I tried setting up a vhost and adding my new url to the hosts file by adding a line like this one : xxx.xx.xx.xx app.url.com.
I also tried different VHost conf file but none worked, so I must miss something.
EDIT:
<VirtualHost *:80>
ServerName app.fr
ServerAlias www.app.fr
DocumentRoot "/var/www/html/app/public"
ErrorLog ${APACHE_LOG_DIR}/app-error.log
CustomLog ${APACHE_LOG_DIR}/app-access.log common
<Directory "/var/www/html/app/public">
AllowOverride None
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =app.fr
RewriteRule ^ http://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

Re-setting up working project on local machine

I'm working on a symfony 1.4 project which is working, i wanted to work on a local copy on my personal machine; so I've settled a virtual host (I'm on a Windows 8.1 with xamppp web server).
I'm getting a 500 error when trying to access from browser by giving "joyaa" (it's the virtualhost alias), and in some of my test I had a redirect to the project working on the server (it's a statement in .htaccess)
This is the virtual host defining:
<VirtualHost *:80>
ServerName joyaa
DocumentRoot "C:/xampp/htdocs/yaol/web"
DirectoryIndex index.php
<Directory "C:/xampp/htdocs/yaol/web">
AllowOverride All
Allow from All
</Directory>
Alias /sf C:/xampp/htdocs/yaol/lib/vendor/symfony/data/web/sf
<Directory "C:/xampp/htdocs/yaol/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
Alias /joyaa "C:/xampp/htdocs/yaol/web"
<Directory "C:/xampp/htdocs/yaol/">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
and this is the .htaccess defining:
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /joyaa
RewriteRule ^yaol(.*)$ http://www.arcadja.com/joyaa$1 [L,R=301]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Probably it's a configuration problem but I'm not sure about where to look at... Please help. Thanks

Categories