M
M
Maxim Zolotoy2019-01-05 23:56:39
Apache HTTP Server
Maxim Zolotoy, 2019-01-05 23:56:39

Why is php not working on ubuntu?

I installed astralinux and wanted to run php there,
but for some reason it does not work (displays the code, but does not execute) - I can not understand why. I made a detailed log of my actions since the installation of the system. I would appreciate your help!

sudo mkdir -p /var/www/astra.com/public_html
sudo chown -R $USER:$USER /var/www/astra.com/public_html
sudo chmod -R 755 /var/www

nano /var/www/astra.com/public_html/index.html
!начало содержимого файла!
<html>
<head>
<title>Welcome to Astra.com!</title>
</head>
<body>
<h1>Success! The astra.com virtual host is working!</h1>
</body>
</html>
!конец содержимого файла!

sudo su
apt-get install apache2

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/astra.com.conf
sudo nano /etc/apache2/sites-available/astra.com.conf
!начало содержимого файла!
<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        ServerName astra.com

        ServerAdmin [email protected]
        DocumentRoot /var/www/astra.com/public_html
        DirectoryIndex index.php index.html

        # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For example the
        # following line enables the CGI configuration for this host only
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
!конец содержимого файла!

sudo a2ensite astra.com.conf
sudo systemctl reload apache2

sudo a2dissite 000-default.conf
sudo systemctl reload apache2


sudo nano /etc/hosts
!начало содержимого файла!
127.0.0.1       localhost
127.0.1.1       astra
127.0.1.1       astra.com

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
!конец содержимого файла!

nano /var/www/astra.com/public_html/index.php
!начало содержимого файла!
<?php phpinfo(); ?>
!конец содержимого файла!

apt-get update
apt-get install php7.0
php -v
!начало ответа в терминале!
PHP 7.0.27-0+deb9u1 (cli) (built: Jan  5 2018 13:51:52) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.27-0+deb9u1, Copyright (c) 1999-2017, by Zend Technologies
!конец ответа в терминале!

sudo systemctl reload apache2

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Zolotoy, 2019-01-07
@spacenear

The solution was found - the whole thing was in astralinux. To make everything work as it should, it was necessary to find the #AstraMode On line in the /etc/apache2/apache2.conf file and change this line to AstraMode off

G
grinat, 2019-01-06
@grinat

In Apache, php is not connected, so it displays php files as text, and does not give php for execution.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question