I have a symfony project with a lot of requests and users, so I decided to use nginx + php-fpm to get a bit more performance.
But my client wants to have plesk for server administration. So, I installed everything whats required (nginx, fpm, apache) and created the host instance in plesk. Now, the start page of the website works fine - but some child pages gives me a 404 error code directly from nginx, other child pages works.
All urls are rewritten (symfony default). I only renamed the symfony default index file of the web folder app.php to index.php.
My additional configuration in plesk is: nothing
edit: I use nginx 1.9.4 (delivered with ubuntu or plesk) and symfony 2.8
Try to add a following lines in "Apache & Nginx settings" > "Additional nginx directives" to your domain in Plesk:
if (!-f $request_filename) {
rewrite ^/(.*)$ /index.php last;
}
Related
I'll try to be short as it can get bloated.
I set up an ubuntu server 20.04 VM on an Oracle vbox.
I installed nginx, php7.4, Xdebug 3.
I configured everything properly for remote debugging and sftp ( I use PHPstorm), I forwarded the ports and customized my local hosts file.Everything works except...
when loading HTTP://127.0.0.2 it loads the default nginx landing page.My index.php file is uploaded in the root /var/www/my_domain folder through sftp. I created the server block for my_domain.
Still won't work. I am new to this so I am missing something.
If you need more info please request.
Any help appreciated!
Vhost config ( server block in nginx) - php-projects being my current domain and containing index.php:
server {
listen 80;
listen [::]:80 ipv6only=on;
root /var/www/php-projects;
server_name php-projects www.php-projects;
location / {
try_files $uri $uri/ =404;
}
error_log /var/log/nginx/debug.log debug;
}
Network settings from Vbox:
PS. I have tried :
How to set index.html as root file in Nginx?
and
Rewrite rule for the root file in nginx?
with no success.
"I configured everything properly for remote debugging and sftp"
Please post your xdebug configuration.
"when loading HTTP://127.0.0.2"
From where ? Host machine or VM?
"My index.php file is uploaded in the root /var/www/my_domain folder
through sftp."
Please post your nginx vhost configuration
"I created the server block for my_domain"
Where? Post the path to the file where you have done this
I am trying to migrated my application in ebs because it was deprecated, my previous platform was:
PHP 5.6 running on 64bit Amazon Linux / 2.9.8
now i'm migrating to:
PHP 7.4 running on 64bit Amazon Linux 2 / 3.0.3
This platform uses the Nginx server instead of Apache.
I was able to deploy my application but the problem is that my .htaccess configuration file was deprecated as was my .ebextensions configuration file. so I have lost the settings I had for example to get clean urls and redirects from http to https.
I have tried to transform the apache configurations to Nginx by putting the respective configuration file but apparently they have no effect.
I have tried many test configurations and I have come to the conclusion that the platform is not reading the configurations that I put.
I have tried to try for example with this little configuration, which should allow me to list the "views" directory:
cleanurl.config
server {
location / views / {
autoindex on;
}
}
I have tried putting it in the following folders.
".ebextensions / cleanurl.config"
files:
"/etc/nginx/conf.d/cleanurl.conf":
mode: "000644"
owner: root
group: root
content: |
server {
location / views / {
autoindex on;
}
}
".platform / nginx / conf.d / cleanurl.config"
server {
location / views / {
autoindex on;
}
}
But I don't get results. I always get 403 Forbidden when I point to a folder. Please help.
Thanks in advance
After trying and trying I was able to solve it in the following way:
I put the file in this location
.platform/nginx/conf.d/elasticbeanstalk/cleanurl.conf
change my config file like this
location/views/ {
autoindex on;
}
and now everything works.
I have tried many test configurations and I have come to the conclusion that the platform is not reading the configurations that I put.
In the first case this is because the configuration files that you use are for Amazon Linux 1 (AL1). However, you environment is PHP 7.4 running on 64bit Amazon Linux 2 (AL2).
In your second attempt, you are using the config files in .platform/nginx/conf.d/ as you should. However, you are using *.config extension. This wrong extension and it should be:
cleanurl.conf
You still may have other issues, but the wrong extension could explain why the files are being ignored.
I have created a PHP website on azure using app services. I use continuous deployment through bitbucket. I need to point the website to public folder in my code to run the app as it is built with zend framework.
After some search, was not able to find how to change the folder where the server points for default directory.
Go to Azure Web apps settings -> Application Settings -> Virtual Applications and directories and setup the physical path of the new folder. Also check the Application checkbox.
Restart the web app once.
There are a few scenarios possible:
You run a Windows App Service
You run a Linux App Service with PHP 7.4 or less
You run a Linux App Service with PHP 8
In the first scenario (Windows App Service) you can go to the App Service > Settings > Configuration blade you need to select the tab "Path Mappings" where you can set the Virtual Applications paths as follows: "/" maps to "site\wwwroot\public".
In the second scenario you can use the .htaccess solution described by #Ed Greenberg, even though for Zend Framework I suggest to use the following settings:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]
For the third scenario you have a bit more of a challenge since Apache was replaced by Nginx and the rewrite rules no longer apply. Please see my detailed blog article "PHP 8 on Azure App Service" on how to solve this and other challenges with the new Azure App Service for PHP 8.
Good luck and let me know if it solved your problem.
For PHP 8.0 with nginx I use startup.sh script placed in the root directory of the project. startup.sh contains the following line:
sed -i 's/\/home\/site\/wwwroot/\/home\/site\/wwwroot\/public/g' /etc/nginx/sites-available/default && service nginx reload
You need to add "startup.sh" as Startup Command in General Settings. Now "public" dir is your root directory.
The correct answer in 2021 (for Laravel, and probably other frameworks with a /public directory) is to put an extra .htaccess in the webroot directory.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Credit to Azure Web App - Linux/Laravel : Point domain to folder
Finally I've found Laravel documentation how to make it work with Azure. To be more precise - PHP8 + NGINX. Here is the article link - https://azureossd.github.io/2022/04/22/PHP-Laravel-deploy-on-App-Service-Linux-copy/index.html
Hope it will be useful :-)
PHP 8 (NGINX)
PHP 8 on Azure App Service Linux use NGINX as the Web Server. To have NGINX route requests to /public we’ll have to configure a custom startup script. We can grab the existing default.conf under /etc/nginx/sites-available/default.conf and run cp /etc/nginx/sites-available/default.conf /home. This will copy the default.conf we need into /home so we can download it with an FTP client or any other tool that allows this.
This default.conf has the following line:
root /home/site/wwwroot;
We need to change it to the following:
root /home/site/wwwroot/public;
Next, under the location block we need to change it from:
location / {
index index.php index.html index.htm hostingstart.html;
}
to the following:
location / {
index index.php index.html index.htm hostingstart.html;
try_files $uri $uri/ /index.php?$args;
}
Now configure your actual startup.sh bash script. Note, the file name is arbitrary as long as it is a Bash (.sh) script. Configure the file along the lines of the below:
#!/bin/bash
echo "Copying custom default.conf over to /etc/nginx/sites-available/default.conf"
NGINX_CONF=/home/default.conf
if [ -f "$NGINX_CONF" ]; then
cp /home/default.conf /etc/nginx/sites-available/default
service nginx reload
else
echo "File does not exist, skipping cp."
fi
NOTE: $query_string can be used as well. See the official documentation here.
Our custom default.conf should look like the below:
server {
#proxy_cache cache;
#proxy_cache_valid 200 1s;
listen 8080;
listen [::]:8080;
root /home/site/wwwroot/public;
index index.php index.html index.htm;
server_name example.com www.example.com;
location / {
index index.php index.html index.htm hostingstart.html;
try_files $uri $uri/ /index.php?$args;
}
........
.....
...all the other default directives that were in this file originally...
}
Use an FTP client to upload both your startup.sh script and your custom default.sh to the /home directory for your PHP App Service.
Next, under ‘Configuration’ in the portal target /home/startup.sh (or whatever the startup script file name is).
Laravel App
Lastly, restart the App Service. This should now be using our custom startup script. Use LogStream or the Diagnose and Solve -> Application Logs detector, or other methods, to see the stdout from the script.
I have created a fresh Laravel application by using composer create-project command. Then I put all the folders and files in /usr/share/nginx/html/, which is the default document root for my nginx server. However everytime I runs the http://localhost, it keeps displaying 403 Forbiden. I tried creating a testing index.php (<? php_info();) and it worked fine.
I've read somewhere that I need to set the containing folder (/html), as well as the app/storage folder permission to 777 but still no luck.
Please help me. Thank you in advance.
Here is the nginx default.conf
Laravel projects serve from the <projectName>/public directory. Make sure your nginx config is set up to look there for your index file and NOT in your <projectName> folder only.
Would you edit your question and paste your server config there?
I think it may because index.php is not in the index file list. check these lines:
index index.html index.php;
or
try_files $uri $uri/ =404;
The accepted answer is correct - Laravel services from the public folder and you need to tell nginx to look there - but also a little vague if you're bumping up against this problem. When you create new sites on a Homestead installation by adding them to your .yaml file and using vagrant provision or vagrant up --provision, the created nginx conf file will need editing before Laravel will serve files correctly.
Go to your CLI, and enter Homestead using vagrant ssh or homestead ssh. It will ask for your password, which by default is "vagrant".
Once you're in the virtual machine, type the following commands:
sudo nano /etc/nginx/sites-enabled/your-site-name-here
Then add /public to the end of the existing root near the top of the file (it'll be something like /home/vagrant/projects/your-site to begin with and save in Nano (ctrl+s), then exit nano (ctrl+x).
Once you've exited Nano, restart nginx using sudo nginx -s reload. Your routing will now work!
This is my problem:
- I downloaded and installed XAMPP;
- I changed the listen port from 80 to 100 (to not interfere with Skype);
- in browser i typed: localhost:127.0.0.1:100
WAMPP page appears. So far so good. I opened NetBeans and tried to run a PHP application and I got Error 404.
Apache service is running (at least XAMPP reports soand the Apache icon is showing).
I use Win 7 on laptop, 64 b.
So, what can I do to successfully run the application.
Tank you,
Eugen
Do you have
Listen 81
in \xampp\apache\conf\httpd.conf ?
Or do you have the vhosts properly configured?
<VirtualHost *:100>
....
Do you have mod_rewrite enabled in httpd.conf?
LoadModule rewrite_module modules/mod_rewrite.so