0

I'm setting up a PHP project on my machine's loalhost. This part is working fine, and it's loading the index.php correctly when visiting http://localhost. However, visiting http://localhost/phpmyadmin it is giving me a HTTP 404 error.

Here are my settings:

  • Project's path Users/zaina-alyahya/Sites/Meetings

  • phpmyadmin path Users/zaina-alyahya/Sites

  • DocumentRoot settings in httpd.conf: /Users/zaina-alyahya/Sites/Meetings/public

  • VirtualHost setup in httpd-vhosts.conf for /Users/zaina-alyahya/Sites/Meetings/public

    • Tried to setup a VirtualHost for phpmyadmin as well, but it didn't work.

    • I did however follow the steps in the second answer here. That worked, but it doesn't seem right to access phpmyadmin via phpmyadmin.localhost.

What am I missing in order to make localhost/phpmadmin load with no errors?

Here is my software configuration:

  • macOS High Sierra 10.13.3

  • Apache 2.4.28

  • PHPMyAdmin 4.8.0.1

  • This is off topic IMO but it appears the community disagrees. – JBis Oct 31 '18 at 11:56
1

Phpmyadmin should be inside your DocumentRoot. ‘localhost/phpmyadmin’ stands for phpmyadmin inside localhost DocumentRoot. Change either the path for your DocumentRoot inside your httpd.conf or move the phpmyadmin folder inside the folder you have already configured.

VirtualHost or DNSmasq only make certain folders accessible via a specific address. If I am not mistaken they should still reside inside your DocumentRoot.

You should also edit permissions for user and group inside httpd.conf or set permissions on the DocumentRoot accordingly.

Remember to restart Apache after you change settings.

$ sudo apachectl -k restart

Update:

Web applications are placed in a particular folder on your machine. A web server such as Apache serves them to the web or your browser. You will have to configure apache and DNS for each project. Usually all application directories reside in the document root. In any case the connection between the application directory (in this case your phpmyadmin, which is just a web app) and your web server is made in a configuration file such as httpd.conf for apache. Depending from how you installed apache you will have to configure:

  • the port where to listen
  • set DocumentRoot /usr/local/var/www to your document root
  • change the tag reference below and set AllowOverride All
  • enable mod_rewrite
  • depending on how you would like to manage permissions either keep _www and apply corresponding permissione to your web app folder or better set in the config file user YourName + Group staff
  • set the server name to ServerName localhost
  • set up your site folder (edit permissions if necessary)
  • restart apache

This will serve everything on your development machine starting from localhost, which coincides with your document root.

localhost/phpinfo.php will open the phpinfo.php file placed in your document root localhost/phpmyadmin will open the index inside the phpmyadmin directory

In case you have multiple web projects they will be available through the same procedure: localhost/webapp1 or localhost/webapp1/index.html etc.

The translation to another address available to your system is made through virtual hosts, dns server, etc. Which translates/connects a URL to the root of your web app.

To do this:

  • uncomment LoadModule vhost_alias_module lib/httpd/modules/mod_vhost_alias.so in /usr/local/etc/httpd/httpd.conf
  • include /usr/local/etc/httpd/extra/httpd-vhosts.conf
  • edit the /usr/local/etc/httpd/extra/httpd-vhosts.conf

Be aware that when configuring virtual host you will loose your document root so the first thing is to add it back or you will loose the ability to use localhost/phpinfo:

<VirtualHost *:80>
    DocumentRoot "Users/zaina-alyahya/Sites"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "Users/zaina-alyahya/Sites/webapp"
    ServerName webapp.test
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "Users/zaina-alyahya/Sites/PHPmyadmin"
    ServerName phpmyadmin
</VirtualHost>

The ServerName for the web app has to be chosen by you. You will have to add it to your host file /etc/hosts, use a DNS server, which I would prefer. Since OSX server is going to loose DNS functionality you should take a look at dnsmasq (simple) or better BIND (full functionality). These programmes resolve an URL to your machine.

Certain areas could create trouble:

  • in case Apache is used: is Apple's version used? Which one? System or macOS server's? In case you have macOS server installed deactivate the web server part. You will loose it anyway this year in case you decide to upgrade to the next version of macOS. It is better to configure everything manually, much more educative anyway!
  • DNS setup
  • Permissions!!!!!!!! In case they are not set correctly you will get a 404.
  • restart the web server after you changed its configuration.
  • Thank you @SEJU. If I go with the former suggestion (have phpmyadmin inside the DocumentRoot), how will I be able to access the app? – zalyahya May 2 '18 at 6:23
  • If everything is set up correctly you should be able to visit it through ‘localhost/phpmyadmin’, since localhost refers to your DocumentRoot and everything after to the relative location starting from your DocumentRoot – SEJU May 2 '18 at 6:26
  • If I do follow this (which I attempted before), the problem that arises is that when I visit localhost/Meetings (which is my app), I can only see the directory, and visiting localhost/Meetings/public to load index.php doesn't seem like a correct practice. – zalyahya May 2 '18 at 6:42
  • That is how it is done without configuring name routing through virtual hosts, DNS mapping. If you want to have a specific url on your development machine configure name routing. – SEJU May 2 '18 at 8:06
  • Your document root should be /Users/zaina-alyahya/Sites. Inside of it you place all your project directories and resolve them through virtual hosts, DNS mapping. – SEJU May 2 '18 at 8:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .