After lamp install, can't run php scripts on localhost
First of all, I would rather create a public_html folder in user's home directory
mkdir public_html
By default, PHP scripts in user directories are disabled. In other words you need to enable them. With your instructions, you seem to have php5 installed. To enable PHP scripts in user directories, edit /etc/apache2/mods-available/php5.conf file as root.
In my case I did
sudo vim /etc/apache2/mods-available/php5.conf
When that file is open, comment out the following lines (instructions inside the file too)
<IfModule mod_userdir.c>
<Directory /home/*/public_html>
php_admin_value engine Off
</Directory>
</IfModule>
and save it. Make sure userdir is enabled with
sudo a2enmod userdir
Move that info.php file to your public_html folder. Restart apache2 with
sudo service apache2 restart
Go to http://localhost/~yourusername/info.php and it should work perfectly.
Related videos on Youtube
Metaphysiker
I use Ruby and Ruby on Rails. I've written this app: http://safe-stream-36713.herokuapp.com/
Updated on September 18, 2022Comments
-
Metaphysiker over 1 year
I followed this tutorial to install lamp: https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu
At step 4: See PHP on your Server, I was told to do the following:
First create a new file:
> sudo nano /var/www/info.php
Add in the following line:
<?php phpinfo(); ?>
Then,I should see a page with lots of information, when I type in
localhost/info.php
But the page is just white. No error message.
If I type in
localhost/index
, then the Apache2 Ubuntu default page loads.Later, I moved info.php to
/var/www/html
but the page is still white.At this point, I'm clueless. Any suggestions to fix this problem?
-
AzkerM over 7 yearswould you please update the outputs for
which php
&whereis php
? -
Metaphysiker over 7 years@AzkerM which php: /usr/bin/php whereis php: php: /usr/bin/php7.0 /usr/bin/php /usr/lib/php /etc/php /usr/share/php7.0-json /usr/share/php7.0-xml /usr/share/php7.0-readline /usr/share/php7.0-mcrypt /usr/share/php7.0-opcache /usr/share/php7.0-mbstring /usr/share/php7.0-gd /usr/share/php /usr/share/php7.0-common /usr/share/php7.0-mysql /opt/lampp/bin/php /usr/share/man/man1/php.1.gz
-
-
Metaphysiker over 7 yearsI tried to follow your steps: I couldn't install php5 so instead I just used the last version. Then, I went to /etc/apche2/mods-available/php7.o.conf and commented the section out (by putting #before the lines). And did sudo a2enmod userdir and apache2 restart. It says: Not found . The requested URL /sandro/public_html/info.php was not found on this server. (Apache/2.4.18)
-
jiipeezz over 7 years@Metaphysiker If you already installed libapache2-mod-php , try running
sudo a2enmod php7.0
, otherwise runsudo apt-get install libapache2-mod-php
and then the first mentioned command. After this try restarting apache2 once again and tell me what is the outcome -
Metaphysiker over 7 yearssudo a2enmod php7.0: ob for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details. And now, I cant restart the apache 2 now
-
jiipeezz over 7 yearsThat's weird because I started everything over and followed steps above and my info.php script works perfectly on apache2 server. Can you reach localhost/~username/ and see if your info.php is there, or what does it say if you try that?
-
Metaphysiker over 7 yearsThanks for your help! It turns out, that I didnt properly installed lamp. Shame one me.