Home > Enterprise >  Apache Server to serve WordPress and Normal sites on different port
Apache Server to serve WordPress and Normal sites on different port

Time:04-19

I have installed Apache/2.4.4 in my ubuntu 21. I have already had a website in this IP: 172.20.x.y is listening to port 80 i.e the default port. It doesn't have a domain name yet. I have mentioned its document root below,

DocumentRoot: /var/www/html

I plan to use port 81 to run WordPress on the same machine.

DocumentRoot: /srv/www/wordpress

I tried to update the 000.default.conf file to support that. Below are the codes I changed.

Listen 81

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/htm
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

<VirtualHost *:81>
        ServerAdmin webmaster@localhost
        DocumentRoot /srv/www/wordpress
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Directory /srv/www/wordpress>
            Options FollowSymLinks
            AllowOverride Limit Options FileInfo
            DirectoryIndex index.php
            Require all granted
        </Directory>
</VirtualHost>

However, when I access the 172.20.x.y:81, it will redirect to the default port. Wordpress doesn't work, when I disable 000.default.conf and run only WordPress.conf it works fine.

<VirtualHost *:80>
    DocumentRoot /srv/www/wordpress
    <Directory /srv/www/wordpress>
        Options FollowSymLinks
        AllowOverride Limit Options FileInfo
        DirectoryIndex index.php
        Require all granted
    </Directory>
    <Directory /srv/www/wordpress/wp-content>
        Options FollowSymLinks
        Require all granted
    </Directory>
</VirtualHost>

Can anyone help fix this problem?

CodePudding user response:

I would recommend checking the Site/Home URL of your WordPress. Make sure to change the Site/Home URLs to match the port, for example, if your URL is currently "http://localhost" ( 80 HTTP port by default ) it is absolutely normal behavior to see a redirection occur when you attempt to visit "http://localhost:81".

Please try adding ":81" at the end of your WordPress URL and see how it goes.

CodePudding user response:

I do not know how it works, but it works. I erased all the changes I had made and started doing it all over again. Now I did not touch the 000-default.conf file, I just added the wordpress.conf file and wrote vhost code mentioned below in it.

Listen 81

<VirtualHost *:81>

        ServerAdmin webmaster@localhost
        DocumentRoot /srv/wordpress
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

Let me test the Apache syntax by running the $apache2ctl configtest command, it shows syntax ok. Then I reload the apache server by running $service apache2 reload;

Finally, I open 172.20.x.y:81, which says "You do not have permission to access", At which point I uncommnent some parts of code on apache2.conf file at /etc/apache2/. It was like

# <Directory /srv/>
#        Options Indexes FollowSymLinks
#        AllowOverride None
#        Require all granted
# </Directory>

Changed to

<Directory /srv/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

Again I reload the Apache server. Finally, it works properly.

  • Related