How to connect php-fpm with nginx? - php

I have a server that uses Nginx and PHP-FPM. It was working as well, I executed the following command for some reasons:
apt-get --purge remove php-common
After that, I executed this:
apt-get install php-common php-mysql php-cli
Commands executed successfully, but I get 502 error when I want to access websites on the servers:
It should be noted, there are several projects on this server. And I have nothing inside /etc/nginx/sites-available. I have all configurations under /etc/nginx/conf.d. See:
Each of them is a project. Now, I guess I need to set to PHP-FPM to use conf.d instead of sites-available. Any idea how can I do that?
Could you please help me how can I debug it?

Related

Why does my website loads infinitely after I tried the sleep method?

So I was playing with the sleep method of php. I coded sleep(99999); Now my website won't load lol. Is it because of that? How can I fix it?
I think you can just restart apache, or php-fpm if you are using php-fpm. And why in the world would you try that!
You must restart your server if restarting your web server didn't work. Or, it will just be stuck in a delay until the sleep time ends.
I would advise you not to play with a production server. Use a test server for these tests. Because it is not as easy to reset these issues.
For example, when you are using shared hosting, you cannot restart apache yourself.
How do I setup a test server:
Install some software like XAMPP if you are using Windows in your home PC. Or, if you are using Linux, you can just install apache and php using the following commands on:
Ubuntu/Debian: sudo apt install apache2 php
CentOS/Fedora: sudo yum install epel-release, and sudo yum install httpd php or sudo dnf install httpd php
Arch Linux/Manjaro: sudo pacman -S apache php php-apache

Apache2 cannot open .php files

I installed lamp long time ago and was able to execute php files. However, recently I tried to install cakePHP and ran into trouble (restarting apache started to generate errors). Thus I purged apache2 from my system. I reinstalled apache2 using command "apt-get install apache2" but after doing so it could no longer open .php files, shows a blank page instead. I've set the necessary permissions (given -R 777 to /etc and /var/www). I've also ran the command "apt-get install php7.0 libapache2-mod-php7.0" and restarted apache several times, nothing works. Can anyone help?
PS: I was originally trying to run phpmyadmin, before purging I was able to run it but after reinstalling it threw errors, thence I discovered my server was not able to execute any php file.
Additionally, when I access the file (home.php) via localhost/home.php it shows a blank page but if follow the path file:///var/www/html/home.php it brings a pop up that asks me to either save or open the script.
I think problem is the apache-php-mod is not well installed,I suggest you purge remove all apache and php package,then reinstall them.
sudo apt-get purge apache2
sudo apt-get purge php
sudo apt-get autoremove
Then,find all apache2 or php files, and remove them,you can do it by using find command,be carefully when do this!
sudo find / -name apache2
At last,you can reinstall them

Phpmyadmin-error on nginx VPS with Ubuntu 12.04.3 x32

I am trying to install phpmyadmin on a VPS LEMP-stack.
I created an info.php, which is perfectly reachable when I call my server's IP in my browser, revealing all relevant php-info, i.e. nginx is running.
However, after installing phpmyadmin, which I try to access via http://192.xxx.xxx.x/phpmyadmin/, I get the following error message:
The mysqli extension is missing. Please check your PHP configuration.
I already installed php5-mysql via sudo apt-get install php5-mysql, restarted nginx and cleared my browser-cache, but the situation remains.
Could you please advice me what goes wrong?
mysql and mysqli are two different things.
You have to install the mysqli library:
sudo apt-get install php5-mysqli
Don't forget to also restart the php fpm workers, because that's where the mods get loaded, not in nginx.
/etc/init.d/php5-fpm restart
Update:
I was wrong, the php5-mysql package contains the mysql AND the mysqli library.
It must be enough for you to restart the php workers :-)

How to install PHP extensions on nginx?

I recently discovered NginX, and decided to try it out on my server. I have NginX running and able to serve PHP and HTML files. But now I want to try to install drupal. When trying to install it and check the requirements, I am stopped by one requirement.
PHP extensions Disabled
Drupal requires you to enable the PHP extensions in the following list (see the system requirements page for more information):
gd
I have tried to install gd by doing apt-get install php5-gd, and it says it is already installed. So I created a phpinfo() file, and checked to see if gd was enabled and I wasn't able to find it. Does this have to do with NginX or PHP? What do I do to fix this?
Since you are using Nginx - that must mean you are running PHP with PHP-FPM.
After you install stuff you need to:
sudo /etc/init.d/php-fpm restart
or
service php5-fpm restart
in newer ubuntu versions
so that PHP will pickup the new extensions.
If your web server setup is in order, only install the php gd extension and restart php scripting interpreter and web server.
sudo apt-get install php5-gd
sudo /etc/init.d/php-fastcgi stop
sudo /etc/init.d/php-fastcgi start
sudo /etc/init.d/nginx stop
sudo /etc/init.d/nginx start
Here's a great LEMP tutorial http://library.linode.com/web-servers/nginx/php-fastcgi/ubuntu-10.04-lucid
For future me if I forget this.
If you've been messing around with /etc/php/fpm then you may have accidentally lost the symlink to conf.d which means the gd and PDO load files won't be booted with FPM.
This will be an issue if you're just using the basic config that comes with PHP5-FPM. If you have a custom config you may included the files in a different place.
Solution: Recreate the sym-link.
cd /etc/php5/fpm
sudo ln -s /etc/php5/conf.d /etc/php5/fpm/conf.d
PHP extensions have only to do with PHP. Your choice of webserver (apache, nginx, etc) do not affect them. Most likely you just need to enable the gd extension. If you are on Ubuntu, check /etc/php5/conf.d folder and add a gd.ini with the following line:
extension=gd.so
if you are using centos 7 and you can't find /etc/init.d/php-fpm, you may try systemctl restart php-fpm, that worked for me.
I encountered the same problem with making sudo apt-get install php5-gd to work. Console output suggested to do sudo apt-get update. Just basic updating on all your packages.
After updating, I run sudo apt-get instal php5-gd and it did all heavy lifting for me, including restarting php5-fpm and correctly installing everything in between.

How can I run things off Netbeans on Ubuntu? Localhost not working

When I try to run something on Netbeans using Ubuntu, a window opens but nothing actually works. I'm pretty sure it's because my http://localhost/ isn't working. So, how do I get that to work so I run files on Netbeans? Any specific step-by-step instructions would be great. I heard I had to install Apache, but I'm not sure.
If you want to run PHP stuff outside NetBeans, there are several steps you have to take:
Install apache web server - sudo apt-get install apache2
Install PHP and connect it with apache - sudo apt-get install php5 sudo apt-get install libapache2-mod-php5
Restart apache - sudo /etc/init.d/apache2 restart
Now, your Document Root (web root) should be at /var/www.
Place your files there and access them with http://localhost/desired_file.php with some web browser or just execute them with php compiler on the command line.
Depending on your distro/version, there might be some configurations to be done, but that's the basic stuff you need to run PHP outside NetBeans

Categories