linux(Ubuntu) build LAMP environment

1. Update source

sudo apt- get update

2. Install common software

SSH、Vim、Git、Tree

①SSH

sudo apt-get install openssh-server

Management command: service ssh status/start/stop/restart

②Vim

sudo apt-get install vim

③Git

sudo apt-get install git

④Tree

sudo apt-get install tree

3. Install Apache

sudo apt-get intall apache2

Basic Information:

Test: Access http:IP and the apache work page appears

Administrative command: service apache2 status/start/restart/stop

web directory: var/www The default access specific directory is var/www/html

Installation directory: /etc/apache2/

Configuration file: /etc/apache2/apache2.conf (global configuration file)

4. Install MySQL

sudo apt-get install mysql-server mysql-client

Test: mysql -u -root -p

Management command: service mysql status/start/stop/restart

5. Install PHP (PHP7.0)

sudo apt-get install  php7.0

test: php -v

6. Installation of other modules

sudo apt-get install libapache2-mod-php7.0 php7.0-mysql

7. Modify web directory permissions

sudo chmod 777 /var/www

8. Restart the service to test whether php can be parsed by apache

service apache2 restart

service mysql restart

 

Use vim to create and edit phpinfo.php

vim /var/www/html/phpinfo.php

Write in the file: <?php echo phpinfo(); ?>

Browser access http://IP/phpinfo.php

If everything goes well, you will see the phpinfo page at this point

 

9. Install phpmyadmin

sudo apt-get install phpmyadmin 

Select apache2 and confirm. Configure the database, and enter a password.

Create phpmyadmin shortcut: sudo ln -s /usr/share/phpmyadmin var/www/html

Enable Apache mod_rewrite module: sudo a2enmod rewrite

Restart the service:

service php7.0-fpm restart

service apache2 restart

Test: visit http://IP/phpmyadmin

 

10. Configure Apache

①, Aliyun-like remote server

vim /etc/apache2/apache2.conf

Add to:

AddType application/x-httpd-php .php .htm .html

AddDefaultCharset UTF-8

Multi-project subdomain configuration

Add: (To configure several subdomains|projects, add several times)

<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/html/test
ServerName cy.wanggangg.top
ServerAlias cy.wanggangg.top
</VirtualHost>

Main item: DocumentRoot specifies the directory to access

    ServerName domain name|subdomain

Restart apache to test access

 ②, local virtual host domain name configuration

Suppose you want to configure two virtual domain names www.aio.com www.bio.com

sudo vim /etc/hosts

Added to the file:

127.0.0.1  www.aio.com

127.0.0.1 www.bio.com

save changes and exit

 

Copy the default configuration file 000-default.conf and modify it

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/www.aio.com.conf

sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/www.bio.com.conf

sudo vim /etc/apache2/sites-available/www.aio.com.conf

www.bio.com.conf Do similar modifications and save the access directory can be defined by yourself, do not need to specify the html directory

Establish soft connection

sudo ln -s /etc/apache2/sites-avaliable/www.aio.com.conf  /etc/apache2/sites-enabled/

sudo ln -s /etc/apache2/sites-avaliable/www.bio.com.conf /etc/apache2/sites-enabled/

restart Apache

service apache2 restart

The designated access directory for www.aio.com is /var/www/html/aio

cd / var / www / html / aio

Create new folders and files

mkdir aio

touch aio/index.php

edit file

vim aio/index.php

Write: <?php echo 'www.aio.com page'; ?>

save and exit

Browser access test www.aio.com

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324581163&siteId=291194637