How to use Docker, PHP, and Laravel
We can use phpmyadmin to manage our sql database instance. One way to set up phpmyadmin and mysql server 8.0.1 is to use docker.
Docker is a newer technology that uses the concept of a container to serve applications. To get started you must download docker desktop. I am using a windows machine so I had to configure windows subsystem for linux before I could install docker. After you have docker desktop set up the next steps are very simple. From an administrative powershell prompt we need to run
docker run — name my-own-mysql -e MYSQL_ROOT_PASSWORD=mypass123 -d mysql:8.0.1
then in a separate terminal we need to run
docker run — name my-own-phpmyadmin -d — link my-own-mysql:db -p 8081:80 phpmyadmin/phpmyadmin
After you’ve successfully executed these two commands we can navigate to localhost:80/phpmyadmin and log into phpmyadmin using username: root and password: mypass123. Next we can create a simple web service using the php framework, Laravel. You’ll need to install the package manager composer for php. Composer is a cli tool that is very useful for php development. After we run the command
composer create-project laravel/laravel module_8
We need to open the file app/config/database.php with a code editor. We just need to configure the appropriate settings for the database connection in the following block of code
‘mysql’ => [ ‘driver’ => ‘mysql’, ‘port’ => env(‘DB_PORT’, ‘3306’), ‘host’ => $host, ‘database’ => $database, ‘username’ => $username, ‘password’ => $password, ‘charset’ => ‘utf8’, ‘collation’ => ‘utf8_unicode_ci’, ‘prefix’ => ‘’, ‘strict’ => false, ‘engine’ => null, ‘options’ => extension_loaded(‘pdo_mysql’) ? array_filter([ PDO::MYSQL_ATTR_SSL_CA => env(‘MYSQL_ATTR_SSL_CA’), ]) : ,],
After we’ve completed that step we can serve our php application
php artisan serve --port=8082
from the /app directory. After we’ve executed that command successfully we should be able to visit localhost:8082 to see a running version of our application.