Home > Article > Operation and Maintenance > How to install and start linux php
Step One: Install Linux
Usually, installing Linux starts from a bootable media, such as a DVD or USB. Boot the computer from the media to enter the installation program, and then follow the prompts to complete the installation process. In the installer, you need to select the packages you want to install. Make sure to install with Apache web server and PHP selected.
After the installation is complete, you need to configure the network so that the server can be accessed. This is the command used:
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
sudo route add default gw 192.168.1.1
sudo echo "nameserver 8.8.8.8" >> /etc /resolv.conf
The above command assumes the Ethernet interface is eth0, sets the IP address to 192.168.1.100, the gateway is 192.168.1.1, and uses the Google public DNS server.
Step 2: Install PHP
After the Linux installation is completed, you need to install PHP. Install PHP using the following command:
sudo apt-get install php7.0
Please note that in the above command, you need to change the PHP version to the version you need to install.
Step Three: Configure Apache
Apache needs to be configured correctly to use with PHP. Please look for the following in the file path /etc/apache2/mods-enabled/dir.conf:
DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
And make sure index.php is in the list. Otherwise, you can add it manually as follows:
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
Next, enable it using the following command Apache and PHP:
sudo a2dismod mpm_event
sudo a2enmod mpm_prefork
sudo a2enmod php7.0
sudo service apache2 restart
Step 4: Test your installation
Finally, you need to test your installation and make sure it is working. To do this, you can create a "test.php" file and put the following code into it:
phpinfo();
?>
Save and place it in the root directory of the Web server. You can then view the PHP information by entering the server's IP address or domain name into your web browser and adding "/test.php" after the URL. When you are able to access the PHP information page, your installation and configuration are correct.
The above is the detailed content of How to install and start linux php. For more information, please follow other related articles on the PHP Chinese website!