How to set up Magento 2.3 in Linux with PHP XDebug? – A Story of a Programmer interest in Technology, Life Style

Magento 2

Today I thought to share some tips and tricks to easily set up the Magento 2 e-commerce web application. We will use the Apache2 Server and MySQL database as the background environment. You can follow the below steps to easily set up the development environment.

Steps to follow;

  1. Set up Apache2 and MySQL servers
  2. Install PHP 7.1.33 version
  3. Install PHP Xdebug
  4. Run composer and download the vendor files
  5. Setup the Magento 2 installation configurations

Set up Apache2 and MySQL servers

It is easy to install these two servers by using below linux terminal commands.

sudo apt-get install apache2 mysql-server

After installed the Apache2 and MySQL servers, you will have to set up your hosts’ file and apache2 virtual host file to create a domain name for your Magento 2 e-commerce web application. You can add the below configurations to relevant files.

file /etc/hosts
127.0.0.1 dev.domain.com

file /etc/apache2/sites-available/dev.domain.com.conf
<VirtualHost *:80>
    ServerName dev.domain.com
    DocumentRoot /var/www/html/<install-directory-name>/pub/
    <Directory /var/www/html/<install-directory-name>/pub/>
       AllowOverride All
    </Directory>
    ErrorLog $APACHE_LOG_DIR/error.log
    CustomLog $APACHE_LOG_DIR/access.log combined
</VirtualHost>

Install PHP 7.1.33 version

I used the below command to install the PHP with its relevant all the extensions as well.

sudo apt-get -y install php7.1-common php7.1-opcache php7.1-xml php7.1-gd php7.1-mysql php7.1-intl php7.1-mbstring php7.1-bcmath php7.1-json php7.1-soap php7.1-dev php7.1-curl php7.1-intl php7.1-xsl php7.1-zip php7.1-soap openssl mcrypt

Install PHP Xdebug

PHP XDebug
PHP XDebug

PHP Xdebug is a tool to use for code debugging. This tool is supported by almost every PHP Code Editors. It will help to add breakpoints to required code lines and analyze the variable values on that code debugging time. You can use the below command to install the PHP Xdebug tool. In addition, you should add below PHP Xdebug configuration to php.ini file in the /etc/php/7.1/cli and /etc/php/7.1/apache2 folders.

sudo apt-get install php-pear
sudo pecl install xdebug OR sudo apt-get install php-xdebug
file /etc/php/7.1/cli/php.ini
file /etc/php/7.1/apache2/php.ini

[xdebug]
zend_extension=/usr/lib/php/<folder-name>/xdebug.so # ex: /usr/lib/php/20170718/xdebug.so
xdebug.remote_enable=1
xdebug.remote_host=127.0.0.1
xdebug.remote_port=9000

Thereafter, you have to install the Xdebug Helper chrome browser extension. Also, you will have to install the PHP Xdebug extension to your code editor and add the correct remote port 9000 in its configurations before run the debug feature in your code editor.

Run composer and download the vendor files

PHP Composer

We already talked about what is composer and what it can do. You can read our previous article to get more ideas about what is composer? You need to change the directory to the relevant Magento 2 codebase using the cd command in the terminal. It is required to run the below command to download all the relevant files and folders from the Magento 2 repository.

cd /var/www/html/<install-directory-name>
composer create-project --repository-url= magento/project-enterprise-edition=2.3.0 <install-directory-name>

You will require to provide Magento account user logins to download the files. It would require providing the correct files and folder permission as below.

cd /var/www/html/<magento install directory>
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w  +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws  +
chown -R :www-data . # Ubuntu
chmod u+x bin/magento

Finally, you can run the below command to install Magento 2. I believe at this point that you have already created the database and its user logins.

bin/magento setup:install \
--base-url= \
--db-host=localhost \
--db-name=magento \
--db-user=magento \
--db-password=magento \
--admin-firstname=admin \
--admin-lastname=admin \
--admin-email=admin@admin.com \
--admin-user=admin \
--admin-password=admin123 \
--language=en_US \
--currency=USD \
--timezone=America/Chicago \
--use-rewrites=1

In conclusion, you will require to install Apache2, MySQL, PHP, and PHP Xdebug correctly. Hopefully, it shouldn’t be showing any errors if you would have correctly set up all the above steps. Finally, run the setup domain name in the browser to view your Magento 2 e-commerce web application.

Happy Coding!

References;

Scroll to Top