Apache2 cannot open .php files - php

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

Related

How to connect php-fpm with nginx?

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?

How to enable php5 curl on Ubuntu 14.04?

I have installed curl on Ubuntu 14.04 running PHP 5.6 with the following commands:
sudo apt-get install php5-curl
sudo service apache2 restart
It returns a successful message, but when I run:
php -m
the curl module is not listed, and phpinfo(); does not recognize it as installed or active. I also tried adding:
extension=curl.so
to my php.ini file, but that had no effect. How do I get PHP to recognize that curl is installed?
I got it working based on the second answer listed here: https://askubuntu.com/questions/9293/how-do-i-install-curl-in-php5
Basically:
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install php5.6-curl
sudo service apache2 restart
I'm not really sure what made the difference. The repository reference is the most significant difference from previous attempts, but it seems odd as prior installation attempts didn't appear to have any problem accessing or installing/updating php-curl. And I had made sure everything was updated several times. But whatever it was, the above resolved it.
ssh to your server and cd to /
find / -name 'curl.so'
Run the above find command to locate where the curl binary is hanging out at. If you can't find the file, you might need to install curl and run the find command again.
apt-get install php5-curl
You'll now want to edit the php.ini being used for php files run from the cli (it's different than the one used by apache), and is likely at /etc/php5/cli/php.ini
nano /etc/php5/cli/php.ini
You can also run
php -i | grep 'php.ini'
To get the file path, just to be sure.
In your php.ini file search for [curl] by pressing ctrl + w
You'll now want to add the extension to the file and it should look something like the following, though your path to the curl.so file and such might be a little different:
[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
;curl.cainfo =
extension=/usr/lib/php5/20131226/curl.so
After doing the above, I was able to use curl in php scripts run from the cli.

phpmyadmin page shows source code, Ubuntu 16.04 installed with Vagrant and Puphpet

I installed virtualbox and vagrant, then went to https://puphpet.com and downloaded a package with Ubuntu 16.04. The relevant parts of that package are PHP, MySQL and Apache. It works now, I managed to connect to the server and PHP is running correctly (I installed magento on it).
Now I'm trying to install phpmyadmin, however after running the commands:
sudo apt-get install phpmyadmin
sudo ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf-available/phpmyadmin.conf
sudo a2enconf phpmyadmin.conf
sudo service apache2 restart
When i go to http://{serverIP}/phpmyadmin/ I get the source code of the file that's supposed to be the phpmyadmin login page, like this:
Source
What could be causing this? It can't be that PHP isn't installed correclty, cause I managed to install Magento and it works fine, so what could be the problem?
Edit:
Also in the /etc/apache2/apache.conf file, I added this line at the end of the file:
Include "/etc/phpmyadmin/apache.conf"
Solved it, I needed to run:
sudo apt-get install libapache2-mod-php7.0
I was missing that extension. Also after I installed that extension I got an error saying:
AH00534: apache2: Configuration error: More than one MPM loaded.
I fixed that by runnning:
sudo a2dismod worker
Not sure why this happened.

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