Docker deploys LAMP to build wordpress blog system

LAMP is currently a more popular web framework, namely the website architecture scheme of Linux+Apache+Mysql+PHP. Docker is a very popular virtualized application container, which can create a lightweight and portable container for any application. Now we are going to deploy the LAMP environment through docker and build a wordpress blog system to test.

1. Download the mysql and php-apache images

docker pull mysql
docker pull php:7.2-apache

Create a custom network lamp

docker network create lamp
docker network ls

 2. Create a script
vim docker_lamp.sh to generate mysql and httpd-php containers

Copy code

#!/bin/bash
function mysql()
{
    docker run -d -p 3306:3306 --name mysql -e MYSQL_ROOT_PASSWORD=root daocloud.io/library/mysql:5.7.5 \
    -v /data/docker/mysql/data:/var/lib/mysql \
    -v /data/docker/mysql/conf:/etc/mysql/conf.d -v /data/docker/mysql/logs:/logs 
}

function httpd_php()
{
    docker run --name httpd-php --net lamp -p 80:80 \
    -v /data/docker/httpd/conf:/etc/apache2/sites-enabled \
    -v / data / docker / www: / var / www / html \
    -v /data/docker/httpd/logs:/var/log/apache2 \
    -d php:7.2-apache
}
$1

Copy code

3. Start mysql and httpd-php containers

sh docker_lamp.sh mysql
sh docker_lamp.sh httpd_php

4. Write a php homepage file to test

echo "<?php phpinfo(); ?>" > /data/docker/www/index.php

Visit http://10.0.0.11 through a browser

5. Download the wordpress blog system

wget https://cn.wordpress.org/wordpress-4.9.4-zh_CN.tar.gz
tar -zxvf wordpress-4.9.4-zh_CN.tar.gz -C /data/docker/www/

6. Configure the wordpress blog
browser to visit http://10.0.0.11/wordpress 

 

 There is an error

7. Modify wp-config-sample.php configuration

cd /data/docker/www/wordpress/
vim wp-config-sample.php #Modify the following

Copy code

/** The name of the WordPress database*/
define('DB_NAME', 'wordpress');

/** MySQL database user name*/
define('DB_USER', 'root');

/** MySQL database password*/
define('DB_PASSWORD', '123456');

/** MySQL host*/
define('DB_HOST', '10.0.0.11');

/** The default text encoding when creating a data table*/
define('DB_CHARSET', 'utf8');

/** Database collation type. Do not change if you are not sure*/
define('DB_COLLATE', '');

Copy code

Use the browser to visit http://10.0.0.11/wordpress

After consulting the information, I found that the mysql_connect() function was not recommended since PHP5.0, but the function was directly abandoned in php7.0. The replacement function was mysqli_connect(). Finally, the cause of the problem was found.

8. Call to undefined function mysql_connect() problem solution
Enter into the mysql container to install the mysqli extension

Copy code

docker exec -it httpd-php /bin/bash
apt-get update
apt-get install libpng-dev
cd /usr/local/bin/
./docker-php-ext-install gd mysqli
./docker-php-ext-enable gd mysqli
exit
docker restart httpd-php

Copy code

Write a php
vim /data/docker/www/test.php to test the connection to mysql

Copy code

<?php
    echo "Hello PHP<br/>";
    $conn = mysqli_connect("10.0.0.11","root","123456");
    if(!$conn){
        echo "Failed to connect to the database";
    }else{
        echo "Connect to the database successfully";
    }
    phpinfo();
?>

Copy code

 

 Modify the wp-db.php file and replace mysql_connect with mysqli_connect

cd /data/docker/www/wordpress/
sed -i "s/mysql_connect/mysqli_connect/g" wp-includes/wp-db.php
mv wp-config.php wp-config-sample.php

9. Reconfigure the wordpress blog

After filling in the configuration information for connecting to mysql according to the previous steps, you will see the following page, indicating that the mysql connection is successful.

 You need to manually create the wp-config.php file and paste the above information into the wp-config.php file
vim /data/docker/www/wordpress/wp-config.php

 Then click "install now", the following page appears

 After entering the above information, click "Install WordPress"

 

 

Note: There are some ununderstandings in this article, add QQ: 1300536862 to discuss

Recommendation: If you need to rent cloud servers, domain names and other services, you can scan the QR code below. The cloud server is free to receive and use. Huawei Cloud services :

        

Guess you like

Origin blog.csdn.net/qq_33648367/article/details/112600245